Simplify "dev dagger with dagger" example

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes 2021-04-06 01:37:31 +00:00
parent 6673ae69b3
commit 299a38c6b1
3 changed files with 70 additions and 84 deletions

71
dev.cue
View File

@ -1,8 +1,6 @@
package main package main
import ( import (
"strings"
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/alpine" "dagger.io/alpine"
) )
@ -10,13 +8,12 @@ import (
// Dagger source code // Dagger source code
source: dagger.#Artifact source: dagger.#Artifact
// Go environment build: #Container & {
goenv: #Container & { image: #ImageFromRef & {ref: "docker.io/golang:1.16-alpine"}
image: #ImageFromRef & {
ref: "docker.io/golang:1.16-alpine"
}
setup: "apk add --no-cache file" setup: [
"apk add --no-cache file",
]
volume: { volume: {
daggerSource: { daggerSource: {
@ -28,53 +25,31 @@ goenv: #Container & {
dest: "/root/.cache/gocache" dest: "/root/.cache/gocache"
} }
} }
// Add go to search path (FIXME: should be inherited from image metadata)
shell: search: "/usr/local/go/bin": true
env: { env: {
GOMODCACHE: volume.goCache.dest GOMODCACHE: volume.goCache.dest
CGO_ENABLED: "0" CGO_ENABLED: "0"
}
let pathPrefixes = ["/", "/usr/", "/usr/local/", "/usr/local/go/"] dir: "/src"
PATH: strings.Join([ outputDir: "/binaries"
for prefix in pathPrefixes {prefix + "sbin"}, command: """
for prefix in pathPrefixes {prefix + "bin"}, go test -v ./...
], ":") go build -o /binaries/ ./cmd/...
} """
command: {
debug: {
args: ["env"]
always: true
}
test: {
dir: "/src"
args: ["go", "test", "-v", "/src/..."]
}
build: {
dir: "/src"
args: ["go", "build", "-o", "/binaries/", "/src/cmd/..."]
outputDir: "/binaries"
}
}
} }
runner: #Container & { usage: #Container & {
image: alpine.#Image & { image: alpine.#Image
package: make: true
}
volume: daggerBinaries: { volume: binaries: {
from: goenv.command.build from: build
dest: "/usr/local/dagger/bin" dest: "/usr/local/dagger/bin/"
} }
env: PATH: "/bin:/usr/bin:/usr/local/bin:/usr/local/dagger/bin" shell: search: "/usr/local/dagger/bin": true
command: { command: "dagger help"
// Run `dagger help`
usage: args: ["dagger", "help"]
// FIXME: run integration tests
// Just a debug command to check that this config works
debug: {
args: ["env"]
env: FOO: "BAR"
}
}
} }

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"strings"
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
@ -41,8 +43,8 @@ import (
image: dagger.#Artifact image: dagger.#Artifact
// Optional setup script // Optional setup scripts
setup: string | *null setup: [...string]
// Environment variables shared by all commands // Environment variables shared by all commands
env: [string]: string env: [string]: string
@ -62,36 +64,44 @@ import (
} }
} }
command: [name=string]: { shell: {
args: [...string] path: string | *"/bin/sh"
dir: string | *"/" args: [...string] | *["-c"]
"env": env & { search: [string]: bool
[string]: string search: {
"/sbin": true
"/bin": true
"/usr/sbin": true
"/usr/bin": true
"/usr/local/sbin": true
"/usr/local/bin": true
} }
outputDir: string | *"/" }
always: true | *false env: PATH: string | *strings.Join([ for p, v in shell.search if v {p}], ":")
// Execute each command in a pristine filesystem state command: string
// (commands do not interfere with each other's changes)
#up: [ dir: string | *"/"
op.#Load & {from: image},
// Copy volumes with type=copy env: [string]: string
for _, v in volume if v.type == "copy" {
op.#Copy & { outputDir: string | *"/"
from: v.from always: true | *false
dest: v.dest
src: v.source #up: [
} op.#Load & {from: image},
}, // Copy volumes with type=copy
// Execute setup script for _, v in volume if v.type == "copy" {
if setup != null { op.#Copy & {
op.#Exec & { from: v.from
"env": env dest: v.dest
args: ["/bin/sh", "-c", setup] src: v.source
} }
}, },
// Execute setup commands, then main command
for cmd in setup + [command] {
op.#Exec & { op.#Exec & {
"args": args args: [shell.path] + shell.args + [cmd]
"env": env "env": env
"dir": dir "dir": dir
"always": always "always": always
@ -109,11 +119,10 @@ import (
} }
} }
} }
}, }
op.#Subdir & { },
dir: outputDir op.#Subdir & {
}, dir: outputDir
] },
} ]
} }

View File

@ -5,6 +5,8 @@ import (
"dagger.io/dagger/op" "dagger.io/dagger/op"
) )
#Image: dagger.#Artifact
#Ref: string #Ref: string
// Build a docker container image // Build a docker container image