ci: improve dogfood configuration
- Use official Go package - Use golangci-lint package - Fix node_modules exclusion for local source - Improve CUE performance by optimizing cache hits Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
8fe29cdc76
commit
31daeb05ed
@ -1,80 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"universe.dagger.io/docker"
|
|
||||||
)
|
|
||||||
|
|
||||||
let GoVersion = "1.17"
|
|
||||||
let GolangCILintVersion = "1.44.0"
|
|
||||||
let CUEVersion = "0.4.2"
|
|
||||||
|
|
||||||
// Base container images used for the CI
|
|
||||||
#Images: {
|
|
||||||
|
|
||||||
// base image to build go binaries
|
|
||||||
goBuilder: _goBuilder.output
|
|
||||||
_goBuilder: docker.#Build & {
|
|
||||||
_packages: ["bash", "git", "alpine-sdk"]
|
|
||||||
|
|
||||||
steps: [
|
|
||||||
docker.#Pull & {
|
|
||||||
source: "index.docker.io/golang:\(GoVersion)-alpine"
|
|
||||||
},
|
|
||||||
for pkg in _packages {
|
|
||||||
docker.#Run & {
|
|
||||||
command: {
|
|
||||||
name: "apk"
|
|
||||||
args: ["add", pkg]
|
|
||||||
flags: {
|
|
||||||
"-U": true
|
|
||||||
"--no-cache": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
// base image for the Go linter
|
|
||||||
// https://golangci-lint.run/usage/install/#docker
|
|
||||||
goLinter: _goLinter.output
|
|
||||||
_goLinter: docker.#Pull & {
|
|
||||||
source: "index.docker.io/golangci/golangci-lint:v\(GolangCILintVersion)"
|
|
||||||
}
|
|
||||||
|
|
||||||
// base image for CUE cli + alpine distrib
|
|
||||||
cue: _cue._alpine.output
|
|
||||||
_cue: {
|
|
||||||
_cueBinary: docker.#Pull & {
|
|
||||||
source: "index.docker.io/cuelang/cue:\(CUEVersion)"
|
|
||||||
}
|
|
||||||
|
|
||||||
_alpine: docker.#Build & {
|
|
||||||
_packages: ["bash", "git"]
|
|
||||||
|
|
||||||
steps: [
|
|
||||||
docker.#Pull & {
|
|
||||||
source: "index.docker.io/alpine:3"
|
|
||||||
},
|
|
||||||
for pkg in _packages {
|
|
||||||
docker.#Run & {
|
|
||||||
command: {
|
|
||||||
name: "apk"
|
|
||||||
args: ["add", pkg]
|
|
||||||
flags: {
|
|
||||||
"-U": true
|
|
||||||
"--no-cache": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
docker.#Copy & {
|
|
||||||
// input: _alpine.output
|
|
||||||
contents: _cueBinary.output.rootfs
|
|
||||||
source: "/usr/bin/cue"
|
|
||||||
dest: "/usr/bin/cue"
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
162
ci/main.cue
162
ci/main.cue
@ -2,98 +2,136 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"dagger.io/dagger"
|
"dagger.io/dagger"
|
||||||
"dagger.io/dagger/core"
|
|
||||||
"universe.dagger.io/bash"
|
"universe.dagger.io/bash"
|
||||||
|
"universe.dagger.io/alpine"
|
||||||
|
"universe.dagger.io/docker"
|
||||||
|
"universe.dagger.io/go"
|
||||||
|
"universe.dagger.io/go/golangci"
|
||||||
)
|
)
|
||||||
|
|
||||||
dagger.#Plan & {
|
dagger.#Plan & {
|
||||||
|
|
||||||
// FIXME: Ideally we would want to automatically set the platform's arch identical to the host
|
// 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)
|
// to avoid the performance hit caused by qemu (linter goes from <3s to >3m when arch is x86)
|
||||||
// Uncomment if running locally on Mac M1 to bypass qemu
|
// Uncomment if running locally on Mac M1 to bypass qemu
|
||||||
// platform: "linux/aarch64"
|
// platform: "linux/aarch64"
|
||||||
platform: "linux/amd64"
|
platform: "linux/amd64"
|
||||||
|
|
||||||
client: filesystem: "./build": write: contents: actions.build.export.directories["/build"]
|
client: filesystem: "../": read: exclude: [
|
||||||
|
"ci",
|
||||||
|
"**/node_modules",
|
||||||
|
"cmd/dagger/dagger",
|
||||||
|
"cmd/dagger/dagger-debug",
|
||||||
|
]
|
||||||
|
client: filesystem: "./build": write: contents: actions.build.output
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
_mountGoCache: {
|
_source: client.filesystem["../"].read.contents
|
||||||
mounts: "go mod cache": {
|
|
||||||
dest: "/root/.gocache"
|
// FIXME: this can be removed once `go` supports built-in VCS info
|
||||||
contents: core.#CacheDir & {
|
version: {
|
||||||
id: "go mod cache"
|
_image: alpine.#Build & {
|
||||||
}
|
packages: bash: _
|
||||||
}
|
packages: curl: _
|
||||||
env: GOMODCACHE: mounts["go mod cache"].dest
|
packages: git: _
|
||||||
}
|
}
|
||||||
|
|
||||||
_mountSourceCode: {
|
_revision: bash.#Run & {
|
||||||
mounts: "dagger source code": {
|
input: _image.output
|
||||||
contents: _source.output
|
workdir: "/src"
|
||||||
dest: "/usr/src/dagger"
|
mounts: source: {
|
||||||
}
|
dest: "/src"
|
||||||
workdir: mounts["dagger source code"].dest
|
contents: _source
|
||||||
}
|
|
||||||
|
|
||||||
_baseImages: #Images
|
|
||||||
|
|
||||||
// Go build the dagger binary
|
|
||||||
// depends on goLint and goTest to complete successfully
|
|
||||||
build: bash.#Run & {
|
|
||||||
_mountSourceCode
|
|
||||||
_mountGoCache
|
|
||||||
|
|
||||||
input: _baseImages.goBuilder
|
|
||||||
|
|
||||||
env: {
|
|
||||||
GOOS: client.platform.os
|
|
||||||
GOARCH: client.platform.arch
|
|
||||||
CGO_ENABLED: "0"
|
|
||||||
// Makes sure the linter and unit tests complete before starting the build
|
|
||||||
"__depends_lint": "\(goLint.exit)"
|
|
||||||
"__depends_tests": "\(goTest.exit)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
script: contents: #"""
|
script: contents: #"""
|
||||||
mkdir -p /build
|
printf "$(git rev-parse --short HEAD)" > /revision
|
||||||
git_revision=$(git rev-parse --short HEAD)
|
|
||||||
go build -v -o /build/dagger \
|
|
||||||
-ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \
|
|
||||||
./cmd/dagger/
|
|
||||||
"""#
|
"""#
|
||||||
|
export: files: "/revision": string
|
||||||
|
}
|
||||||
|
|
||||||
export: directories: "/build": _
|
output: _revision.export.files["/revision"]
|
||||||
|
}
|
||||||
|
|
||||||
|
build: go.#Build & {
|
||||||
|
source: _source
|
||||||
|
package: "./cmd/dagger/"
|
||||||
|
os: client.platform.os
|
||||||
|
arch: client.platform.arch
|
||||||
|
|
||||||
|
ldflags: "-s -w -X go.dagger.io/dagger/version.Revision=\(version.output)"
|
||||||
|
|
||||||
|
env: {
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
// Makes sure the linter and unit tests complete before starting the build
|
||||||
|
// "__depends_lint": "\(goLint.exit)"
|
||||||
|
// "__depends_tests": "\(goTest.exit)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go unit tests
|
// Go unit tests
|
||||||
goTest: bash.#Run & {
|
test: go.#Test & {
|
||||||
_mountSourceCode
|
// container: image: _goImage.output
|
||||||
_mountGoCache
|
source: _source
|
||||||
|
package: "./..."
|
||||||
|
|
||||||
input: _baseImages.goBuilder
|
// FIXME: doesn't work with CGO_ENABLED=0
|
||||||
script: contents: "go test -race -v ./..."
|
// command: flags: "-race": true
|
||||||
|
|
||||||
|
env: {
|
||||||
|
// FIXME: removing this complains about lack of gcc
|
||||||
|
CGO_ENABLED: "0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go lint using golangci-lint
|
lint: {
|
||||||
goLint: bash.#Run & {
|
go: golangci.#Lint & {
|
||||||
_mountSourceCode
|
source: _source
|
||||||
_mountGoCache
|
version: "1.45"
|
||||||
|
|
||||||
input: _baseImages.goLinter
|
|
||||||
script: contents: "golangci-lint run -v --timeout 5m"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CUE lint
|
cue: docker.#Build & {
|
||||||
cueLint: bash.#Run & {
|
steps: [
|
||||||
_mountSourceCode
|
alpine.#Build & {
|
||||||
|
packages: bash: _
|
||||||
|
packages: curl: _
|
||||||
|
packages: git: _
|
||||||
|
},
|
||||||
|
|
||||||
input: _baseImages.cue
|
docker.#Copy & {
|
||||||
|
contents: _source
|
||||||
|
source: "go.mod"
|
||||||
|
dest: "go.mod"
|
||||||
|
},
|
||||||
|
|
||||||
|
// Install CUE
|
||||||
|
bash.#Run & {
|
||||||
script: contents: #"""
|
script: contents: #"""
|
||||||
# Format the cue code
|
export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2 | head -1 | sed -E 's/\.[[:digit:]]\.[[:alnum:]]+-[[:alnum:]]+$//')"
|
||||||
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
|
export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz"
|
||||||
# Check that all formatted files where committed
|
echo "Installing cue version $CUE_VERSION"
|
||||||
test -z $(git status -s . | grep -e '^ M' | grep .cue | cut -d ' ' -f3)
|
curl -L "https://github.com/cue-lang/cue/releases/download/${CUE_VERSION}/${CUE_TARBALL}" | tar zxf - -C /usr/local/bin
|
||||||
|
cue version
|
||||||
"""#
|
"""#
|
||||||
|
},
|
||||||
|
|
||||||
|
// CACHE: copy only *.cue files
|
||||||
|
docker.#Copy & {
|
||||||
|
contents: _source
|
||||||
|
include: ["*.cue"]
|
||||||
|
dest: "/cue"
|
||||||
|
},
|
||||||
|
|
||||||
|
// LINT
|
||||||
|
bash.#Run & {
|
||||||
|
workdir: "/cue"
|
||||||
|
script: contents: #"""
|
||||||
|
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -t -n 1 -P 8 cue fmt -s
|
||||||
|
test -z "$(git status -s . | grep -e "^ M" | grep "\.cue" | cut -d ' ' -f3 | tee /dev/stderr)"
|
||||||
|
"""#
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
source.cue
15
source.cue
@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"dagger.io/dagger/core"
|
|
||||||
)
|
|
||||||
|
|
||||||
_source: core.#Source & {
|
|
||||||
path: "."
|
|
||||||
exclude: [
|
|
||||||
"ci",
|
|
||||||
"node_modules",
|
|
||||||
"cmd/dagger/dagger",
|
|
||||||
"cmd/dagger/dagger-debug",
|
|
||||||
]
|
|
||||||
}
|
|
Reference in New Issue
Block a user