Skip to content

Commit f385f84

Browse files
ci: enhance container workflow with metadata action and tag improvements
1 parent 4914364 commit f385f84

1 file changed

Lines changed: 32 additions & 22 deletions

File tree

.github/workflows/container.yml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,52 @@ on:
55
branches:
66
- main
77
tags:
8-
- v*
8+
- 'v*.*.*'
9+
10+
permissions:
11+
contents: read
12+
packages: write
913

1014
jobs:
1115
build:
1216
runs-on: ubuntu-latest
1317
steps:
14-
- name: Set up QEMU
15-
uses: docker/setup-qemu-action@v3
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
1623
- name: Set up Docker Buildx
1724
uses: docker/setup-buildx-action@v3
25+
1826
- name: Login to GitHub Container Registry
1927
uses: docker/login-action@v3
2028
with:
2129
registry: ghcr.io
2230
username: ${{ github.repository_owner }}
2331
password: ${{ secrets.GITHUB_TOKEN }}
24-
- if: "startsWith(github.ref, 'refs/tags/v')"
25-
name: build container (release)
26-
uses: docker/build-push-action@v6
32+
33+
- name: Extract Metadata (tags, labels) for Docker
34+
id: meta
35+
uses: docker/metadata-action@v5
2736
with:
28-
push: true
29-
platforms: linux/amd64,linux/arm64
30-
cache-from: type=gha
31-
cache-to: type=gha,mode=max
37+
images: ghcr.io/deltalaboratory/postgres-backup
3238
tags: |
33-
ghcr.io/deltalaboratory/postgres-backup:latest
34-
ghcr.io/deltalaboratory/postgres-backup:${{ github.ref_name }}
35-
ghcr.io/deltalaboratory/postgres-backup:${{ github.sha }}
36-
- if: "!startsWith(github.ref, 'refs/tags/v')"
37-
name: build container (development)
39+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} # 'latest' tag only for versioned releases
40+
type=raw,value=development,enable=${{ github.ref == 'refs/heads/main' }} # 'development' tag for main branch
41+
type=semver,pattern={{version}} # Semantic version tag (e.g., 1.0.0) from git tags
42+
type=sha,prefix=,format=short # Short commit SHA tag for unique identification
43+
labels: |
44+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
45+
org.opencontainers.image.created=${{ github.event.repository.updated_at }}
46+
org.opencontainers.image.revision=${{ github.sha }}
47+
48+
- name: Build and Push Docker Image
3849
uses: docker/build-push-action@v6
3950
with:
40-
push: true
41-
platforms: linux/amd64,linux/arm64
42-
cache-from: type=gha
43-
cache-to: type=gha,mode=max
44-
tags: |
45-
ghcr.io/deltalaboratory/postgres-backup:development
46-
ghcr.io/deltalaboratory/postgres-backup:${{ github.sha }}
51+
push: true # Push the image to the registry
52+
platforms: linux/amd64,linux/arm64 # Build for multiple architectures
53+
tags: ${{ steps.meta.outputs.tags }} # Use tags generated by metadata-action
54+
labels: ${{ steps.meta.outputs.labels }} # Use labels generated by metadata-action
55+
cache-from: type=gha # Pull cache from GitHub Actions cache
56+
cache-to: type=gha,mode=max # Push cache to GitHub Actions cache (with max retention) 🚀

0 commit comments

Comments
 (0)