CI: port GitLab pipeline to Forgejo Actions
Some checks failed
ci / frontend-test (push) Successful in 47s
ci / build-1 (push) Failing after 1m42s
ci / frontend-docker (push) Failing after 0s
ci / backend-test (push) Successful in 2m53s
ci / backend-docker (push) Has been cancelled
ci / chart (push) Has been cancelled
ci / build-2 (push) Has been cancelled
ci / build (push) Has been cancelled
Some checks failed
ci / frontend-test (push) Successful in 47s
ci / build-1 (push) Failing after 1m42s
ci / frontend-docker (push) Failing after 0s
ci / backend-test (push) Successful in 2m53s
ci / backend-docker (push) Has been cancelled
ci / chart (push) Has been cancelled
ci / build-2 (push) Has been cancelled
ci / build (push) Has been cancelled
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8a40d90069
commit
73a238b42b
3 changed files with 84 additions and 106 deletions
83
.forgejo/workflows/ci.yml
Normal file
83
.forgejo/workflows/ci.yml
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['**']
|
||||
tags: ['**']
|
||||
|
||||
jobs:
|
||||
backend-test:
|
||||
runs-on: default
|
||||
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: cd backend && go test ./...
|
||||
env:
|
||||
CGO_ENABLED: '0'
|
||||
|
||||
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.13'
|
||||
- run: |
|
||||
set -eu
|
||||
npm install -g pnpm@12.21.0
|
||||
cd frontend
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm test
|
||||
pnpm build
|
||||
|
||||
backend-docker:
|
||||
uses: infra/ci-snippets/.forgejo/workflows/docker-build.yml@master
|
||||
with:
|
||||
image-suffix: /backend
|
||||
context-dir: backend
|
||||
secrets: inherit
|
||||
|
||||
frontend-docker:
|
||||
uses: infra/ci-snippets/.forgejo/workflows/docker-build.yml@master
|
||||
with:
|
||||
image-suffix: /frontend
|
||||
context-dir: frontend
|
||||
# The image build context has no .git, so the commit goes into a file that vite.config.ts reads.
|
||||
pre-build: echo "$GITHUB_SHA" > GIT_SHA
|
||||
secrets: inherit
|
||||
|
||||
# Renders the chart, packages it and pushes it to the OCI registry:
|
||||
# helm install timetracker oci://<registry>/<owner>/timetracker-next/charts/timetracker --version <version>
|
||||
# Runs only if both image builds succeeded. The chart's image repositories and tags point at this repo's registry path and commit.
|
||||
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: deploy/helm/timetracker
|
||||
push: true
|
||||
lint-args: --strict
|
||||
app-version: ${{ github.sha }}
|
||||
# Flux picks the highest version, so versions must only grow: the patch number is the run number,
|
||||
# major.minor come from Chart.yaml.
|
||||
version-patch: ${{ github.run_number }}
|
||||
pre-package: |
|
||||
set -eu
|
||||
sed -i "s|__GIT_COMMIT_SHA__|$GITHUB_SHA|g; s|__CI_REGISTRY_IMAGE__|$REGISTRY/$(echo "$GITHUB_REPOSITORY" | tr 'A-Z' 'a-z')|g" deploy/helm/timetracker/values.yaml
|
||||
if grep -Eq "__GIT_COMMIT_SHA__|__CI_REGISTRY_IMAGE__" deploy/helm/timetracker/values.yaml; then echo "placeholder left in values.yaml"; exit 1; fi
|
||||
extra-checks: |
|
||||
set -eu
|
||||
CHART_DIR=deploy/helm/timetracker
|
||||
# Render with the common configurations so template failures show up in CI.
|
||||
helm template ci "$CHART_DIR" --set secrets.inline.jwtSecret=ci > /dev/null
|
||||
helm template ci "$CHART_DIR" --set config.database.driver=postgres --set config.database.host=db --set config.database.user=timetracker --set secrets.inline.dbPassword=ci --set secrets.inline.jwtSecret=ci --set replicaCount=2 --set ingress.enabled=true --set 'ingress.hosts={timetracker.example.com}' > /dev/null
|
||||
# The frontend pod runs with a read-only root file system. nginx writes only to these paths, so each
|
||||
# needs an emptyDir mount; without /var/lib/nginx/tmp it fails at start with "mkdir() ... client_body".
|
||||
RENDERED=$(helm template ci "$CHART_DIR" --set secrets.inline.jwtSecret=ci)
|
||||
for path in /var/lib/nginx/tmp /run /tmp; do
|
||||
echo "$RENDERED" | grep -q "mountPath: $path\$" || { echo "frontend pod has no writable $path"; exit 1; }
|
||||
done
|
||||
secrets: inherit
|
||||
105
.gitlab-ci.yml
105
.gitlab-ci.yml
|
|
@ -1,105 +0,0 @@
|
|||
stages:
|
||||
- test
|
||||
- build
|
||||
- bundle
|
||||
- deploy
|
||||
|
||||
BackendUnitTests:
|
||||
image: golang:1.27.4-alpine
|
||||
stage: test
|
||||
needs: []
|
||||
variables:
|
||||
CGO_ENABLED: "0"
|
||||
script:
|
||||
- cd backend
|
||||
- go test ./...
|
||||
|
||||
FrontendUnitTests:
|
||||
image: node:26.13-alpine@sha256:6bd9ab43c0ec0190ca7b2d193906cb8b7edf6e7f4afa43ddeccd6452710bffb5
|
||||
stage: test
|
||||
needs: []
|
||||
before_script:
|
||||
- npx get-pnpm
|
||||
- export PNPM_HOME='/root/.local/share/pnpm'
|
||||
- export PATH="$PNPM_HOME/bin:$PATH"
|
||||
script:
|
||||
- cd frontend
|
||||
- pnpm install --frozen-lockfile
|
||||
- pnpm test
|
||||
- pnpm build
|
||||
|
||||
BackendDocker:
|
||||
image: jonasled.dev/infra/docker-build:master@sha256:d6f535fcb2817edec221eac33331369863f3409322d5f2d516356e7e7554326b
|
||||
stage: build
|
||||
needs: []
|
||||
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: []
|
||||
script:
|
||||
- export IMAGE_NAME=$CI_REGISTRY_IMAGE/frontend
|
||||
- cd frontend
|
||||
# The image build context has no .git, so the commit goes into a file that vite.config.ts reads.
|
||||
- echo "$CI_COMMIT_SHA" > GIT_SHA
|
||||
- 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 the chart, packages it and pushes it to the project's OCI registry:
|
||||
# helm install timetracker oci://$CI_REGISTRY/$CI_PROJECT_PATH/charts/timetracker --version <version>
|
||||
# The job needs both image builds, so it runs only if they succeeded. The chart's image
|
||||
# repositories and tags are set to this project's registry path and this commit's SHA.
|
||||
image:
|
||||
name: alpine/helm:4.3.2
|
||||
entrypoint: [""]
|
||||
stage: bundle
|
||||
needs:
|
||||
- BackendDocker
|
||||
- FrontendDocker
|
||||
variables:
|
||||
CHART_DIR: deploy/helm/timetracker
|
||||
CHART_REPO: oci://$CI_REGISTRY/$CI_PROJECT_PATH/charts
|
||||
script:
|
||||
- sed -i "s|__GIT_COMMIT_SHA__|$CI_COMMIT_SHA|g; s|__CI_REGISTRY_IMAGE__|$CI_REGISTRY_IMAGE|g" "$CHART_DIR/values.yaml"
|
||||
- if grep -Eq "__GIT_COMMIT_SHA__|__CI_REGISTRY_IMAGE__" "$CHART_DIR/values.yaml"; then echo "placeholder left in values.yaml"; exit 1; fi
|
||||
- helm lint "$CHART_DIR" --strict
|
||||
# Render with the common configurations so template failures show up in CI.
|
||||
- helm template ci "$CHART_DIR" --set secrets.inline.jwtSecret=ci > /dev/null
|
||||
- helm template ci "$CHART_DIR" --set config.database.driver=postgres --set config.database.host=db --set config.database.user=timetracker --set secrets.inline.dbPassword=ci --set secrets.inline.jwtSecret=ci --set replicaCount=2 --set ingress.enabled=true --set 'ingress.hosts={timetracker.example.com}' > /dev/null
|
||||
- |
|
||||
# The frontend pod runs with a read-only root file system. nginx writes only to these paths, so each
|
||||
# needs an emptyDir mount; without /var/lib/nginx/tmp it fails at start with "mkdir() ... client_body".
|
||||
RENDERED=$(helm template ci "$CHART_DIR" --set secrets.inline.jwtSecret=ci)
|
||||
for path in /var/lib/nginx/tmp /run /tmp; do
|
||||
echo "$RENDERED" | grep -q "mountPath: $path\$" || { echo "frontend pod has no writable $path"; exit 1; }
|
||||
done
|
||||
- |
|
||||
# Flux picks the highest version, so versions must only grow. The patch number is the pipeline IID,
|
||||
# which increases with every pipeline of the project. The major.minor part comes from Chart.yaml.
|
||||
BASE_VERSION=$(sed -n 's/^version: *//p' "$CHART_DIR/Chart.yaml" | cut -d. -f1,2)
|
||||
CHART_VERSION="${BASE_VERSION}.${CI_PIPELINE_IID}"
|
||||
helm package "$CHART_DIR" --version "$CHART_VERSION" --app-version "$CI_COMMIT_SHA" --destination dist
|
||||
- helm registry login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
|
||||
- helm push dist/timetracker-*.tgz "$CHART_REPO"
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
artifacts:
|
||||
paths:
|
||||
- dist/
|
||||
|
|
@ -88,7 +88,7 @@ helm install timetracker deploy/helm/timetracker \
|
|||
|
||||
## CI
|
||||
|
||||
`.gitlab-ci.yml` führt Go- und Frontend-Tests aus, baut beide Images (`build-image`), rendert und prüft das Chart (`helm lint --strict`, `helm template`) und veröffentlicht es als OCI-Chart. Der Chart-Tag ist die Pipeline-IID als Patch-Version; Image-Tags und Registry-Pfad werden in der Pipeline in `values.yaml` eingesetzt.
|
||||
`.forgejo/workflows/ci.yml` führt Go- und Frontend-Tests aus, baut beide Images über die wiederverwendbaren Workflows aus `infra/ci-snippets`, rendert und prüft das Chart (`helm lint --strict`, `helm template`) und veröffentlicht es als OCI-Chart. Der Chart-Tag ist die Workflow-Run-Nummer als Patch-Version; Image-Tags und Registry-Pfad werden im Workflow in `values.yaml` eingesetzt.
|
||||
|
||||
## Lokale Entwicklung
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue