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 & {
"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
}

View File

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

View File

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