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"
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
160
ci/main.cue
160
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: _
|
||||||
|
packages: git: _
|
||||||
|
}
|
||||||
|
|
||||||
|
_revision: bash.#Run & {
|
||||||
|
input: _image.output
|
||||||
|
workdir: "/src"
|
||||||
|
mounts: source: {
|
||||||
|
dest: "/src"
|
||||||
|
contents: _source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
script: contents: #"""
|
||||||
|
printf "$(git rev-parse --short HEAD)" > /revision
|
||||||
|
"""#
|
||||||
|
export: files: "/revision": string
|
||||||
}
|
}
|
||||||
env: GOMODCACHE: mounts["go mod cache"].dest
|
|
||||||
|
output: _revision.export.files["/revision"]
|
||||||
}
|
}
|
||||||
|
|
||||||
_mountSourceCode: {
|
build: go.#Build & {
|
||||||
mounts: "dagger source code": {
|
source: _source
|
||||||
contents: _source.output
|
package: "./cmd/dagger/"
|
||||||
dest: "/usr/src/dagger"
|
os: client.platform.os
|
||||||
}
|
arch: client.platform.arch
|
||||||
workdir: mounts["dagger source code"].dest
|
|
||||||
}
|
|
||||||
|
|
||||||
_baseImages: #Images
|
ldflags: "-s -w -X go.dagger.io/dagger/version.Revision=\(version.output)"
|
||||||
|
|
||||||
// Go build the dagger binary
|
|
||||||
// depends on goLint and goTest to complete successfully
|
|
||||||
build: bash.#Run & {
|
|
||||||
_mountSourceCode
|
|
||||||
_mountGoCache
|
|
||||||
|
|
||||||
input: _baseImages.goBuilder
|
|
||||||
|
|
||||||
env: {
|
env: {
|
||||||
GOOS: client.platform.os
|
|
||||||
GOARCH: client.platform.arch
|
|
||||||
CGO_ENABLED: "0"
|
CGO_ENABLED: "0"
|
||||||
// Makes sure the linter and unit tests complete before starting the build
|
// Makes sure the linter and unit tests complete before starting the build
|
||||||
"__depends_lint": "\(goLint.exit)"
|
// "__depends_lint": "\(goLint.exit)"
|
||||||
"__depends_tests": "\(goTest.exit)"
|
// "__depends_tests": "\(goTest.exit)"
|
||||||
}
|
}
|
||||||
|
|
||||||
script: contents: #"""
|
|
||||||
mkdir -p /build
|
|
||||||
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: directories: "/build": _
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
cue: docker.#Build & {
|
||||||
script: contents: "golangci-lint run -v --timeout 5m"
|
steps: [
|
||||||
}
|
alpine.#Build & {
|
||||||
|
packages: bash: _
|
||||||
|
packages: curl: _
|
||||||
|
packages: git: _
|
||||||
|
},
|
||||||
|
|
||||||
// CUE lint
|
docker.#Copy & {
|
||||||
cueLint: bash.#Run & {
|
contents: _source
|
||||||
_mountSourceCode
|
source: "go.mod"
|
||||||
|
dest: "go.mod"
|
||||||
|
},
|
||||||
|
|
||||||
input: _baseImages.cue
|
// Install CUE
|
||||||
script: contents: #"""
|
bash.#Run & {
|
||||||
# Format the cue code
|
script: contents: #"""
|
||||||
find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s
|
export CUE_VERSION="$(grep cue ./go.mod | cut -d' ' -f2 | head -1 | sed -E 's/\.[[:digit:]]\.[[:alnum:]]+-[[:alnum:]]+$//')"
|
||||||
# Check that all formatted files where committed
|
export CUE_TARBALL="cue_${CUE_VERSION}_linux_amd64.tar.gz"
|
||||||
test -z $(git status -s . | grep -e '^ M' | grep .cue | cut -d ' ' -f3)
|
echo "Installing cue version $CUE_VERSION"
|
||||||
"""#
|
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