Skip to content

Commit c283529

Browse files
committed
Update GitHub Actions docker build/push workflow
1 parent cc0d27b commit c283529

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

.github/workflows/docker-publish.yml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,50 @@ name: Build Docker Image, Push to GHCR
22

33
on:
44
push:
5-
branches:
6-
- master
5+
branches: [ "main" ]
6+
tags: [ 'v*.*.*' ]
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: osmcha/osmcha-django
711

812
jobs:
913
build:
1014
runs-on: ubuntu-latest
1115

1216
steps:
1317
- name: Checkout code
14-
uses: actions/checkout@v2
18+
uses: actions/checkout@v4
1519

20+
# Enable BuildKit for docker builds. This enables building
21+
# multi-platform images and exporting the layer cache
22+
# https://github.com/docker/setup-buildx-action
1623
- name: Set up Docker Buildx
17-
uses: docker/setup-buildx-action@v1
24+
uses: docker/setup-buildx-action@v3
1825

19-
- name: Login to GitHub Container Registry
20-
uses: docker/login-action@v2
26+
# https://github.com/docker/login-action
27+
- name: Login to Registry ${{ env.REGISTRY }}
28+
uses: docker/login-action@v3
2129
with:
22-
registry: ghcr.io
30+
registry: ${{ env.REGISTRY }}
2331
username: ${{ github.actor }}
2432
password: ${{ secrets.GITHUB_TOKEN }}
2533

34+
# Extract metadata (tags, labels) for Docker
35+
# https://github.com/docker/metadata-action
36+
- name: Extract Docker metadata
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
42+
# https://github.com/docker/build-push-action
2643
- name: Build and push Docker image
27-
uses: docker/build-push-action@v4
44+
uses: docker/build-push-action@v5
2845
with:
2946
context: .
3047
push: true
31-
tags: |
32-
ghcr.io/osmcha/osmcha-django:latest
33-
ghcr.io/osmcha/osmcha-django:${{ github.sha }}
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}
3450
cache-from: type=gha
35-
cache-to: type=gha,mode=max
51+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)