CI: port GitLab pipeline to Forgejo Actions
All checks were successful
ci / frontend-test (push) Successful in 34s
ci / build-1 (push) Successful in 2m15s
ci / frontend-docker (push) Successful in 0s
ci / backend-test (push) Successful in 4m27s
ci / build (push) Successful in 9m16s
ci / backend-docker (push) Successful in 0s
ci / build-2 (push) Successful in 38s
ci / chart (push) Successful in 0s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonas Leder 2026-11-18 01:44:30 +01:00
commit d5a5532409
3 changed files with 117 additions and 126 deletions

114
.forgejo/workflows/ci.yml Normal file
View file

@ -0,0 +1,114 @@
name: ci
on:
push:
branches: ['**']
tags: ['**']
workflow_dispatch:
jobs:
backend-test:
runs-on: default
env:
# Modules, including jonasled.dev/jonasled/go-libs, come from our proxy. Direct is only the fallback.
GOPROXY: https://goproxy.jonasled.dev,direct
CGO_ENABLED: '0'
steps:
- uses: https://code.forgejo.org/actions/checkout@v7
- uses: https://code.forgejo.org/actions/setup-go@v7
with:
go-version: '1.27'
cache-dependency-path: backend/go.sum
- run: |
set -eu
cd backend
test -z "$(gofmt -l .)" || { gofmt -l .; echo "run gofmt"; exit 1; }
go vet ./...
# The generated API docs must match the handler annotations.
go install github.com/swaggo/swag/cmd/swag@v1.16.4
"$(go env GOPATH)/bin/swag" init -g cmd/server/main.go -o docs --parseInternal --outputTypes go,json,yaml
git diff --exit-code -- docs || { echo "docs/ is stale, run swag init"; exit 1; }
go test -count=1 -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | tail -1
- uses: https://code.forgejo.org/forgejo/upload-artifact@v4
if: always()
with:
name: coverage
path: backend/coverage.out
if-no-files-found: ignore
retention-days: 7
frontend-test:
runs-on: default
steps:
- uses: https://code.forgejo.org/actions/checkout@v7
- uses: https://code.forgejo.org/actions/setup-node@v7
with:
node-version: '26'
- run: |
set -eu
cd frontend
npm ci
npm run typecheck
npm test
npm run build
backend-docker:
needs: backend-test
uses: infra/ci-snippets/.forgejo/workflows/docker-build.yml@master
with:
image-suffix: /backend
context-dir: backend
secrets: inherit
frontend-docker:
needs: frontend-test
uses: infra/ci-snippets/.forgejo/workflows/docker-build.yml@master
with:
image-suffix: /frontend
context-dir: frontend
secrets: inherit
# Renders, lints and packages the chart with this commit's image tags, then pushes it to the OCI registry:
# helm install auth oci://<registry>/<owner>/auth-server/charts/auth-server --version <version>
chart:
needs: [backend-docker, frontend-docker]
if: github.ref_type == 'tag' || github.ref_name == github.event.repository.default_branch
uses: infra/ci-snippets/.forgejo/workflows/helm-build.yml@master
with:
chart-path: build/chart
push: true
lint-args: --strict
# Flux picks the highest version, so versions must only grow: patch is the run number plus the last
# GitLab pipeline (112), major.minor come from Chart.yaml.
version-from-run-number: true
version-offset: '112'
# helm package has no --set, so the image repository goes into a copy of the chart. The tag defaults
# to appVersion, which is the commit SHA the images were built with.
pre-package: |
set -eu
IMAGE="$REGISTRY/$(echo "$GITHUB_REPOSITORY" | tr 'A-Z' 'a-z')"
rm -rf build && mkdir -p build
cp -r deploy/helm/auth-server build/chart
sed -i "s|registry.example.com/auth-server/|$IMAGE/|" build/chart/values.yaml
extra-checks: |
set -eu
CHART_DIR=deploy/helm/auth-server
helm template ci "$CHART_DIR" --set secrets.values.ADMIN_PASSWORD=ci > /dev/null
helm template ci "$CHART_DIR" --set secrets.values.ADMIN_PASSWORD=ci --set redis.internal.enabled=true --set secrets.values.REDIS_PASSWORD=ci --set kube.enabled=false > /dev/null
helm template ci "$CHART_DIR" --set config.dbDriver=postgres --set config.db.host=db --set secrets.values.DB_PASSWORD.secretName=ci --set secrets.values.DB_PASSWORD.key=password --set persistence.enabled=false --set backend.replicaCount=2 --set signingKey.existingSecret=ci --set ingress.enabled=true --set host=auth.example.com > /dev/null
# Server databases are migrated by one job, never by the pods.
PG_ARGS="--set config.dbDriver=postgres --set config.db.host=db --set secrets.values.DB_PASSWORD=ci --set persistence.enabled=false"
helm template ci "$CHART_DIR" $PG_ARGS | grep -q 'kind: Job'
helm template ci "$CHART_DIR" $PG_ARGS | grep -q 'MIGRATE_ON_START: "false"'
helm template ci "$CHART_DIR" --set config.dbDriver=mariadb --set config.db.host=db --set secrets.values.DB_PASSWORD=ci --set redis.internal.enabled=true --set secrets.values.REDIS_PASSWORD=ci > /dev/null
# The chart must point at the images this run built: <registry image>/<name>:<commit sha>.
post-package: |
set -eu
IMAGE="$REGISTRY/$(echo "$GITHUB_REPOSITORY" | tr 'A-Z' 'a-z')"
IMAGES=$(helm template ci "$CHART" --set secrets.values.ADMIN_PASSWORD=ci | sed -n 's/^ *image: "\(.*\)"$/\1/p' | grep -E '/(backend|frontend):' || true)
echo "$IMAGES"
for name in backend frontend; do
echo "$IMAGES" | grep -qx "$IMAGE/$name:$GITHUB_SHA" || { echo "chart does not use $IMAGE/$name:$GITHUB_SHA"; exit 1; }
done
secrets: inherit

