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 <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2022-02-18 15:12:58 +01:00 committed by Vasek - Tom C
parent 2887139bf7
commit 1e384c4e9a
No known key found for this signature in database
GPG Key ID: 175D82E572427960
3 changed files with 25 additions and 19 deletions

View File

@ -28,7 +28,11 @@ import (
container: #Container & { container: #Container & {
"source": source "source": source
"env": env "env": {
env
GOOS: os
GOARCH: arch
}
command: { command: {
args: [package] args: [package]
flags: { flags: {
@ -39,12 +43,8 @@ import (
"-o": "/output/" "-o": "/output/"
} }
} }
export: directories: "/output/": _
} }
_binary: dagger.#Subdir & { binary: container.export.directories."/output/".contents
input: container.output.rootfs
path: "/output"
}
binary: _binary.output
} }

View File

@ -8,27 +8,20 @@ import (
// A standalone go environment to run go command // A standalone go environment to run go command
#Container: { #Container: {
// Go version to use // Container app name
version: *#DefaultVersion | string name: *"go_builder" | string
// Source code // Source code
source: dagger.#FS source: dagger.#FS
// Configure caching
cache: {
id: *"go_build" | string
}
// Use go image // Use go image
_image: #Image & { _image: #Image
"version": version
}
_sourcePath: "/src" _sourcePath: "/src"
_cachePath: "/root/.cache/gocache" _cachePath: "/root/.cache/gocache"
docker.#Run & { docker.#Run & {
input: _image.output input: *_image.output | docker.#Image
workdir: "/src" workdir: "/src"
command: name: "go" command: name: "go"
mounts: { mounts: {
@ -38,7 +31,7 @@ import (
} }
"go assets cache": { "go assets cache": {
contents: dagger.#CacheDir & { contents: dagger.#CacheDir & {
id: "\(cache.id)_assets" id: "\(name)_assets"
} }
dest: _cachePath dest: _cachePath
} }

View File

@ -3,6 +3,7 @@ package go
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"universe.dagger.io/go" "universe.dagger.io/go"
"universe.dagger.io/alpine"
) )
dagger.#Plan & { dagger.#Plan & {
@ -13,5 +14,17 @@ dagger.#Plan & {
source: _source source: _source
command: args: ["version"] command: args: ["version"]
} }
overide: {
base: alpine.#Build & {
packages: go: _
}
command: go.#Container & {
input: base.output
source: _source
command: args: ["version"]
}
}
} }
} }