Skip to content

Commit 4bdd64c

Browse files
committed
ci: limit builds to main and PRs with improved tagging
- Build only on main branch pushes and PRs to main - Tag main builds as both 'latest' and 'main' - Tag PR builds as 'pr-<number>' - Add SHA tags for traceability (sha-<hash>) - Simplify README image reference to :latest
1 parent 4bbe138 commit 4bdd64c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ name: Build Docker Image
33
on:
44
push:
55
branches:
6-
- '**' # Build all branches during rapid iteration
6+
- main
7+
pull_request:
8+
branches:
9+
- main
710

811
permissions:
912
contents: read
@@ -34,9 +37,22 @@ jobs:
3437
username: ${{ github.actor }}
3538
password: ${{ secrets.GHCR_PAT || secrets.GITHUB_TOKEN }}
3639

37-
- name: Sanitize branch name for Docker tag
38-
id: tag
39-
run: echo "name=$(echo ${{ github.ref_name }} | sed 's/\//-/g')" >> $GITHUB_OUTPUT
40+
- name: Generate Docker tags
41+
id: meta
42+
run: |
43+
IMAGE="${{ env.REGISTRY }}/${{ steps.image.outputs.name }}"
44+
SHA_SHORT=$(echo ${{ github.sha }} | cut -c1-7)
45+
46+
if [ "${{ github.event_name }}" = "pull_request" ]; then
47+
# PR builds: tag as pr-<number>
48+
TAGS="${IMAGE}:pr-${{ github.event.pull_request.number }},${IMAGE}:sha-${SHA_SHORT}"
49+
else
50+
# Push to main: tag as both 'main' and 'latest'
51+
TAGS="${IMAGE}:main,${IMAGE}:latest,${IMAGE}:sha-${SHA_SHORT}"
52+
fi
53+
54+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
55+
echo "primary_tag=$(echo ${TAGS} | cut -d',' -f1 | cut -d':' -f2)" >> $GITHUB_OUTPUT
4056
4157
- name: Build and push Docker image
4258
uses: docker/build-push-action@v5
@@ -45,12 +61,12 @@ jobs:
4561
file: docker/Dockerfile
4662
platforms: linux/amd64
4763
push: true
48-
tags: ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.name }}
64+
tags: ${{ steps.meta.outputs.tags }}
4965
cache-from: type=gha
5066
cache-to: type=gha,mode=max
5167

5268
- name: Image summary
5369
run: |
5470
echo "### Docker Image Built 🐳" >> $GITHUB_STEP_SUMMARY
5571
echo "" >> $GITHUB_STEP_SUMMARY
56-
echo "**Image:** ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:${{ steps.tag.outputs.name }}" >> $GITHUB_STEP_SUMMARY
72+
echo "**Tags:** ${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ kubectl logs -n devseed-staging -l eventsource-name=rabbitmq-geozarr --tail=50
251251

252252
## Resources
253253

254-
**Pipeline Image:** `ghcr.io/eopf-explorer/data-pipeline:main`
254+
**Container Image:** `ghcr.io/eopf-explorer/data-pipeline:latest`
255255

256256
**Resource Limits:**
257257
- CPU: 2 cores (convert), 500m (register)

0 commit comments

Comments
 (0)