@@ -2,43 +2,50 @@ name: Publish
22
33on :
44 push :
5- branches :
6- - main
75 tags :
8- - " v* "
6+ - " v[0-9]+.[0-9]+.[0-9]+ "
97
108env :
119 IMAGE_NAME : agg
1210
1311jobs :
1412 publish :
15- runs-on : ubuntu-22.04
13+ runs-on : ubuntu-latest
1614 permissions :
1715 packages : write
1816 contents : read
1917
2018 steps :
2119 - uses : actions/checkout@v6.0.2
2220
23- - name : Build image
24- run : docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
25-
26- - name : Log in to registry
27- run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
28-
29- - name : Push image
30- run : |
31- IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
32-
33- # Change all uppercase to lowercase
34- IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
35- # Strip git ref prefix from version
36- VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
37- # Strip "v" prefix from tag name
38- [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
39- # Use Docker `latest` tag convention
40- [ "$VERSION" == "main" ] && VERSION=latest
41- echo IMAGE_ID=$IMAGE_ID
42- echo VERSION=$VERSION
43- docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
44- docker push $IMAGE_ID:$VERSION
21+ - name : Set up Docker Buildx
22+ uses : docker/setup-buildx-action@v4.0.0
23+
24+ - name : Log in to GitHub Container Registry
25+ uses : docker/login-action@v4.1.0
26+ with :
27+ registry : ghcr.io
28+ username : ${{ github.actor }}
29+ password : ${{ secrets.GITHUB_TOKEN }}
30+
31+ - name : Extract image metadata
32+ id : meta
33+ uses : docker/metadata-action@v6.0.0
34+ with :
35+ images : ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
36+ flavor : |
37+ latest=auto
38+ tags : |
39+ type=semver,pattern={{version}}
40+ labels : |
41+ runnumber=${{ github.run_id }}
42+
43+ - name : Build and push image
44+ uses : docker/build-push-action@v7.1.0
45+ with :
46+ context : .
47+ push : true
48+ tags : ${{ steps.meta.outputs.tags }}
49+ labels : ${{ steps.meta.outputs.labels }}
50+ cache-from : type=gha
51+ cache-to : type=gha,mode=max
0 commit comments