Skip to content

Commit d943411

Browse files
Merge pull request #5 from Zipstack/feat/docker-ghcr-publish
ci: add GitHub Actions workflow to publish Docker images to GHCR
2 parents 42e607a + 09bab9d commit d943411

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build and Publish Docker Images to GHCR
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: "Docker image tag"
10+
required: true
11+
default: "latest"
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
16+
jobs:
17+
build-and-push:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
23+
strategy:
24+
matrix:
25+
include:
26+
- image: backend
27+
dockerfile: docker/dockerfiles/backend.Dockerfile
28+
- image: frontend
29+
dockerfile: docker/dockerfiles/frontend.Dockerfile
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
with:
35+
ref: ${{ github.event.release.tag_name || github.event.inputs.tag }}
36+
37+
- name: Set up QEMU (for multi-platform builds)
38+
uses: docker/setup-qemu-action@v3
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Log in to GHCR
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ${{ env.REGISTRY }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Set image prefix
51+
id: repo
52+
run: echo "image_prefix=${{ env.REGISTRY }}/${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
53+
54+
- name: Extract metadata
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ${{ steps.repo.outputs.image_prefix }}/${{ matrix.image }}
59+
tags: |
60+
type=semver,pattern={{version}}
61+
type=semver,pattern={{major}}.{{minor}}
62+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
63+
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
64+
65+
- name: Build and push ${{ matrix.image }}
66+
uses: docker/build-push-action@v6
67+
with:
68+
context: .
69+
file: ${{ matrix.dockerfile }}
70+
platforms: linux/amd64,linux/arm64
71+
push: true
72+
tags: ${{ steps.meta.outputs.tags }}
73+
labels: ${{ steps.meta.outputs.labels }}
74+
cache-from: type=gha,scope=${{ matrix.image }}
75+
cache-to: type=gha,mode=max,scope=${{ matrix.image }}

0 commit comments

Comments
 (0)