Apply Solomon comments on universe.dagger.io/go
- Improve #Container with a better docker.#Run integration - Supports concurrency caching in #Container - Simplify code maintainability and readability - Simplify binary export in #Build - Support multi binary building - External #Version management Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
This commit is contained in:
parent
e49bb34e87
commit
2887139bf7
@ -1,4 +1,5 @@
|
||||
# generated by dagger
|
||||
dagger.lock
|
||||
alpha.dagger.io
|
||||
universe.dagger.io
|
||||
dagger.io
|
||||
universe.dagger.io
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 | *""
|
||||
|
||||
|
@ -6,6 +6,12 @@ package go
|
||||
package: *"." | string
|
||||
|
||||
#Container & {
|
||||
args: ["test", "-v", package]
|
||||
command: {
|
||||
args: [package]
|
||||
flags: {
|
||||
test: true
|
||||
"-v": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
} & {
|
||||
|
@ -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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 & {}
|
||||
|
Reference in New Issue
Block a user