Repository navigation
Greek i18n #426
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker publish | |
| # Builds the multi-arch (amd64 + arm64) image from the repo Dockerfile. | |
| # * PR → build only (catches cross-arch build breaks early, e.g. an | |
| # amd64-only step slipping back in). Nothing is pushed. | |
| # * push to dev → push `:dev` + `:sha-<short>`. Pre-release, for deploying a | |
| # branch to a real instance to test it before it reaches main. | |
| # Deliberately does NOT move `:edge` or `:latest`. | |
| # * push to main → push `:edge` + `:sha-<short>` (bleeding edge). | |
| # * push a `vX.Y.Z` tag → push `:X.Y.Z`, `:X.Y`, and `:latest`, then cut a GitHub | |
| # Release with standalone binaries and checksums. | |
| # So `:latest` always tracks the newest *release*, | |
| # never raw main. | |
| # | |
| # Pin a deployment to `:sha-<short>`, never to `:dev` or `:edge` — those move under | |
| # you, and then nothing records which commit an instance is actually running. | |
| on: | |
| push: | |
| branches: [main, dev] | |
| tags: ['v*.*.*'] | |
| pull_request: | |
| concurrency: | |
| group: docker-publish-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| REGISTRY: ghcr.io | |
| # Hardcoded lowercase — GHCR tags reject the repo's actual "Calnode/calnode" | |
| # casing (${{ github.repository }} would break the push). | |
| IMAGE_NAME: calnode/calnode | |
| BUILD_PLATFORMS: linux/amd64,linux/arm64 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| # Digest of the multi-arch index this job pushed. The arm64 smoke test | |
| # pulls exactly this image, so it cannot test a stale tag and cannot race | |
| # the publish: it runs after this job, against the bytes just published. | |
| digest: ${{ steps.build.outputs.digest }} | |
| # Without this the job inherits GitHub's 360-minute default, so a hung | |
| # multi-arch build sits for six hours before being cancelled (observed on | |
| # one branch, cancelled at exactly 6h0m44s). Normal duration is 11-13 | |
| # minutes, so an hour is a generous ceiling that fails visibly instead. | |
| timeout-minutes: 60 | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: docker/setup-qemu-action@v4 | |
| - uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Computes the tag set from the git ref: | |
| # main → edge, sha-<short> | |
| # dev → dev, sha-<short> | |
| # vX.Y.Z tag → X.Y.Z, X.Y, and latest (latest=auto only fires on a semver tag) | |
| # | |
| # sha- is emitted for every branch build, not just the default one, so a | |
| # pre-release deploy can be pinned to an immutable tag that names its commit. | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=edge,branch=main | |
| type=ref,event=branch,enable=${{ github.ref == 'refs/heads/dev' }} | |
| type=sha | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| - name: Build (push on branch pushes and on tags) | |
| id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: ${{ env.BUILD_PLATFORMS }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ steps.meta.outputs.version }} | |
| COMMIT=${{ github.sha }} | |
| - name: Export standalone binaries | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| target: standalone | |
| platforms: ${{ env.BUILD_PLATFORMS }} | |
| outputs: type=local,dest=dist/binaries,platform-split=true | |
| build-args: | | |
| VERSION=${{ steps.meta.outputs.version }} | |
| COMMIT=${{ github.sha }} | |
| - name: Package standalone binaries | |
| env: | |
| VERSION: ${{ steps.meta.outputs.version }} | |
| run: | | |
| mkdir -p dist/release | |
| for platform_dir in dist/binaries/linux_*; do | |
| platform="${platform_dir##*/}" | |
| tar -czf "dist/release/calnode_${VERSION#v}_${platform}.tar.gz" \ | |
| -C "$platform_dir" calnode LICENSE | |
| done | |
| cd dist/release | |
| sha256sum ./*.tar.gz > checksums.txt | |
| - name: Upload standalone binaries | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: standalone-binaries | |
| path: dist/release/ | |
| if-no-files-found: error | |
| arm64-smoke: | |
| # Proves the arm64 half of the multi-arch image actually runs on an ARM CPU, | |
| # not under QEMU. The build job cross-builds both arches under emulation, | |
| # which cannot demonstrate native execution. | |
| # | |
| # Two paths, because the image is not always in the registry: | |
| # push (main/dev/tag) -> pull the exact digest the build job just pushed | |
| # pull request -> build the image natively here, so a PR is checked | |
| # too and this job is proven BEFORE it reaches main | |
| # The pull-request path matters as much as the assertion itself: a gate that | |
| # cannot run until it is merged has not been tested at all. | |
| # | |
| # Free and unmetered: standard arm64 runners cost nothing on public repos. | |
| needs: build | |
| runs-on: ubuntu-24.04-arm | |
| timeout-minutes: 30 | |
| permissions: | |
| contents: read | |
| packages: read | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Prove this runner is genuinely arm64 | |
| run: | | |
| set -euo pipefail | |
| echo "uname -m: $(uname -m)" | |
| echo "nproc: $(nproc)" | |
| test "$(uname -m)" = "aarch64" | |
| - name: Pull the image this build just published | |
| if: github.event_name != 'pull_request' | |
| env: | |
| IMAGE_REF: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.build.outputs.digest }}" | |
| run: | | |
| set -euo pipefail | |
| if [ -z "${{ needs.build.outputs.digest }}" ]; then | |
| echo "::error::build produced no digest, so there is nothing to verify" | |
| exit 1 | |
| fi | |
| docker pull "$IMAGE_REF" | |
| - name: Build for arm64 natively (pull requests only) | |
| if: github.event_name == 'pull_request' | |
| run: docker build --platform linux/arm64 -t calnode-pr:arm64 . | |
| - name: Resolve the image under test | |
| id: img | |
| run: | | |
| set -euo pipefail | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "ref=calnode-pr:arm64" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.build.outputs.digest }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Confirm the image is arm64 | |
| env: | |
| IMAGE_REF: ${{ steps.img.outputs.ref }} | |
| run: | | |
| docker image inspect "$IMAGE_REF" --format 'image arch: {{.Architecture}} / {{.Os}}' | |
| - name: Run it natively, as a deployment would | |
| env: | |
| IMAGE_REF: ${{ steps.img.outputs.ref }} | |
| run: | | |
| set -euo pipefail | |
| docker run -d --name calnode \ | |
| -p 127.0.0.1:3000:3000 \ | |
| -e PORT=3000 \ | |
| -e DATABASE_URL=sqlite:///data/calnode.db \ | |
| -e BASE_URL=http://127.0.0.1:3000 \ | |
| -v calnode-data:/data \ | |
| "$IMAGE_REF" | |
| echo "container arch: $(docker exec calnode uname -m)" | |
| - name: Wait for HTTP and assert the app serves | |
| run: | | |
| set -euo pipefail | |
| for i in $(seq 1 60); do | |
| code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/ || true) | |
| if [ "$code" = "200" ] || [ "$code" = "302" ] || [ "$code" = "307" ]; then | |
| echo "app answered on native arm64 (attempt $i, HTTP $code)" | |
| exit 0 | |
| fi | |
| sleep 2 | |
| done | |
| echo "::error::app did not answer within 120s on arm64" | |
| exit 1 | |
| - name: Assert the admin UI loads | |
| run: | | |
| set -euo pipefail | |
| code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/admin/) | |
| echo "/admin/ -> HTTP $code" | |
| test "$code" = "200" | |
| - name: Assert the encryption key was persisted, not ephemeral | |
| # Regression guard for the quick-start trap: a first start with no | |
| # CALNODE_ENCRYPTION_KEY must write a key beside the database, so stored | |
| # credentials survive a restart instead of becoming unreadable. | |
| run: | | |
| set -euo pipefail | |
| docker run --rm -v calnode-data:/data alpine:3 sh -c 'test -s /data/calnode.key' \ | |
| && echo "key persisted beside the database" | |
| - name: Assert a restart still finds the key | |
| run: | | |
| set -euo pipefail | |
| docker restart calnode | |
| for i in $(seq 1 60); do | |
| code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/ || true) | |
| if [ "$code" = "200" ] || [ "$code" = "302" ] || [ "$code" = "307" ]; then | |
| echo "still serving after restart (HTTP $code)" | |
| docker logs calnode 2>&1 | grep -q "DEK unwrapped from keystore" \ | |
| && echo "restart reused the persisted key" \ | |
| || { echo "::error::restart did not reuse the persisted key"; exit 1; } | |
| exit 0 | |
| fi | |
| sleep 2 | |
| done | |
| echo "::error::app did not come back after restart" | |
| exit 1 | |
| - name: Show app logs | |
| if: always() | |
| run: docker logs calnode 2>&1 | tail -30 | |
| release: | |
| # Only on a version tag, and only once the image built + pushed. | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: standalone-binaries | |
| path: dist/release | |
| # Pull the matching version's section out of CHANGELOG.md for the release body, | |
| # so the GitHub Release and the CHANGELOG stay identical. Index-based (not a `\[` | |
| # regex) so it's portable across awk flavours. Falls back to GitHub's | |
| # auto-generated notes if there's no CHANGELOG entry for the tag. | |
| - name: Extract release notes from CHANGELOG | |
| id: notes | |
| run: | | |
| version="${GITHUB_REF_NAME#v}" | |
| awk -v tag="## [${version}]" ' | |
| index($0, tag)==1 {cap=1; next} | |
| index($0, "## [")==1 && cap==1 {cap=0} | |
| substr($0,1,1)=="[" && cap==1 {exit} | |
| cap {print} | |
| ' CHANGELOG.md > release-notes.md | |
| if [ -s release-notes.md ]; then | |
| echo "have_notes=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "have_notes=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| # Preinstalled gh CLI + GITHUB_TOKEN (no third-party action — keeps the | |
| # supply-chain surface small). | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ "${{ steps.notes.outputs.have_notes }}" = "true" ]; then | |
| gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" \ | |
| --notes-file release-notes.md --verify-tag dist/release/* | |
| else | |
| gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" \ | |
| --generate-notes --verify-tag dist/release/* | |
| fi |