diff --git a/pkg/universe.dagger.io/cue.mod/pkg/.gitignore b/pkg/universe.dagger.io/cue.mod/pkg/.gitignore index 5089911a..331f139d 100644 --- a/pkg/universe.dagger.io/cue.mod/pkg/.gitignore +++ b/pkg/universe.dagger.io/cue.mod/pkg/.gitignore @@ -1,4 +1,5 @@ # generated by dagger dagger.lock alpha.dagger.io -universe.dagger.io +dagger.io +universe.dagger.io \ No newline at end of file diff --git a/pkg/universe.dagger.io/go/build.cue b/pkg/universe.dagger.io/go/build.cue index 5684460c..b8084c07 100644 --- a/pkg/universe.dagger.io/go/build.cue +++ b/pkg/universe.dagger.io/go/build.cue @@ -2,14 +2,10 @@ package go import ( "dagger.io/dagger" - "dagger.io/dagger/engine" ) // Build a go binary #Build: { - // Go version to use - version: *#Image.version | string - // Source code source: dagger.#FS @@ -28,24 +24,27 @@ import ( // LDFLAGS to use for linking ldflags: *"" | string - // Target binary output - output: string - env: [string]: string - _build: #Container & { - "version": version - "source": source - "env": env - args: ["build", "-v", "-tags", tags, "-ldflags", ldflags, "-o", output, package] + container: #Container & { + "source": source + "env": env + command: { + args: [package] + flags: { + build: true + "-v": true + "-tags": tags + "-ldflags": ldflags + "-o": "/output/" + } + } } - _copy: engine.#Copy & { - input: engine.#Scratch - contents: _build.output.rootfs - source: output - dest: output + _binary: dagger.#Subdir & { + input: container.output.rootfs + path: "/output" } - binary: _copy.output + binary: _binary.output } diff --git a/pkg/universe.dagger.io/go/container.cue b/pkg/universe.dagger.io/go/container.cue index 617f3b70..cc7da69c 100644 --- a/pkg/universe.dagger.io/go/container.cue +++ b/pkg/universe.dagger.io/go/container.cue @@ -3,20 +3,21 @@ package go import ( "dagger.io/dagger" - "dagger.io/dagger/engine" "universe.dagger.io/docker" ) // A standalone go environment to run go command #Container: { // Go version to use - version: *#Image.version | string + version: *#DefaultVersion | string // Source code source: dagger.#FS - // Arguments - args: [...string] + // Configure caching + cache: { + id: *"go_build" | string + } // Use go image _image: #Image & { @@ -29,18 +30,15 @@ import ( docker.#Run & { input: _image.output workdir: "/src" - command: { - name: "go" - "args": args - } + command: name: "go" mounts: { "source": { dest: _sourcePath contents: source } "go assets cache": { - contents: engine.#CacheDir & { - id: "\(_cachePath)_assets" + contents: dagger.#CacheDir & { + id: "\(cache.id)_assets" } dest: _cachePath } diff --git a/pkg/universe.dagger.io/go/image.cue b/pkg/universe.dagger.io/go/image.cue index ff46e0d5..9edbd2da 100644 --- a/pkg/universe.dagger.io/go/image.cue +++ b/pkg/universe.dagger.io/go/image.cue @@ -4,9 +4,12 @@ import ( "universe.dagger.io/docker" ) +// Go image default version +#DefaultVersion: "1.16" + // Build a go base image #Image: { - version: *"1.16" | string + version: *#DefaultVersion | string packages: [pkgName=string]: version: string | *"" diff --git a/pkg/universe.dagger.io/go/test.cue b/pkg/universe.dagger.io/go/test.cue index 6594bef8..5de2b94b 100644 --- a/pkg/universe.dagger.io/go/test.cue +++ b/pkg/universe.dagger.io/go/test.cue @@ -6,6 +6,12 @@ package go package: *"." | string #Container & { - args: ["test", "-v", package] + command: { + args: [package] + flags: { + test: true + "-v": true + } + } } } diff --git a/pkg/universe.dagger.io/go/test/build.cue b/pkg/universe.dagger.io/go/test/build.cue index 34e653e1..8f8dba2c 100644 --- a/pkg/universe.dagger.io/go/test/build.cue +++ b/pkg/universe.dagger.io/go/test/build.cue @@ -2,7 +2,6 @@ package go import ( "dagger.io/dagger" - "dagger.io/dagger/engine" "universe.dagger.io/go" "universe.dagger.io/docker" "universe.dagger.io/alpine" @@ -17,24 +16,23 @@ dagger.#Plan & { simple: { build: go.#Build & { source: inputs.directories.testhello.contents - output: "/bin/hello" } exec: docker.#Run & { input: _baseImage.output command: { name: "/bin/sh" - args: ["-c", "hello >> /output.txt"] + args: ["-c", "/bin/hello >> /output.txt"] } env: NAME: "dagger" mounts: binary: { - dest: build.output + dest: "/bin/hello" contents: build.binary - source: "/bin/hello" + source: "/test" } } - verify: engine.#ReadFile & { + verify: dagger.#ReadFile & { input: exec.output.rootfs path: "/output.txt" } & { diff --git a/pkg/universe.dagger.io/go/test/container.cue b/pkg/universe.dagger.io/go/test/container.cue index b845df9a..fd925cc3 100644 --- a/pkg/universe.dagger.io/go/test/container.cue +++ b/pkg/universe.dagger.io/go/test/container.cue @@ -2,17 +2,16 @@ package go import ( "dagger.io/dagger" - "dagger.io/dagger/engine" "universe.dagger.io/go" ) dagger.#Plan & { actions: tests: container: { - _source: engine.#Scratch & {} + _source: dagger.#Scratch & {} simple: go.#Container & { source: _source - args: ["version"] + command: args: ["version"] } } } diff --git a/pkg/universe.dagger.io/go/test/image.cue b/pkg/universe.dagger.io/go/test/image.cue index 9d45725b..5a7ecbbb 100644 --- a/pkg/universe.dagger.io/go/test/image.cue +++ b/pkg/universe.dagger.io/go/test/image.cue @@ -2,14 +2,13 @@ package go import ( "dagger.io/dagger" - "dagger.io/dagger/engine" "universe.dagger.io/go" "universe.dagger.io/docker" ) dagger.#Plan & { actions: tests: image: { - _source: engine.#Scratch & {} + _source: dagger.#Scratch & {} simple: { _image: go.#Image & {}