This commit is contained in:
Kasper Juul Hermansen 2022-04-19 22:45:36 +02:00
parent 9ddbc60a3b
commit f496357522
9 changed files with 218 additions and 0 deletions

View File

@ -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
}
}
}

View File

@ -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"
},
]
}
}

View File

@ -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"
}

View File

@ -0,0 +1,15 @@
package rust
// Test a rust package
#Test: {
// Package to test
package: *"." | string
#Container & {
command: {
args: [package]
flags: test: true
}
}
}

View File

@ -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]

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View File

@ -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'"]
}
}
}
}
}

View File

@ -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!"
}
}
}
}

View File

@ -0,0 +1,10 @@
setup() {
load '../../../../bats_helpers'
common_setup
}
@test "rust" {
dagger "do" -p ./publish.cue test
dagger "do" -p ./image.cue test
}