Skip to content

Commit 859dc75

Browse files
committed
update workflow for building docker image
1 parent fa65317 commit 859dc75

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

.github/workflows/build-and-push-docker-image.yml

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,32 @@ jobs:
1111
if: endsWith(github.ref, '/prod') || endsWith(github.ref, '/stage') || endsWith(github.ref, '/migration')
1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
1515

1616
- name: Set up Docker Buildx
17-
uses: docker/setup-buildx-action@v1
17+
uses: docker/setup-buildx-action@v3
1818

1919
- name: Login to DockerHub
20-
uses: docker/login-action@v1
20+
uses: docker/login-action@v3
2121
with:
2222
username: ${{ secrets.DOCKER_USERNAME }}
2323
password: ${{ secrets.DOCKER_PASSWORD }}
2424

25-
- name: Build and push production image
26-
if: endsWith(github.ref, '/prod')
27-
uses: docker/build-push-action@v2
28-
with:
29-
context: .
30-
file: ./Dockerfile
31-
tags: ${{ env.DOCKER_REPO }}:prod
32-
push: ${{ endsWith(github.ref, '/prod') }}
33-
34-
- name: Build and push stage image
35-
if: endsWith(github.ref, '/stage')
36-
uses: docker/build-push-action@v2
25+
- name: Extract metadata (tags, labels) for Docker
26+
id: meta
27+
uses: docker/metadata-action@v5
3728
with:
38-
context: .
39-
file: ./stage.Dockerfile
40-
tags: ${{ env.DOCKER_REPO }}:stage
41-
push: ${{ endsWith(github.ref, '/stage') }}
29+
images: ${{ steps.base_image_name.outputs.image_name }}
30+
tags: |
31+
type=ref,event=branch
32+
type=ref,event=pr
33+
type=raw,value=latest,enable={{is_default_branch}}
34+
type=raw,value={{sha}}-{{date 'X'}},enable=${{ startsWith(github.ref, 'refs/heads') }}
4235
43-
- name: Build and push migration image
44-
if: endsWith(github.ref, '/migration')
45-
uses: docker/build-push-action@v2
36+
- name: Build and push production image
37+
uses: docker/build-push-action@v5
4638
with:
4739
context: .
48-
file: ./stage.Dockerfile
49-
tags: ${{ env.DOCKER_REPO }}:migration
50-
push: ${{ endsWith(github.ref, '/migration') }}
40+
file: ./Dockerfile
41+
tags: ${{ steps.meta.outputs.tags }}
42+
push: true

0 commit comments

Comments
 (0)