View file

@ -1,123 +0,0 @@
# Test, build the two images, package the chart. Same layout as the sfp-database pipeline.
variables:
GIT_SUBMODULE_STRATEGY: none
CHART_DIR: deploy/helm/auth-server
stages:
- test
- build
- bundle
BackendTest:
image: golang:1.27.4-alpine
stage: test
before_script:
- apk add --no-cache git
- export PATH="$PATH:$(go env GOPATH)/bin"
needs: []
variables:
CGO_ENABLED: "0"
# Modules, including jonasled.dev/jonasled/go-libs, come from our proxy. Direct is only the fallback.
GOPROXY: https://goproxy.jonasled.dev,direct
script:
- cd backend
- test -z "$(gofmt -l .)" || { gofmt -l .; echo "run gofmt"; exit 1; }
- go vet ./...
# The generated API docs must match the handler annotations.
- go install github.com/swaggo/swag/cmd/swag@v1.16.4
- swag init -g cmd/server/main.go -o docs --parseInternal --outputTypes go,json,yaml
- git diff --exit-code -- docs || { echo "docs/ is stale, run swag init"; exit 1; }
- go test -count=1 -coverprofile=coverage.out ./...
- go tool cover -func=coverage.out | tail -1
artifacts:
when: always
paths:
- backend/coverage.out
expire_in: 1 week
FrontendTest:
image: node:26-alpine
stage: test
needs: []
script:
- cd frontend
- npm ci
- npm run typecheck
- npm test
- npm run build
BackendDocker:
image: jonasled.dev/infra/docker-build:master@sha256:d6f535fcb2817edec221eac33331369863f3409322d5f2d516356e7e7554326b
stage: build
needs: [BackendTest]
script:
- export IMAGE_NAME=$CI_REGISTRY_IMAGE/backend
- cd backend
- build-image
- mv image-hash.txt ../image-hash-backend.txt
- mv image-scan-report.bom.json ../backend.bom.json
artifacts:
paths:
- image-hash-backend.txt
- backend.bom.json
FrontendDocker:
image: jonasled.dev/infra/docker-build:master@sha256:d6f535fcb2817edec221eac33331369863f3409322d5f2d516356e7e7554326b
stage: build
needs: [FrontendTest]
script:
- export IMAGE_NAME=$CI_REGISTRY_IMAGE/frontend
- cd frontend
- build-image
- mv image-hash.txt ../image-hash-frontend.txt
- mv image-scan-report.bom.json ../frontend.bom.json
artifacts:
paths:
- image-hash-frontend.txt
- frontend.bom.json
HelmChart:
# Renders, lints and packages the chart with this commit's image tags, then pushes it to the OCI registry:
# helm install auth oci://$CI_REGISTRY/$CI_PROJECT_PATH/charts/auth-server --version <version>
image:
name: alpine/helm:4.3.2
entrypoint: [""]
stage: bundle
needs: [BackendDocker, FrontendDocker]
variables:
CHART_REPO: oci://$CI_REGISTRY/$CI_PROJECT_PATH/charts
script:
- helm lint "$CHART_DIR" --strict
- helm template ci "$CHART_DIR" --set secrets.values.ADMIN_PASSWORD=ci > /dev/null
- helm template ci "$CHART_DIR" --set secrets.values.ADMIN_PASSWORD=ci --set redis.internal.enabled=true --set secrets.values.REDIS_PASSWORD=ci --set kube.enabled=false > /dev/null
- helm template ci "$CHART_DIR" --set config.dbDriver=postgres --set config.db.host=db --set secrets.values.DB_PASSWORD.secretName=ci --set secrets.values.DB_PASSWORD.key=password --set persistence.enabled=false --set backend.replicaCount=2 --set signingKey.existingSecret=ci --set ingress.enabled=true --set host=auth.example.com > /dev/null
# Server databases are migrated by one job, never by the pods.
- |
PG_ARGS="--set config.dbDriver=postgres --set config.db.host=db --set secrets.values.DB_PASSWORD=ci --set persistence.enabled=false"
helm template ci "$CHART_DIR" $PG_ARGS | grep -q 'kind: Job'
helm template ci "$CHART_DIR" $PG_ARGS | grep -q 'MIGRATE_ON_START: "false"'
- helm template ci "$CHART_DIR" --set config.dbDriver=mariadb --set config.db.host=db --set secrets.values.DB_PASSWORD=ci --set redis.internal.enabled=true --set secrets.values.REDIS_PASSWORD=ci > /dev/null
- |
# Flux picks the highest version, so versions must only grow. The patch number is the pipeline IID.
# helm package has no --set, so the image repository goes into a copy of the chart. The tag defaults to appVersion,
# which is the commit SHA the images were built with.
BASE_VERSION=$(sed -n 's/^version: *//p' "$CHART_DIR/Chart.yaml" | cut -d. -f1,2)
CHART_VERSION="${BASE_VERSION}.${CI_PIPELINE_IID}"
rm -rf build && mkdir -p build
cp -r "$CHART_DIR" build/chart
sed -i "s|registry.example.com/auth-server/|$CI_REGISTRY_IMAGE/|" build/chart/values.yaml
helm package build/chart --version "$CHART_VERSION" --app-version "$CI_COMMIT_SHA" --destination dist
# The chart must point at the images this pipeline built: <registry image>/<name>:<commit sha>.
IMAGES=$(helm template ci dist/auth-server-*.tgz --set secrets.values.ADMIN_PASSWORD=ci | sed -n 's/^ *image: "\(.*\)"$/\1/p' | grep -E '/(backend|frontend):' || true)
echo "$IMAGES"
for name in backend frontend; do
echo "$IMAGES" | grep -qx "$CI_REGISTRY_IMAGE/$name:$CI_COMMIT_SHA" || { echo "chart does not use $CI_REGISTRY_IMAGE/$name:$CI_COMMIT_SHA"; exit 1; }
done
- helm registry login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
- helm push dist/auth-server-*.tgz "$CHART_REPO"
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
artifacts:
paths:
- dist/

