From e1b21884950db5d52940f61698f26f7602c8c741 Mon Sep 17 00:00:00 2001 From: Per Magnus Petersen Date: Fri, 18 Sep 2026 15:51:45 +0200 Subject: [PATCH] Add reviewed container release workflow --- .dockerignore | 13 ++++ .gitea/workflows/build.yml | 92 ++++++++++++++++++++++++++ .gitea/workflows/pr.yml | 37 +++++++++++ test/clj/pmagnus/elprice/core_test.clj | 9 ++- 4 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitea/workflows/pr.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..332abc5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.git +.gitea +.cpcache +.clj-kondo +.env +.token +.idea +log +node_modules +resources/public/css/output.css +target +*.iml +*.log diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..21bcc5b --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,92 @@ +name: build + +on: + push: + branches: [main] + tags: ['v*'] + +env: + REGISTRY: harbor.pmagnus.cloud + IMAGE: harbor.pmagnus.cloud/elprice/elprice + +jobs: + build: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:17-alpine + env: + POSTGRES_DB: elprice + POSTGRES_USER: elprice + POSTGRES_PASSWORD: elprice + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U elprice -d elprice" + --health-interval 2s + --health-timeout 5s + --health-retries 30 + env: + TARGET_HOST: localhost + TARGET_PORT: "5432" + TARGET_DB: elprice + TARGET_USER: elprice + TARGET_PASSWORD: elprice + steps: + - uses: actions/checkout@v4 + + - name: Test + run: clojure -M:test + + - name: Generate immutable tags + id: tags + shell: bash + run: | + set -euo pipefail + SHA=$(git rev-parse --short HEAD) + case "$GITHUB_REF" in + refs/tags/v*) VERSION="${GITHUB_REF_NAME#v}" ;; + *) VERSION="main-$(date -u +%Y%m%d%H%M%S)" ;; + esac + echo "primary=$IMAGE:$VERSION" >> "$GITHUB_OUTPUT" + echo "qualified=$IMAGE:$VERSION-$SHA" >> "$GITHUB_OUTPUT" + + # The runner host has the pinned route to Harbor. Keep BuildKit on the + # host network until job containers can resolve and reach it directly. + - uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + + - uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.HARBOR_ROBOT_USER }} + password: ${{ secrets.HARBOR_ROBOT_TOKEN }} + + - uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + push: true + tags: ${{ steps.tags.outputs.primary }} + cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache + cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max + + - name: Wait for Harbor policy, then add SHA tag + env: + PRIMARY: ${{ steps.tags.outputs.primary }} + QUALIFIED: ${{ steps.tags.outputs.qualified }} + run: | + for attempt in $(seq 1 60); do + if docker buildx imagetools inspect "$PRIMARY" >/dev/null 2>&1; then + docker buildx imagetools create --tag "$QUALIFIED" "$PRIMARY" + exit 0 + fi + echo "waiting for Harbor scan/pull policy ($attempt/60)" + sleep 10 + done + echo "Harbor did not approve $PRIMARY within 10 minutes" >&2 + exit 1 + + - name: Summary + run: echo "pushed ${{ steps.tags.outputs.primary }} and ${{ steps.tags.outputs.qualified }}" diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml new file mode 100644 index 0000000..8e5df9b --- /dev/null +++ b/.gitea/workflows/pr.yml @@ -0,0 +1,37 @@ +name: pull-request + +on: + pull_request: + branches: [main] + +jobs: + validate: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:17-alpine + env: + POSTGRES_DB: elprice + POSTGRES_USER: elprice + POSTGRES_PASSWORD: elprice + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U elprice -d elprice" + --health-interval 2s + --health-timeout 5s + --health-retries 30 + env: + TARGET_HOST: localhost + TARGET_PORT: "5432" + TARGET_DB: elprice + TARGET_USER: elprice + TARGET_PASSWORD: elprice + steps: + - uses: actions/checkout@v4 + + - name: Test + run: clojure -M:test + + - name: Build production image + run: docker build --platform linux/amd64 -t elprice:pr-check . diff --git a/test/clj/pmagnus/elprice/core_test.clj b/test/clj/pmagnus/elprice/core_test.clj index 3bb8c4d..01c09cb 100644 --- a/test/clj/pmagnus/elprice/core_test.clj +++ b/test/clj/pmagnus/elprice/core_test.clj @@ -1,8 +1,7 @@ (ns pmagnus.elprice.core-test (:require - [pmagnus.elprice.test-utils :as utils] - [clojure.test :refer :all])) - -(deftest example-test - (is (= 1 2))) + [clojure.test :refer [deftest is]] + [pmagnus.elprice.core :as core])) +(deftest system-state-is-managed-in-an-atom + (is (instance? clojure.lang.Atom core/system))) -- 2.54.0