2022-02-10 05:48:22 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-02-11 01:09:08 +01:00
|
|
|
"strings"
|
|
|
|
|
2022-02-10 05:48:22 +01:00
|
|
|
"dagger.io/dagger/engine"
|
|
|
|
"universe.dagger.io/bash"
|
|
|
|
)
|
|
|
|
|
|
|
|
engine.#Plan & {
|
2022-02-18 05:39:40 +01:00
|
|
|
|
|
|
|
// FIXME: Ideally we would want to automatically set the platform's arch identical to the host
|
|
|
|
// to avoid the performance hit caused by qemu (linter goes from <3s to >3m when arch is x86)
|
|
|
|
platform: "linux/aarch64"
|
|
|
|
|
2022-02-10 05:48:22 +01:00
|
|
|
inputs: {
|
|
|
|
params: {
|
2022-02-11 01:09:08 +01:00
|
|
|
// FIXME: until we support a better way
|
2022-02-11 02:18:57 +01:00
|
|
|
os: string | *"darwin"
|
2022-02-11 01:09:08 +01:00
|
|
|
arch: string | *"amd64"
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
// FIXME: implement condition actions using params until we have a
|
|
|
|
// better way to select specific actions
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
directories: {
|
|
|
|
// dagger repository
|
|
|
|
source: path: "../"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs: directories: "go binaries": {
|
2022-02-17 20:58:31 +01:00
|
|
|
contents: actions.build.export.directories["/build"].contents
|
|
|
|
dest: "./build"
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
actions: {
|
2022-02-18 05:39:40 +01:00
|
|
|
_goModCache: "go mod cache": {
|
|
|
|
dest: "/gomodcache"
|
|
|
|
contents: engine.#CacheDir & {
|
|
|
|
id: "go mod cache"
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
_baseImages: #Images
|
2022-02-17 20:58:31 +01:00
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
_source: "dagger source code": {
|
2022-02-11 02:18:57 +01:00
|
|
|
contents: inputs.directories.source.contents
|
|
|
|
dest: "/usr/src/dagger"
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: build only if the linter passed
|
2022-02-10 05:48:22 +01:00
|
|
|
build: bash.#Run & {
|
2022-02-18 05:39:40 +01:00
|
|
|
input: _baseImages.goBuilder
|
2022-02-10 05:48:22 +01:00
|
|
|
|
2022-02-11 01:09:08 +01:00
|
|
|
env: {
|
|
|
|
GOMODCACHE: mounts["go mod cache"].dest
|
2022-02-11 02:18:57 +01:00
|
|
|
GOOS: strings.ToLower(inputs.params.os)
|
|
|
|
GOARCH: strings.ToLower(inputs.params.arch)
|
2022-02-11 01:09:08 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 05:48:22 +01:00
|
|
|
script: contents: #"""
|
|
|
|
mkdir -p /build
|
|
|
|
git_revision=$(git rev-parse --short HEAD)
|
2022-02-11 01:09:08 +01:00
|
|
|
CGO_ENABLED=0 \
|
2022-02-10 05:48:22 +01:00
|
|
|
go build -v -o /build/dagger \
|
|
|
|
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
|
|
|
./cmd/dagger/
|
|
|
|
"""#
|
|
|
|
|
2022-02-18 05:39:40 +01:00
|
|
|
workdir: mounts["dagger source code"].dest
|
2022-02-10 05:48:22 +01:00
|
|
|
mounts: {
|
2022-02-18 05:39:40 +01:00
|
|
|
_source
|
|
|
|
_goModCache
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
|
2022-02-11 01:09:08 +01:00
|
|
|
export: directories: "/build": _
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
2022-02-11 02:18:57 +01:00
|
|
|
|
|
|
|
goLint: bash.#Run & {
|
2022-02-18 05:39:40 +01:00
|
|
|
input: _baseImages.goLinter
|
2022-02-11 02:18:57 +01:00
|
|
|
|
|
|
|
script: contents: "golangci-lint run -v --timeout 5m"
|
|
|
|
workdir: mounts["dagger source code"].dest
|
|
|
|
mounts: {
|
2022-02-18 05:39:40 +01:00
|
|
|
_source
|
|
|
|
_goModCache
|
2022-02-11 02:18:57 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-10 05:48:22 +01:00
|
|
|
}
|
|
|
|
}
|