From 297fded56dd15f97f678392b34e5504ad450ed31 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 23 Feb 2022 15:15:44 -0800 Subject: [PATCH] ci: ported to new Plan syntax + implemented CUE fmt + go linter + code cleanup Signed-off-by: Sam Alba --- ci/images.cue | 37 +++++++++++++++++++++++++++++++++++++ ci/main.cue | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/ci/images.cue b/ci/images.cue index be8615cb..8263b1c7 100644 --- a/ci/images.cue +++ b/ci/images.cue @@ -6,6 +6,7 @@ import ( let GoVersion = "1.17" let GolangCILintVersion = "1.44.0" +let CUEVersion = "0.4.2" // Base container images used for the CI #Images: { @@ -40,4 +41,40 @@ let GolangCILintVersion = "1.44.0" _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" + }, + ] + } + } } diff --git a/ci/main.cue b/ci/main.cue index ba877a59..27704095 100644 --- a/ci/main.cue +++ b/ci/main.cue @@ -3,11 +3,11 @@ package main import ( "strings" - "dagger.io/dagger/engine" + "dagger.io/dagger" "universe.dagger.io/bash" ) -engine.#Plan & { +dagger.#Plan & { // 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) @@ -29,22 +29,25 @@ engine.#Plan & { } } - outputs: directories: "go binaries": { - contents: actions.build.export.directories["/build"].contents - dest: "./build" - } + // FIXME? + // FTL failed to load plan: outputs.directories."go binaries".contents: undefined field: contents: + // + // outputs: directories: "go binaries": { + // contents: actions.build.export.directories["/build"].contents + // dest: "./build" + // } actions: { _goModCache: "go mod cache": { dest: "/gomodcache" - contents: engine.#CacheDir & { + contents: dagger.#CacheDir & { id: "go mod cache" } } _baseImages: #Images - _source: "dagger source code": { + _sourceCode: "dagger source code": { contents: inputs.directories.source.contents dest: "/usr/src/dagger" } @@ -63,14 +66,14 @@ engine.#Plan & { mkdir -p /build git_revision=$(git rev-parse --short HEAD) CGO_ENABLED=0 \ - go build -v -o /build/dagger \ - -ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \ - ./cmd/dagger/ + go build -v -o /build/dagger \ + -ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \ + ./cmd/dagger/ """# workdir: mounts["dagger source code"].dest mounts: { - _source + _sourceCode _goModCache } @@ -83,9 +86,21 @@ engine.#Plan & { script: contents: "golangci-lint run -v --timeout 5m" workdir: mounts["dagger source code"].dest mounts: { - _source + _sourceCode _goModCache } } + + cueFmt: bash.#Run & { + input: _baseImages.cue + + script: contents: #""" + find . -name '*.cue' -not -path '*/cue.mod/*' -print | time xargs -n 1 -P 8 cue fmt -s + """# + workdir: mounts["dagger source code"].dest + mounts: { + _sourceCode + } + } } }