Skip to content

Commit bcb9329

Browse files
torrid-fishclaude
andcommitted
ci: add CD workflow to build + push image to GHCR
Triggers on push to main and v*.*.* tags, plus manual workflow_dispatch. Non-default branch builds tag the image by ref + short SHA; `latest` is gated to the default branch and `stable` to version tags, so non-main builds never clobber production tags. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e652594 commit bcb9329

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
name: CD
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches: ["main"]
7+
tags: ["v*.*.*"]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
concurrency:
15+
group: cd-${{ github.ref }}
16+
cancel-in-progress: false
17+
18+
jobs:
19+
build-and-push:
20+
name: Build and push image to GHCR
21+
runs-on: ubuntu-latest
22+
env:
23+
REGISTRY: ghcr.io
24+
# Lowercase, hardcoded: GHCR image names must be lowercase, and
25+
# github.repository would be `sessatakuma/API-tools` (mixed case).
26+
# Must match deploy/compose.yml's api-tools image in jpcorrect-backend.
27+
IMAGE_NAME: sessatakuma/api-tools
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v3
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Log in to GHCR
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Extract metadata
46+
id: meta
47+
uses: docker/metadata-action@v5
48+
with:
49+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50+
tags: |
51+
type=ref,event=branch
52+
type=sha,format=short
53+
type=semver,pattern={{version}}
54+
type=semver,pattern={{major}}.{{minor}}
55+
type=raw,value=latest,enable={{is_default_branch}}
56+
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
57+
58+
- name: Build and push
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: .
62+
file: ./Dockerfile # adjust if the api-tools Dockerfile path differs
63+
platforms: linux/amd64
64+
push: true
65+
tags: ${{ steps.meta.outputs.tags }}
66+
labels: ${{ steps.meta.outputs.labels }}
67+
cache-from: type=gha
68+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)