Skip to content

Commit c529990

Browse files
committed
ci: add GitHub Actions workflow for Docker image build and push
Add automated workflow to build and publish Docker images to GHCR: - Builds on push to master/main branches - Builds on version tags (v*) - Builds on pull requests (without pushing) - Supports manual workflow dispatch Features: - Multi-platform support (linux/amd64) - Automatic semantic versioning from git tags - GitHub Actions cache for faster builds - Build attestation for supply chain security - Images pushed to ghcr.io/netresearch/timetracker-ui Tags generated: - Branch name (e.g., master, main) - PR number (e.g., pr-123) - Semantic versions (e.g., v1.0.0, v1.0, v1) - Git SHA (e.g., master-abc1234) - 'latest' for default branch
1 parent 8c64bc2 commit c529990

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches: [ master, main ]
10+
workflow_dispatch:
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v5
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log in to GitHub Container Registry
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=pr
48+
type=semver,pattern={{version}}
49+
type=semver,pattern={{major}}.{{minor}}
50+
type=semver,pattern={{major}}
51+
type=sha,prefix={{branch}}-
52+
type=raw,value=latest,enable={{is_default_branch}}
53+
54+
- name: Build and push Docker image
55+
id: push
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: .
59+
push: ${{ github.event_name != 'pull_request' }}
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
platforms: linux/amd64
65+
66+
- name: Generate artifact attestation
67+
if: github.event_name != 'pull_request'
68+
uses: actions/attest-build-provenance@v2
69+
with:
70+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
71+
subject-digest: ${{ steps.push.outputs.digest }}
72+
push-to-registry: true
73+

0 commit comments

Comments
 (0)