Files
CaddyProxyManager/.github/workflows/ci.yml
Pacerino abed2d2c69 [CI] Add Dockerfile, entrypoint and GitHub Actions pipeline
Multi-stage Dockerfile builds the frontend and backend into a single
Alpine image bundling Caddy, started via an entrypoint. CI runs backend
tests (with race detector), builds the frontend and publishes the image
to GHCR on master/tags. Targets a self-hosted runner with a local build
cache. Updates .gitignore (secrets/runtime state) and README.
2026-06-14 02:35:56 +02:00

119 lines
3.3 KiB
YAML

name: CI
on:
push:
branches: [master]
tags: ["v*"]
pull_request:
branches: [master]
permissions:
contents: read
packages: write
# Cancel superseded runs for the same ref. Useful on a single self-hosted
# runner so a new push doesn't queue behind an outdated run.
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
test-backend:
name: Test backend
runs-on: self-hosted
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.25"
cache-dependency-path: backend/go.sum
# The backend embeds frontend assets; provide a placeholder so it builds.
- name: Create embed placeholder
run: mkdir -p embed/assets && echo "<!doctype html>" > embed/assets/index.html
- name: Vet
run: go vet ./...
- name: Test
run: go test -race -count=1 ./...
test-frontend:
name: Build frontend
runs-on: self-hosted
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install
run: npm ci || npm install
- name: Type-check and build
run: |
mkdir -p ../backend/embed/assets
npm run build
docker:
name: Build & publish image
runs-on: self-hosted
needs: [test-backend, test-frontend]
# Only push on master pushes and version tags, not on PRs.
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.ref_name }}
COMMIT=${{ github.sha }}
# Local cache persists on the self-hosted runner's disk between runs.
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# Replace the old cache with the new one to keep it from growing
# unbounded across runs.
- name: Rotate build cache
if: always()
run: |
rm -rf /tmp/.buildx-cache
if [ -d /tmp/.buildx-cache-new ]; then
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
fi