From 1e384c4e9a0f8a29e165607b5782e7c51fd1656e Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Fri, 18 Feb 2022 15:12:58 +0100 Subject: [PATCH] Apply Solomon comments - Simplify cache id parameter with a field `name` - Configure GOOS & GOARCH values - Container image can now be overridden - Simplify build export Signed-off-by: Vasek - Tom C --- pkg/universe.dagger.io/go/build.cue | 14 +++++++------- pkg/universe.dagger.io/go/container.cue | 17 +++++------------ pkg/universe.dagger.io/go/test/container.cue | 13 +++++++++++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pkg/universe.dagger.io/go/build.cue b/pkg/universe.dagger.io/go/build.cue index b8084c07..5b4e6e03 100644 --- a/pkg/universe.dagger.io/go/build.cue +++ b/pkg/universe.dagger.io/go/build.cue @@ -28,7 +28,11 @@ import ( container: #Container & { "source": source - "env": env + "env": { + env + GOOS: os + GOARCH: arch + } command: { args: [package] flags: { @@ -39,12 +43,8 @@ import ( "-o": "/output/" } } + export: directories: "/output/": _ } - _binary: dagger.#Subdir & { - input: container.output.rootfs - path: "/output" - } - - binary: _binary.output + binary: container.export.directories."/output/".contents } diff --git a/pkg/universe.dagger.io/go/container.cue b/pkg/universe.dagger.io/go/container.cue index cc7da69c..81e00f28 100644 --- a/pkg/universe.dagger.io/go/container.cue +++ b/pkg/universe.dagger.io/go/container.cue @@ -8,27 +8,20 @@ import ( // A standalone go environment to run go command #Container: { - // Go version to use - version: *#DefaultVersion | string + // Container app name + name: *"go_builder" | string // Source code source: dagger.#FS - // Configure caching - cache: { - id: *"go_build" | string - } - // Use go image - _image: #Image & { - "version": version - } + _image: #Image _sourcePath: "/src" _cachePath: "/root/.cache/gocache" docker.#Run & { - input: _image.output + input: *_image.output | docker.#Image workdir: "/src" command: name: "go" mounts: { @@ -38,7 +31,7 @@ import ( } "go assets cache": { contents: dagger.#CacheDir & { - id: "\(cache.id)_assets" + id: "\(name)_assets" } dest: _cachePath } diff --git a/pkg/universe.dagger.io/go/test/container.cue b/pkg/universe.dagger.io/go/test/container.cue index fd925cc3..ac7056c7 100644 --- a/pkg/universe.dagger.io/go/test/container.cue +++ b/pkg/universe.dagger.io/go/test/container.cue @@ -3,6 +3,7 @@ package go import ( "dagger.io/dagger" "universe.dagger.io/go" + "universe.dagger.io/alpine" ) dagger.#Plan & { @@ -13,5 +14,17 @@ dagger.#Plan & { source: _source command: args: ["version"] } + + overide: { + base: alpine.#Build & { + packages: go: _ + } + + command: go.#Container & { + input: base.output + source: _source + command: args: ["version"] + } + } } }