@@ -3,19 +3,28 @@ name: Build and push docker image
33on :
44 push :
55 branches :
6- - prod
7- - stage
6+ - ' *'
7+ tags :
8+ - ' v*'
89
910env :
10- DOCKER_REPO : ${{ secrets.DOCKER_USERNAME }}/hawk-api
11+ REGISTRY : ghcr.io
12+ IMAGE_NAME : ${{ github.repository }}
1113 HAWK_TOKEN : ${{ secrets.HAWK_TOKEN }}
1214
1315jobs :
1416 build :
1517 runs-on : ubuntu-20.04
1618 steps :
1719 - name : Checkout repository
18- uses : actions/checkout@v2
20+ uses : actions/checkout@v3
21+
22+ - name : Login to GitHub registry
23+ uses : docker/login-action@v2
24+ with :
25+ registry : ${{ env.REGISTRY }}
26+ username : ${{ github.actor }}
27+ password : ${{ secrets.GITHUB_TOKEN }}
1928
2029 - name : Get package info
2130 id : packageInfo
@@ -27,12 +36,23 @@ jobs:
2736 release : ${{ steps.packageInfo.outputs.name }}-${{ steps.packageInfo.outputs.version }}
2837 token : ${{ secrets.HAWK_TOKEN }}
2938
30- - name : Build and push docker image
31- uses : docker/build-push-action@v1
39+ - name : Extract metadata (tags, labels) for Docker
40+ id : meta
41+ uses : docker/metadata-action@v4
42+ with :
43+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+ tags : |
45+ type=ref,event=branch
46+ type=ref,event=pr
47+ type=raw,value={{branch}}-{{sha}}-{{date 'X'}},enable=${{ startsWith(github.ref, 'refs/heads') }}
48+ type=semver,pattern={{version}}
49+ type=semver,pattern={{major}}.{{minor}}
50+
51+ - name : Build and push image
52+ uses : docker/build-push-action@v3
3253 with :
33- username : ${{ secrets.DOCKER_USERNAME }}
34- password : ${{ secrets.DOCKER_PASSWORD }}
35- repository : ${{ env.DOCKER_REPO }}
36- tag_with_ref : true
37- dockerfile : docker/Dockerfile.prod
38- push : ${{ endsWith(github.ref, '/stage') || endsWith(github.ref, '/prod') }}
54+ context : .
55+ file : docker/Dockerfile.prod
56+ tags : ${{ steps.meta.outputs.tags }}
57+ labels : ${{ steps.meta.outputs.labels }}
58+ push : ${{ startsWith(github.ref, 'refs/tags/v') || endsWith(github.ref, '/stage') }}
0 commit comments