diff --git a/ci/.gitignore b/ci/.gitignore new file mode 100644 index 00000000..a007feab --- /dev/null +++ b/ci/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/ci/base.cue b/ci/base.cue new file mode 100644 index 00000000..4e359b9e --- /dev/null +++ b/ci/base.cue @@ -0,0 +1,34 @@ +package main + +import ( + "universe.dagger.io/docker" +) + +let GoVersion = "1.17" + +// Base container images used for the CI +images: { + + // base image to build go binaries + goBuilder: docker.#Build & { + _packages: ["bash", "git"] + + 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 + } + } + } + }, + ] + } +} diff --git a/ci/main.cue b/ci/main.cue new file mode 100644 index 00000000..b06fd4c7 --- /dev/null +++ b/ci/main.cue @@ -0,0 +1,64 @@ +package main + +import ( + // "dagger.io/dagger" + "dagger.io/dagger/engine" + + "universe.dagger.io/bash" +) + +engine.#Plan & { + inputs: { + params: { + // FIXME: implement condition actions using params + } + + directories: { + // dagger repository + source: path: "../" + } + } + + outputs: directories: "go binaries": { + contents: actions.build.export.directories["/build"].contents + dest: "./build" + } + + actions: { + goModCache: engine.#CacheDir & { + id: "go mod cache" + } + + build: bash.#Run & { + input: images.goBuilder.output + + script: contents: #""" + export GOMODCACHE=/gomodcache + mkdir -p /build + git_revision=$(git rev-parse --short HEAD) + GO_ENABLED=0 \ + go build -v -o /build/dagger \ + -ldflags '-s -w -X go.dagger.io/dagger/version.Revision='${git_revision} \ + ./cmd/dagger/ + """# + + export: directories: "/build": _ + workdir: "/usr/src/dagger" + env: GOMODCACHE: "/gomodcache" + + mounts: { + "dagger source code": { + contents: inputs.directories.source.contents + dest: "/usr/src/dagger" + } + + "go mod cache": { + dest: "/gomodcache" + contents: goModCache + } + } + + workdir: mounts["dagger source code"].dest + } + } +}