diff --git a/.tekton/anubis-pipelinerun.yaml b/.tekton/anubis-pipelinerun.yaml new file mode 100644 index 00000000..9ff53b4b --- /dev/null +++ b/.tekton/anubis-pipelinerun.yaml @@ -0,0 +1,35 @@ +apiVersion: tekton.dev/v1 +kind: PipelineRun +metadata: + generateName: anubis-m- + namespace: ci + +spec: + params: + - name: commit + value: "Xe/tekton" + - name: branch + value: main + pipelineRef: + name: anubis-build-test + taskRunTemplate: + serviceAccountName: xe-site-ci + timeouts: + pipeline: 1h0m0s + workspaces: + - name: repo + volumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 4Gi + - name: go-mod-cache + persistentVolumeClaim: + claimName: go-mod-cache + - name: dockerconfig-atcr + secret: + secretName: atcr + - name: dockerconfig-ghcr + secret: + secretName: ghcr diff --git a/.tekton/anubis-test.yaml b/.tekton/anubis-test.yaml new file mode 100644 index 00000000..1844bc99 --- /dev/null +++ b/.tekton/anubis-test.yaml @@ -0,0 +1,110 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: anubis-build-test + namespace: ci + +spec: + description: | + The CI/CD pipeline for Anubis + params: + - name: repo-url + type: string + description: "Git repo to clone" + default: "https://github.com/TecharoHQ/anubis" + - name: "branch" + type: string + description: "Git branch to operate against" + - name: "commit" + type: string + description: "Git revision to check out" + - name: "actor" + type: string + description: "Tangled actor" + default: "did:web:anubis.techaro.lol" + - name: docker-image-base + type: string + description: string prefix for production docker images + default: "registry.int.xeserv.us/techarohq/anubis" + - name: docker-cache + type: string + description: docker repo to store cache files + default: "registry.int.xeserv.us/techarohq/anubis/cache" + workspaces: + - name: repo + description: | + Cloned repo files. + - name: go-mod-cache + description: | + Go module cache + - name: dockerconfig-atcr + description: | + Docker config for pushing images to atcr + - name: dockerconfig-ghcr + description: | + Docker config for pushing images to ghcr + tasks: + - name: fix-permissions + taskRef: + name: fix-permissions + workspaces: + - name: dir + workspace: repo + - name: clone-repo + runAfter: ["fix-permissions"] + taskRef: + name: git-clone-naive + workspaces: + - name: output + workspace: repo + params: + - name: url + value: $(params.repo-url) + - name: revision + value: $(params.commit) + - name: docker-build-ci + runAfter: ["clone-repo"] + workspaces: + - name: source + workspace: repo + taskRef: + name: kaniko + params: + - name: IMAGE + value: registry.int.xeserv.us/xeiaso.net/site/ci:$(params.commit) + - name: DOCKERFILE + value: ./test/ssh-ci/Dockerfile + - name: EXTRA_ARGS + value: + [ + "--cache", + "--cache-copy-layers", + "--cache-run-layers", + "--cache-repo=$(params.docker-cache)", + "--label=org.tangled.actor=$(params.actor)", + "--snapshot-mode=redo", + "--use-new-run", + ] + - name: go-test + runAfter: ["docker-build-ci"] + taskSpec: + workspaces: + - name: repo + mountPath: /src + - name: go-mod-cache + mountPath: /go + steps: + - name: test + image: $(tasks.docker-build-ci.results.IMAGE_URL)@$(tasks.docker-build-ci.results.IMAGE_DIGEST) + workingDir: $(workspaces.source.path)/repo + script: | + npm ci + npm run test + workspaces: + - name: repo + workspace: repo + params: + - name: url + value: $(params.repo-url) + - name: revision + value: $(params.commit) diff --git a/.tekton/kustomization.yaml b/.tekton/kustomization.yaml new file mode 100644 index 00000000..68c2a21d --- /dev/null +++ b/.tekton/kustomization.yaml @@ -0,0 +1,3 @@ +namespace: ci +resources: + - anubis-test.yaml diff --git a/package.json b/package.json index 1d8ed154..4e47a5ac 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "package": "go tool yeet", "lint": "make lint", "prepare": "husky && go mod download", - "format": "prettier -w . 2>&1 >/dev/null && go run goimports -w ." + "format": "prettier -w . 2>&1 >/dev/null && go run goimports -w .", + "deploy:ci": "kubectl apply -k .tekton -n ci --context admin@alrest", + "deploy:ci:invoke": "npm run deploy:ci && kubectl create -f .tekton/anubis-pipelinerun.yaml -n ci --context admin@alrest" }, "author": "", "license": "ISC", diff --git a/test/ssh-ci/Dockerfile b/test/ssh-ci/Dockerfile index 652749d6..7d151958 100644 --- a/test/ssh-ci/Dockerfile +++ b/test/ssh-ci/Dockerfile @@ -1,5 +1,15 @@ ARG ALPINE_VERSION=3.22 +ARG GO_VERSION=1.26.2 + +# Go toolchain bootstrapper +FROM golang:${GO_VERSION} AS go + +RUN CGO_ENABLED=0 go install golang.org/dl/go${GO_VERSION}@latest \ + && mkdir -p /app/bin \ + && mv /go/bin/go${GO_VERSION} /app/bin/go FROM alpine:${ALPINE_VERSION} -RUN apk add -U go nodejs git build-base git npm bash zstd brotli gzip -LABEL org.opencontainers.image.source="https://github.com/TecharoHQ/anubis" \ No newline at end of file +COPY --from=go /app/bin/go /usr/local/bin/go + +RUN apk add -U nodejs git build-base git npm bash zstd brotli gzip \ + && go download \ No newline at end of file