diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/container.cue b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/container.cue new file mode 100644 index 00000000..9e2a0b80 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/container.cue @@ -0,0 +1,29 @@ +package rust + +import ( + "dagger.io/dagger" + "universe.dagger.io/docker" +) + +#Container: { + // Container publisher + name: *"rust_publisher" | string + + // Source code + source: dagger.#FS + + // Rust image + _image: #Image + + _sourcePath: "/src" + + docker.#Run & { + input: *_image.output | docker.#Image + workdir: "/src" + command: name: "rust" + mounts: "source": { + dest: _sourcePath + contents: source + } + } +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/image.cue b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/image.cue new file mode 100644 index 00000000..e94819e8 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/image.cue @@ -0,0 +1,21 @@ + +package rust + +import ( + "universe.dagger.io/docker" +) + +// rust image default version +_#DefaultVersion: "1.60" + +// Pull rust base image +#Image: { + version: *_#DefaultVersion | string + docker.#Build & { + steps: [ + docker.#Pull & { + source: "rust:\(version)-alpine" + }, + ] + } +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/publish.cue b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/publish.cue new file mode 100644 index 00000000..5bebcf65 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/publish.cue @@ -0,0 +1,34 @@ +package rust + +import ( + "dagger.io/dagger" +) + +// Publish a rust binary +#Publish: { + // Source code + source: dagger.#FS + + // Target package to publish + package: *"." | string + + env: [string]: string + + container: #Container & { + "source": source + "env": { + env + } + command: { + args: [package] + flags: { + publish: true + "-o": "/output/" + } + } + export: directories: "/output": _ + } + + // Directory containing the output of the publish + output: container.export.directories."/output" +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test.cue b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test.cue new file mode 100644 index 00000000..4e584ae0 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test.cue @@ -0,0 +1,15 @@ + +package rust + +// Test a rust package +#Test: { + // Package to test + package: *"." | string + + #Container & { + command: { + args: [package] + flags: test: true + } + } +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/data/hello_world/Cargo.toml b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/data/hello_world/Cargo.toml new file mode 100644 index 00000000..624cb069 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/data/hello_world/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "hello_world" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/data/hello_world/src/main.rs b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/data/hello_world/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/data/hello_world/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/image.cue b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/image.cue new file mode 100644 index 00000000..9656ad8e --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/image.cue @@ -0,0 +1,40 @@ + +package rust + +import ( + "dagger.io/dagger" + "universe.dagger.io/x/contact@kjuulh.io/rust" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + actions: test: { + _source: dagger.#Scratch & {} + + simple: { + _image: rust.#Image & {} + + verify: docker.#Run & { + input: _image.output + command: { + name: "/bin/sh" + args: ["-c", "cargo version | grep '1.6'"] + } + } + } + + custom: { + _image: rust.#Image & { + version: "1.56" + } + + verify: docker.#Run & { + input: _image.output + command: { + name: "/bin/sh" + args: ["-c", "cargo version | grep '1.56'"] + } + } + } + } +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/publish.cue b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/publish.cue new file mode 100644 index 00000000..a2f53f7e --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/publish.cue @@ -0,0 +1,58 @@ +package rust + +import ( + "dagger.io/dagger" + "dagger.io/dagger/core" + "universe.dagger.io/x/contact@kjuulh.io/rust" + "universe.dagger.io/docker" + "universe.dagger.io/alpine" +) + +dagger.#Plan & { + client: filesystem: "./data/hello_world": read: contents: dagger.#FS + + actions: test: { + _baseImage: { + build: alpine.#Build & { + packages: { + "ca-certificates": {} + "krb5-libs": {} + libgcc: {} + libintl: {} + "libssl1.1": {} + "libstdc++": {} + zlib: {} + } + } + output: build.output + } + + simple: { + publish: rust.#Publish & { + source: client.filesystem."./data".read.contents + package: "hello" + } + + exec: docker.#Run & { + input: _baseImage.output + command: { + name: "/bin/sh" + args: ["-c", "/app/hello_world >> /output.txt"] + } + env: NAME: "dagger" + mounts: binary: { + dest: "/app" + contents: publish.output + source: "/" + } + } + + verify: core.#ReadFile & { + input: exec.output.rootfs + path: "/output.txt" + } & { + contents: "Hi dagger!" + } + } + } +} diff --git a/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/test.bats b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/test.bats new file mode 100644 index 00000000..a9469058 --- /dev/null +++ b/pkg/universe.dagger.io/x/contact@kjuulh.io/rust/test/test.bats @@ -0,0 +1,10 @@ +setup() { + load '../../../../bats_helpers' + + common_setup +} + +@test "rust" { + dagger "do" -p ./publish.cue test + dagger "do" -p ./image.cue test +}