Skip to content

Commit 2ecf46a

Browse files
authored
feat: add GitHub Actions workflow for building and publishing Docker images with multi-platform support
1 parent 6243bf1 commit 2ecf46a

3 files changed

Lines changed: 150 additions & 2 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
tags:
10+
- '[0-9][0-9][0-9][0-9].[0-9]*.[0-9]*'
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
push_to_registry:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
packages: write
21+
contents: read
22+
attestations: write
23+
id-token: write
24+
steps:
25+
- name: Check out the repo
26+
uses: actions/checkout@v4
27+
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.repository_owner }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Set up Node.js
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: '22'
39+
40+
- name: Get version from package.json
41+
id: app_version
42+
run: |
43+
VERSION=$(node -p "require('./package.json').version")
44+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
45+
46+
- name: Docker metadata (tags, labels)
47+
id: meta
48+
uses: docker/metadata-action@v5
49+
with:
50+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51+
tags: |
52+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }}
53+
type=raw,value=${{ steps.app_version.outputs.version }}
54+
type=raw,value=${{ github.sha }}
55+
56+
- name: Set up QEMU
57+
uses: docker/setup-qemu-action@v3
58+
59+
- name: Setup Docker buildx
60+
uses: docker/setup-buildx-action@v3
61+
62+
- name: Build and push
63+
uses: docker/build-push-action@v5
64+
with:
65+
context: .
66+
push: true
67+
tags: ${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
platforms: |
70+
linux/amd64
71+
linux/arm64/v8
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
75+
- name: Generate artifact attestation
76+
uses: actions/attest-build-provenance@v1
77+
with:
78+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
79+
subject-digest: ${{ steps.build.outputs.digest }}
80+
push-to-registry: true

GITHUB_ACTIONS.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# GitHub Actions Docker Publishing Setup
2+
3+
This repository includes a GitHub Actions workflow that automatically builds and publishes Docker images to GitHub Container Registry (GHCR).
4+
5+
## Workflow Overview
6+
7+
The workflow (`/.github/workflows/publish-docker.yml`) automatically:
8+
9+
1. **Builds** the Docker image using multi-platform support (AMD64 and ARM64)
10+
2. **Publishes** to `ghcr.io/sillyangel/mice`
11+
3. **Tags** images appropriately based on git refs
12+
4. **Caches** layers for faster subsequent builds
13+
5. **Generates** build provenance attestations for security
14+
15+
## Trigger Conditions
16+
17+
The workflow runs on:
18+
19+
- **Push to main/master branch** → Creates `latest` tag
20+
- **Push tags** (e.g., `2025.07.02`) → Creates date-based version tags
21+
- **Pull requests** → Creates PR-specific tags for testing
22+
- **Manual dispatch** → Can be triggered manually from GitHub UI
23+
24+
## Image Tags Generated
25+
26+
Based on different triggers, the workflow creates these tags:
27+
28+
### Main Branch Push
29+
30+
- `ghcr.io/sillyangel/mice:latest`
31+
32+
### Tag Push (e.g., `2025.07.02`)
33+
34+
- `ghcr.io/sillyangel/mice:2025.07.02`
35+
- `ghcr.io/sillyangel/mice:latest`
36+
37+
### Pull Request
38+
39+
- `ghcr.io/sillyangel/mice:pr-123`
40+
41+
## Multi-Platform Support
42+
43+
The workflow builds for multiple architectures:
44+
45+
- `linux/amd64` (Intel/AMD 64-bit)
46+
- `linux/arm64` (ARM 64-bit, Apple Silicon, etc.)
47+
48+
## Usage After Setup
49+
50+
Once the workflow is set up:
51+
52+
1. **Push to main** → New `latest` image published
53+
2. **Create a release** → Versioned images published
54+
3. **Users can pull**: `docker pull ghcr.io/sillyangel/mice:latest`
55+
56+
## Manual Image Building
57+
58+
You can also build and push manually:
59+
60+
```bash
61+
# Build for multiple platforms
62+
docker buildx build --platform linux/amd64,linux/arm64 \
63+
-t ghcr.io/sillyangel/mice:latest \
64+
--push .
65+
66+
# Login first (if needed)
67+
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
68+
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)