View file

@ -40,7 +40,7 @@ A small OIDC provider with Traefik forward auth and a user account UI. Go backen
| Multiple backend replicas (PostgreSQL or MariaDB) | done, tested with two servers on one database; SQLite is single replica only |
| Helm: DB from `config.db.*` with the password in a secret, each secret value inline or external, CI sets image repo and tag | done, checked with `helm lint` and `helm template` only, not deployed |
| Database migrations with gormigrate in a dedicated Helm hook Job; pods only wait and check | done, tested with the real binary on SQLite (also adopting a database from before migrations), not on PostgreSQL or MariaDB, the Job not run on a cluster |
| Tests, GitLab pipeline, Helm chart, two images | done. The chart uses the commit SHA as image tag (empty `image.tag` means appVersion) and CI checks it. CRD schemas are checked by a test, since `helm lint` misses bad keys; CRDs were never applied to a real API server by me |
| Tests, Forgejo pipeline, Helm chart, two images | done. The chart uses the commit SHA as image tag (empty `image.tag` means appVersion) and CI checks it. CRD schemas are checked by a test, since `helm lint` misses bad keys; CRDs were never applied to a real API server by me |
| Recovery codes for 2FA (10 one-time codes, shown once, regenerate any time) | done |
| Admin reset of a user's 2FA | done |
| Password reset by email (30 minute single-use link, needs SMTP) | done, tested against a fake SMTP server and a fake mailer, not a real mail server |
@ -199,5 +199,5 @@ the signing key secret; the chart refuses other combinations.
## Pipeline
`.gitlab-ci.yml`: backend (modules from `https://goproxy.jonasled.dev`) gofmt, vet, swagger docs check and tests; frontend typecheck, tests and build; both images; Helm lint, render and
push of the chart to the project's OCI registry.
`.forgejo/workflows/ci.yml`: backend (modules from `https://goproxy.jonasled.dev`) gofmt, vet, swagger docs check and tests; frontend typecheck, tests and build; both images; Helm lint, render and
push of the chart to the project's OCI registry (images and chart through the reusable workflows in `infra/ci-snippets`).