mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-08-17 20:53:29 +02:00
Compare commits
6 Commits
feat/add-t
...
dagger-sdk
Author | SHA1 | Date | |
---|---|---|---|
f390eac29f
|
|||
e642778d90
|
|||
7133bfae95 | |||
41b20b6268 | |||
13b7805e7e | |||
4381af0295 |
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -260,7 +260,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dagger-core"
|
||||
version = "0.2.7"
|
||||
version = "0.2.8"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dirs",
|
||||
@@ -309,7 +309,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"dagger-core",
|
||||
|
@@ -20,7 +20,7 @@ members = [
|
||||
|
||||
[dependencies]
|
||||
dagger-codegen = { path = "crates/dagger-codegen", version = "^0.2.5" }
|
||||
dagger-core = { path = "crates/dagger-core", version = "^0.2.7" }
|
||||
dagger-core = { path = "crates/dagger-core", version = "^0.2.8" }
|
||||
|
||||
clap = "4.1.6"
|
||||
dirs = "4.0.0"
|
||||
|
43
Makefile.toml
Normal file
43
Makefile.toml
Normal file
@@ -0,0 +1,43 @@
|
||||
[tasks.codegen]
|
||||
command = "cargo"
|
||||
args = ["run", "-p", "ci", "--", "codegen"]
|
||||
workspace = false
|
||||
|
||||
[tasks.build]
|
||||
command = "cargo"
|
||||
args = ["run", "-p", "ci", "--", "ci"]
|
||||
dependencies = ["codegen"]
|
||||
workspace = false
|
||||
|
||||
[tasks.fmt]
|
||||
command = "cargo"
|
||||
args = ["fmt", "--all"]
|
||||
workspace = false
|
||||
|
||||
[tasks.fix]
|
||||
command = "cargo"
|
||||
args = ["fix", "--workspace", "--allow-dirty"]
|
||||
dependencies = ["fmt"]
|
||||
workspace = false
|
||||
|
||||
[tasks.release_crate]
|
||||
command = "cargo"
|
||||
args = [
|
||||
"smart-release",
|
||||
"--allow-fully-generated-changelogs",
|
||||
"--update-crates-index",
|
||||
"dagger-sdk",
|
||||
]
|
||||
dependencies = ["codegen", "fix"]
|
||||
workspace = false
|
||||
|
||||
[tasks.release_crate_commit]
|
||||
command = "cargo"
|
||||
args = [
|
||||
"smart-release",
|
||||
"-e",
|
||||
"--allow-fully-generated-changelogs",
|
||||
"--update-crates-index",
|
||||
"dagger-sdk",
|
||||
]
|
||||
workspace = false
|
@@ -8,6 +8,6 @@ edition = "2021"
|
||||
[dependencies]
|
||||
clap = "4.1.6"
|
||||
color-eyre = "0.6.2"
|
||||
dagger-sdk = { path = "../crates/dagger-sdk/", version = "^0.2.15" }
|
||||
dagger-sdk = { path = "../crates/dagger-sdk/", version = "^0.2.16" }
|
||||
eyre = "0.6.8"
|
||||
tokio = { version = "1.25.0", features = ["full"] }
|
||||
|
@@ -1,5 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use clap::ArgMatches;
|
||||
use dagger_sdk::{Container, HostDirectoryOpts, Query};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -10,6 +11,7 @@ async fn main() -> eyre::Result<()> {
|
||||
.subcommand_required(true)
|
||||
.subcommand(clap::Command::new("pr"))
|
||||
.subcommand(clap::Command::new("release"))
|
||||
.subcommand(clap::Command::new("codegen"))
|
||||
.get_matches();
|
||||
|
||||
let client = dagger_sdk::connect().await?;
|
||||
@@ -20,6 +22,7 @@ async fn main() -> eyre::Result<()> {
|
||||
return validate_pr(client, base).await;
|
||||
}
|
||||
Some(("release", subm)) => return release(client, subm).await,
|
||||
Some(("codegen", subm)) => return run_codegen(client, subm).await,
|
||||
Some(_) => {
|
||||
panic!("invalid subcommand selected!")
|
||||
}
|
||||
@@ -29,6 +32,42 @@ async fn main() -> eyre::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_codegen(client: Arc<Query>, _subm: &ArgMatches) -> eyre::Result<()> {
|
||||
let docker_cli = client
|
||||
.container()
|
||||
.from("docker:cli")
|
||||
.file("/usr/local/bin/docker");
|
||||
let socket = client.host().unix_socket("/var/run/docker.sock");
|
||||
|
||||
let container = get_dependencies(client).await?;
|
||||
|
||||
let generated_image = container
|
||||
.with_exec(vec!["mkdir", "-p", "/mnt/output"])
|
||||
.with_mounted_file("/usr/bin/docker", docker_cli.id().await?)
|
||||
.with_unix_socket("/var/run/docker.sock", socket.id().await?)
|
||||
.with_exec(vec![
|
||||
"cargo",
|
||||
"run",
|
||||
"--",
|
||||
"generate",
|
||||
"--output",
|
||||
"crates/dagger-sdk/gen.rs",
|
||||
])
|
||||
.with_exec(vec!["cargo", "fmt", "--all"])
|
||||
.with_exec(vec!["cargo", "fix", "--workspace", "--allow-dirty"])
|
||||
.with_exec(vec!["cargo", "fmt", "--all"])
|
||||
.with_exec(vec!["mv", "crates/dagger-sdk/gen.rs", "/mnt/output/gen.rs"]);
|
||||
|
||||
let _ = generated_image.exit_code().await?;
|
||||
|
||||
generated_image
|
||||
.file("/mnt/output/gen.rs")
|
||||
.export("crates/dagger-sdk/src/gen.rs")
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn release(client: Arc<Query>, _subm: &clap::ArgMatches) -> Result<(), color_eyre::Report> {
|
||||
let src_dir = client.host().directory_opts(
|
||||
".",
|
||||
@@ -87,14 +126,14 @@ async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
|
||||
);
|
||||
|
||||
let cache_cargo_index_dir = client.cache_volume("cargo_index");
|
||||
let cache_cargo_deps = client.cache_volume("cargo_deps");
|
||||
let _cache_cargo_deps = client.cache_volume("cargo_deps");
|
||||
let cache_cargo_bin = client.cache_volume("cargo_bin_cache");
|
||||
|
||||
let minio_url = "https://github.com/mozilla/sccache/releases/download/v0.3.3/sccache-v0.3.3-x86_64-unknown-linux-musl.tar.gz";
|
||||
|
||||
let base_image = client
|
||||
.container()
|
||||
.from("rust:latest")
|
||||
.from("rustlang/rust:nightly")
|
||||
.with_workdir("app")
|
||||
.with_exec(vec!["apt-get", "update"])
|
||||
.with_exec(vec!["apt-get", "install", "--yes", "libpq-dev", "wget"])
|
||||
@@ -110,7 +149,7 @@ async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
|
||||
"/usr/local/bin/sccache",
|
||||
])
|
||||
.with_exec(vec!["chmod", "+x", "/usr/local/bin/sccache"])
|
||||
.with_env_variable("RUSTC_WRAPPER", "/usr/local/bin/sccache")
|
||||
//.with_env_variable("RUSTC_WRAPPER", "/usr/local/bin/sccache")
|
||||
.with_env_variable(
|
||||
"AWS_ACCESS_KEY_ID",
|
||||
std::env::var("AWS_ACCESS_KEY_ID").unwrap_or("".into()),
|
||||
@@ -152,8 +191,7 @@ async fn get_dependencies(client: Arc<Query>) -> eyre::Result<Container> {
|
||||
"--recipe-path",
|
||||
"recipe.json",
|
||||
])
|
||||
.with_mounted_cache("/app/", cache_cargo_deps.id().await?)
|
||||
.with_mounted_directory("/app/", src_dir.id().await?)
|
||||
.with_directory("/app/", src_dir.id().await?)
|
||||
.with_exec(vec!["cargo", "build", "--all", "--release"]);
|
||||
|
||||
return Ok(builder_start);
|
||||
|
@@ -11,7 +11,7 @@ publish = true
|
||||
|
||||
[dependencies]
|
||||
convert_case = "0.6.0"
|
||||
dagger-core = { path = "../dagger-core", version = "^0.2.7" }
|
||||
dagger-core = { path = "../dagger-core", version = "^0.2.8" }
|
||||
|
||||
eyre = "0.6.8"
|
||||
genco = "0.17.3"
|
||||
|
@@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## v0.2.8 (2023-03-10)
|
||||
|
||||
### New Features
|
||||
|
||||
- <csr-id-41b20b6268db9d8defe333694e4d3ec019d7c923/> bump version
|
||||
- <csr-id-5f9b3a19c0ab6988bc335b020052074f3f101305/> set internal warnings as errors
|
||||
- <csr-id-f9e7af931d94fbedacf74f5da9a2f71b1992324b/> introduce tests again
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- <csr-id-ecca036bc644fee93fbcb69bf6da9f29169e473e/> fix builder pattern to actually work with default values
|
||||
In previous versions the builder pattern required all values to be set.
|
||||
This has not been fixed, so that default values are allowed.
|
||||
|
||||
### Commit Statistics
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
- 4 commits contributed to the release over the course of 13 calendar days.
|
||||
- 13 days passed between releases.
|
||||
- 4 commits were understood as [conventional](https://www.conventionalcommits.org).
|
||||
- 0 issues like '(#ID)' were seen in commit messages
|
||||
|
||||
### Commit Details
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
<details><summary>view details</summary>
|
||||
|
||||
* **Uncategorized**
|
||||
- bump version ([`41b20b6`](https://github.com/kjuulh/dagger-rs/commit/41b20b6268db9d8defe333694e4d3ec019d7c923))
|
||||
- set internal warnings as errors ([`5f9b3a1`](https://github.com/kjuulh/dagger-rs/commit/5f9b3a19c0ab6988bc335b020052074f3f101305))
|
||||
- introduce tests again ([`f9e7af9`](https://github.com/kjuulh/dagger-rs/commit/f9e7af931d94fbedacf74f5da9a2f71b1992324b))
|
||||
- fix builder pattern to actually work with default values ([`ecca036`](https://github.com/kjuulh/dagger-rs/commit/ecca036bc644fee93fbcb69bf6da9f29169e473e))
|
||||
</details>
|
||||
|
||||
## v0.2.7 (2023-02-24)
|
||||
|
||||
### New Features
|
||||
@@ -15,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
- 1 commit contributed to the release.
|
||||
- 2 commits contributed to the release.
|
||||
- 4 days passed between releases.
|
||||
- 1 commit was understood as [conventional](https://www.conventionalcommits.org).
|
||||
- 0 issues like '(#ID)' were seen in commit messages
|
||||
@@ -27,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
<details><summary>view details</summary>
|
||||
|
||||
* **Uncategorized**
|
||||
- Release dagger-core v0.2.7, dagger-sdk v0.2.15 ([`6a9a560`](https://github.com/kjuulh/dagger-rs/commit/6a9a560cdca097abf23371d44599a2f1b726ae7f))
|
||||
- update to dagger-v0.3.13 ([`3e8ca8d`](https://github.com/kjuulh/dagger-rs/commit/3e8ca8d86eafdc1f9d5e8b69f14fb60509549e0f))
|
||||
</details>
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "dagger-core"
|
||||
version = "0.2.7"
|
||||
version = "0.2.8"
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
license-file = "LICENSE.MIT"
|
||||
|
@@ -1,3 +1,4 @@
|
||||
use crate::DAGGER_ENGINE_VERSION;
|
||||
use crate::{
|
||||
cli_session::CliSession, config::Config, connect_params::ConnectParams, downloader::Downloader,
|
||||
};
|
||||
@@ -10,7 +11,9 @@ impl Engine {
|
||||
}
|
||||
|
||||
async fn from_cli(&self, cfg: &Config) -> eyre::Result<(ConnectParams, tokio::process::Child)> {
|
||||
let cli = Downloader::new("0.3.13".into())?.get_cli().await?;
|
||||
let cli = Downloader::new(DAGGER_ENGINE_VERSION.into())?
|
||||
.get_cli()
|
||||
.await?;
|
||||
|
||||
let cli_session = CliSession::new();
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
pub const DAGGER_ENGINE_VERSION: &'static str = "0.4.0";
|
||||
|
||||
pub mod cli_session;
|
||||
pub mod config;
|
||||
pub mod connect_params;
|
||||
|
@@ -6,6 +6,52 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to
|
||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## v0.2.16 (2023-03-10)
|
||||
|
||||
### Chore
|
||||
|
||||
- <csr-id-e642778d9028726dfb07217814e15ad1dd3b83f2/> fix tasks
|
||||
|
||||
### Documentation
|
||||
|
||||
- <csr-id-13b7805e7e6fcf47e0a1318adcc25b4ab773a3c9/> fix missing await in connect
|
||||
|
||||
### New Features
|
||||
|
||||
- <csr-id-7133bfae9508bc5977548e373c49342a1248d6e4/> with dagger-engine v.0.4.0
|
||||
- <csr-id-4381af029521c2cbac9325278d261db79a994657/> add tests to sdk
|
||||
- <csr-id-5f9b3a19c0ab6988bc335b020052074f3f101305/> set internal warnings as errors
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- <csr-id-ecca036bc644fee93fbcb69bf6da9f29169e473e/> fix builder pattern to actually work with default values
|
||||
In previous versions the builder pattern required all values to be set.
|
||||
This has not been fixed, so that default values are allowed.
|
||||
|
||||
### Commit Statistics
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
- 6 commits contributed to the release over the course of 13 calendar days.
|
||||
- 13 days passed between releases.
|
||||
- 6 commits were understood as [conventional](https://www.conventionalcommits.org).
|
||||
- 0 issues like '(#ID)' were seen in commit messages
|
||||
|
||||
### Commit Details
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
<details><summary>view details</summary>
|
||||
|
||||
* **Uncategorized**
|
||||
- fix tasks ([`e642778`](https://github.com/kjuulh/dagger-rs/commit/e642778d9028726dfb07217814e15ad1dd3b83f2))
|
||||
- with dagger-engine v.0.4.0 ([`7133bfa`](https://github.com/kjuulh/dagger-rs/commit/7133bfae9508bc5977548e373c49342a1248d6e4))
|
||||
- fix missing await in connect ([`13b7805`](https://github.com/kjuulh/dagger-rs/commit/13b7805e7e6fcf47e0a1318adcc25b4ab773a3c9))
|
||||
- add tests to sdk ([`4381af0`](https://github.com/kjuulh/dagger-rs/commit/4381af029521c2cbac9325278d261db79a994657))
|
||||
- set internal warnings as errors ([`5f9b3a1`](https://github.com/kjuulh/dagger-rs/commit/5f9b3a19c0ab6988bc335b020052074f3f101305))
|
||||
- fix builder pattern to actually work with default values ([`ecca036`](https://github.com/kjuulh/dagger-rs/commit/ecca036bc644fee93fbcb69bf6da9f29169e473e))
|
||||
</details>
|
||||
|
||||
## v0.2.15 (2023-02-24)
|
||||
|
||||
### New Features
|
||||
@@ -20,7 +66,7 @@ and this project adheres to
|
||||
|
||||
<csr-read-only-do-not-edit/>
|
||||
|
||||
- 2 commits contributed to the release.
|
||||
- 3 commits contributed to the release.
|
||||
- 2 days passed between releases.
|
||||
- 2 commits were understood as [conventional](https://www.conventionalcommits.org).
|
||||
- 0 issues like '(#ID)' were seen in commit messages
|
||||
@@ -32,6 +78,7 @@ and this project adheres to
|
||||
<details><summary>view details</summary>
|
||||
|
||||
* **Uncategorized**
|
||||
- Release dagger-core v0.2.7, dagger-sdk v0.2.15 ([`6a9a560`](https://github.com/kjuulh/dagger-rs/commit/6a9a560cdca097abf23371d44599a2f1b726ae7f))
|
||||
- set deserialize on enums as well ([`e578b0e`](https://github.com/kjuulh/dagger-rs/commit/e578b0e371e13bc30ada793b7cd6ebe75ba83a07))
|
||||
- update to dagger-v0.3.13 ([`3e8ca8d`](https://github.com/kjuulh/dagger-rs/commit/3e8ca8d86eafdc1f9d5e8b69f14fb60509549e0f))
|
||||
</details>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "dagger-sdk"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
edition = "2021"
|
||||
readme = "README.md"
|
||||
license-file = "LICENSE.MIT"
|
||||
@@ -11,7 +11,7 @@ publish = true
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dagger-core = { path = "../dagger-core", version = "^0.2.7" }
|
||||
dagger-core = { path = "../dagger-core", version = "^0.2.8" }
|
||||
|
||||
base64 = "0.21.0"
|
||||
eyre = "0.6.8"
|
||||
|
@@ -27,7 +27,7 @@ cargo add dagger-sdk
|
||||
```rust
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
let client = dagger_sdk::connect()?;
|
||||
let client = dagger_sdk::connect().await?;
|
||||
|
||||
let version = client
|
||||
.container()
|
||||
@@ -46,9 +46,3 @@ And run it like a normal application:
|
||||
```bash
|
||||
cargo run
|
||||
```
|
||||
|
||||
### Disclaimer
|
||||
|
||||
You are free to use something else than `tokio`, I haven't tested it with
|
||||
anything else, but it should work with any other runtime. We don't rely on it
|
||||
specifically. That might change in the future though.
|
||||
|
@@ -22,6 +22,11 @@ pub struct SecretId(String);
|
||||
pub struct SocketId(String);
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct BuildArg {
|
||||
pub value: String,
|
||||
pub name: String,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct PipelineLabel {
|
||||
pub name: String,
|
||||
pub value: String,
|
||||
}
|
||||
@@ -97,8 +102,12 @@ pub struct ContainerExportOpts {
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct ContainerPipelineOpts<'a> {
|
||||
/// Pipeline description.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub description: Option<&'a str>,
|
||||
/// Pipeline labels.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub labels: Option<Vec<PipelineLabel>>,
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct ContainerPublishOpts {
|
||||
@@ -138,6 +147,12 @@ pub struct ContainerWithExecOpts<'a> {
|
||||
/// The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub experimental_privileged_nesting: Option<bool>,
|
||||
/// Execute the command with all root capabilities. This is similar to running a command
|
||||
/// with "sudo" or executing `docker run` with the `--privileged` flag. Containerization
|
||||
/// does not provide any security guarantees when using this option. It should only be used
|
||||
/// when absolutely necessary and only with trusted commands.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub insecure_root_capabilities: Option<bool>,
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct ContainerWithExposedPortOpts<'a> {
|
||||
@@ -252,6 +267,7 @@ impl Container {
|
||||
/// Retrieves an endpoint that clients can use to reach this container.
|
||||
/// If no port is specified, the first exposed port is used. If none exist an error is returned.
|
||||
/// If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -265,6 +281,7 @@ impl Container {
|
||||
/// Retrieves an endpoint that clients can use to reach this container.
|
||||
/// If no port is specified, the first exposed port is used. If none exist an error is returned.
|
||||
/// If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -358,7 +375,7 @@ impl Container {
|
||||
};
|
||||
}
|
||||
/// Exit code of the last executed command. Zero means success.
|
||||
/// Null if no command has been executed.
|
||||
/// Errors if no command has been executed.
|
||||
pub async fn exit_code(&self) -> eyre::Result<isize> {
|
||||
let query = self.selection.select("exitCode");
|
||||
|
||||
@@ -404,7 +421,8 @@ impl Container {
|
||||
|
||||
query.execute(&graphql_client(&self.conn)).await
|
||||
}
|
||||
/// Retrieves the list of exposed ports
|
||||
/// Retrieves the list of exposed ports.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
pub fn exposed_ports(&self) -> Vec<Port> {
|
||||
let query = self.selection.select("exposedPorts");
|
||||
|
||||
@@ -460,6 +478,7 @@ impl Container {
|
||||
};
|
||||
}
|
||||
/// Retrieves a hostname which can be used by clients to reach this container.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
pub async fn hostname(&self) -> eyre::Result<String> {
|
||||
let query = self.selection.select("hostname");
|
||||
|
||||
@@ -505,6 +524,7 @@ impl Container {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Pipeline name.
|
||||
/// * `opt` - optional argument, see inner type for documentation, use <func>_opts to use
|
||||
pub fn pipeline(&self, name: impl Into<String>) -> Container {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
@@ -522,6 +542,7 @@ impl Container {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Pipeline name.
|
||||
/// * `opt` - optional argument, see inner type for documentation, use <func>_opts to use
|
||||
pub fn pipeline_opts<'a>(
|
||||
&self,
|
||||
@@ -534,6 +555,9 @@ impl Container {
|
||||
if let Some(description) = opts.description {
|
||||
query = query.arg("description", description);
|
||||
}
|
||||
if let Some(labels) = opts.labels {
|
||||
query = query.arg("labels", labels);
|
||||
}
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
@@ -600,14 +624,14 @@ impl Container {
|
||||
};
|
||||
}
|
||||
/// The error stream of the last executed command.
|
||||
/// Null if no command has been executed.
|
||||
/// Errors if no command has been executed.
|
||||
pub async fn stderr(&self) -> eyre::Result<String> {
|
||||
let query = self.selection.select("stderr");
|
||||
|
||||
query.execute(&graphql_client(&self.conn)).await
|
||||
}
|
||||
/// The output stream of the last executed command.
|
||||
/// Null if no command has been executed.
|
||||
/// Errors if no command has been executed.
|
||||
pub async fn stdout(&self) -> eyre::Result<String> {
|
||||
let query = self.selection.select("stdout");
|
||||
|
||||
@@ -796,6 +820,9 @@ impl Container {
|
||||
experimental_privileged_nesting,
|
||||
);
|
||||
}
|
||||
if let Some(insecure_root_capabilities) = opts.insecure_root_capabilities {
|
||||
query = query.arg("insecureRootCapabilities", insecure_root_capabilities);
|
||||
}
|
||||
|
||||
return Container {
|
||||
proc: self.proc.clone(),
|
||||
@@ -807,6 +834,7 @@ impl Container {
|
||||
/// Exposed ports serve two purposes:
|
||||
/// - For health checks and introspection, when running services
|
||||
/// - For setting the EXPOSE OCI field when publishing the container
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -828,6 +856,7 @@ impl Container {
|
||||
/// Exposed ports serve two purposes:
|
||||
/// - For health checks and introspection, when running services
|
||||
/// - For setting the EXPOSE OCI field when publishing the container
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -1159,6 +1188,7 @@ impl Container {
|
||||
/// Establish a runtime dependency on a service. The service will be started automatically when needed and detached when it is no longer needed.
|
||||
/// The service will be reachable from the container via the provided hostname alias.
|
||||
/// The service dependency will also convey to any files or directories produced by the container.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -1247,6 +1277,7 @@ impl Container {
|
||||
};
|
||||
}
|
||||
/// Unexpose a previously exposed port.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -1265,6 +1296,7 @@ impl Container {
|
||||
}
|
||||
|
||||
/// Unexpose a previously exposed port.
|
||||
/// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
@@ -1391,8 +1423,12 @@ pub struct DirectoryEntriesOpts<'a> {
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct DirectoryPipelineOpts<'a> {
|
||||
/// Pipeline description.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub description: Option<&'a str>,
|
||||
/// Pipeline labels.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub labels: Option<Vec<PipelineLabel>>,
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct DirectoryWithDirectoryOpts<'a> {
|
||||
@@ -1574,10 +1610,11 @@ impl Directory {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
/// Creates a named sub-pipeline.
|
||||
/// Creates a named sub-pipeline
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Pipeline name.
|
||||
/// * `opt` - optional argument, see inner type for documentation, use <func>_opts to use
|
||||
pub fn pipeline(&self, name: impl Into<String>) -> Directory {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
@@ -1591,10 +1628,11 @@ impl Directory {
|
||||
};
|
||||
}
|
||||
|
||||
/// Creates a named sub-pipeline.
|
||||
/// Creates a named sub-pipeline
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Pipeline name.
|
||||
/// * `opt` - optional argument, see inner type for documentation, use <func>_opts to use
|
||||
pub fn pipeline_opts<'a>(
|
||||
&self,
|
||||
@@ -1607,6 +1645,9 @@ impl Directory {
|
||||
if let Some(description) = opts.description {
|
||||
query = query.arg("description", description);
|
||||
}
|
||||
if let Some(labels) = opts.labels {
|
||||
query = query.arg("labels", labels);
|
||||
}
|
||||
|
||||
return Directory {
|
||||
proc: self.proc.clone(),
|
||||
@@ -2370,8 +2411,12 @@ pub struct QueryHttpOpts {
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct QueryPipelineOpts<'a> {
|
||||
/// Pipeline description.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub description: Option<&'a str>,
|
||||
/// Pipeline labels.
|
||||
#[builder(setter(into, strip_option), default)]
|
||||
pub labels: Option<Vec<PipelineLabel>>,
|
||||
}
|
||||
#[derive(Builder, Debug, PartialEq)]
|
||||
pub struct QuerySocketOpts {
|
||||
@@ -2582,10 +2627,11 @@ impl Query {
|
||||
conn: self.conn.clone(),
|
||||
};
|
||||
}
|
||||
/// Creates a named sub-pipeline
|
||||
/// Creates a named sub-pipeline.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Pipeline name.
|
||||
/// * `opt` - optional argument, see inner type for documentation, use <func>_opts to use
|
||||
pub fn pipeline(&self, name: impl Into<String>) -> Query {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
@@ -2599,10 +2645,11 @@ impl Query {
|
||||
};
|
||||
}
|
||||
|
||||
/// Creates a named sub-pipeline
|
||||
/// Creates a named sub-pipeline.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Pipeline name.
|
||||
/// * `opt` - optional argument, see inner type for documentation, use <func>_opts to use
|
||||
pub fn pipeline_opts<'a>(&self, name: impl Into<String>, opts: QueryPipelineOpts<'a>) -> Query {
|
||||
let mut query = self.selection.select("pipeline");
|
||||
@@ -2611,6 +2658,9 @@ impl Query {
|
||||
if let Some(description) = opts.description {
|
||||
query = query.arg("description", description);
|
||||
}
|
||||
if let Some(labels) = opts.labels {
|
||||
query = query.arg("labels", labels);
|
||||
}
|
||||
|
||||
return Query {
|
||||
proc: self.proc.clone(),
|
||||
@@ -2714,9 +2764,9 @@ impl Socket {
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
pub enum CacheSharingMode {
|
||||
SHARED,
|
||||
PRIVATE,
|
||||
LOCKED,
|
||||
SHARED,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
pub enum NetworkProtocol {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
use dagger_sdk::{connect, ContainerExecOptsBuilder};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_example_container() {
|
||||
@@ -19,3 +20,99 @@ async fn test_example_container() {
|
||||
|
||||
assert_eq!(out, "3.16.2\n".to_string())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_directory() {
|
||||
let c = connect().await.unwrap();
|
||||
|
||||
let contents = c
|
||||
.directory()
|
||||
.with_new_file("/hello.txt", "world")
|
||||
.file("/hello.txt")
|
||||
.contents()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!("world", contents)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_git() {
|
||||
let c = connect().await.unwrap();
|
||||
|
||||
let tree = c.git("github.com/dagger/dagger").branch("main").tree();
|
||||
|
||||
let _ = tree
|
||||
.entries()
|
||||
.await
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|f| f.as_str() == "README.md")
|
||||
.unwrap();
|
||||
|
||||
let readme_file = tree.file("README.md");
|
||||
|
||||
let readme = readme_file.contents().await.unwrap();
|
||||
assert_eq!(true, readme.find("Dagger").is_some());
|
||||
|
||||
let readme_id = readme_file.id().await.unwrap();
|
||||
let other_readme = c.file(readme_id).contents().await.unwrap();
|
||||
|
||||
assert_eq!(readme, other_readme);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_container() {
|
||||
let client = connect().await.unwrap();
|
||||
|
||||
let alpine = client.container().from("alpine:3.16.2");
|
||||
|
||||
let contents = alpine
|
||||
.fs()
|
||||
.file("/etc/alpine-release")
|
||||
.contents()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(contents, "3.16.2\n".to_string());
|
||||
|
||||
let out = alpine
|
||||
.exec_opts(
|
||||
ContainerExecOptsBuilder::default()
|
||||
.args(vec!["cat", "/etc/alpine-release"])
|
||||
.build()
|
||||
.unwrap(),
|
||||
)
|
||||
.stdout()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(out, "3.16.2\n".to_string());
|
||||
|
||||
let id = alpine.id().await.unwrap();
|
||||
let contents = client
|
||||
.container_opts(dagger_sdk::QueryContainerOpts {
|
||||
id: Some(id),
|
||||
platform: None,
|
||||
})
|
||||
.fs()
|
||||
.file("/etc/alpine-release")
|
||||
.contents()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(contents, "3.16.2\n".to_string());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_err_message() {
|
||||
let client = connect().await.unwrap();
|
||||
|
||||
let alpine = client.container().from("fake.invalid:latest").id().await;
|
||||
assert_eq!(alpine.is_err(), true);
|
||||
let err = alpine.expect_err("Tests expect err");
|
||||
|
||||
let error_msg = r#"
|
||||
GQLClient Error: Look at json field for more details
|
||||
Message: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
|
||||
"#;
|
||||
|
||||
assert_eq!(err.to_string().as_str(), error_msg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user