@@ -2,7 +2,7 @@ name: CD Pipeline
22
33on :
44 push :
5- branches : [ main ]
5+ branches : [ main, cd ]
66 workflow_dispatch : {}
77
88permissions :
@@ -17,24 +17,39 @@ jobs:
1717 runs-on : ubuntu-latest
1818 steps :
1919 - uses : actions/checkout@v4
20-
2120 - name : Set up Docker Buildx
2221 uses : docker/setup-buildx-action@v3
2322
23+ - name : Prepare image name
24+ id : prep
25+ run : |
26+ IMAGE="ghcr.io/${GITHUB_REPOSITORY,,}"
27+ echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
28+
2429 - name : Login to GHCR
2530 uses : docker/login-action@v3
2631 with :
2732 registry : ghcr.io
2833 username : ${{ github.actor }}
2934 password : ${{ secrets.GITHUB_TOKEN }}
30-
35+
3136 - name : Build and push (cached)
3237 uses : docker/build-push-action@v6
3338 with :
3439 context : .
3540 push : true
3641 tags : |
37- ghcr.io/${{ github.repository }}:${{ env.VERSION }}
38- ghcr.io/${{ github.repository }}:latest
42+ ${{ steps.prep.outputs.image }}:${{ env.VERSION }}
43+ ${{ steps.prep.outputs.image }}:${{ github.ref_name }}
44+ cache-from : type=gha
45+ cache-to : type=gha,mode=max
46+
47+ - name : Tag latest (main only)
48+ if : github.ref == 'refs/heads/main'
49+ uses : docker/build-push-action@v6
50+ with :
51+ context : .
52+ push : true
53+ tags : ${{ steps.prep.outputs.image }}:latest
3954 cache-from : type=gha
4055 cache-to : type=gha,mode=max
0 commit comments