Skip to content

Commit 243a6cf

Browse files
Merge pull request #187 from microsoft/feature/psl-conregchanges
feat: Add historical tagging and use build-push-action for Docker image build and push
2 parents bf882a9 + 706b48a commit 243a6cf

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
- dev
1919
- demo
2020
- hotfix
21-
workflow_dispatch:
21+
workflow_dispatch:
2222

2323
jobs:
2424
build-and-push:
@@ -32,14 +32,19 @@ jobs:
3232
uses: docker/setup-buildx-action@v1
3333

3434
- name: Log in to Azure Container Registry
35-
if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix') }}
35+
if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
3636
uses: azure/docker-login@v2
3737
with:
3838
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
3939
username: ${{ secrets.ACR_USERNAME }}
4040
password: ${{ secrets.ACR_PASSWORD }}
4141

42-
- name: Set Docker image tag
42+
- name: Get current date
43+
id: date
44+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
45+
46+
- name: Determine Tag Name Based on Branch
47+
id: determine_tag
4348
run: |
4449
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
4550
echo "TAG=latest" >> $GITHUB_ENV
@@ -52,24 +57,30 @@ jobs:
5257
else
5358
echo "TAG=pullrequest-ignore" >> $GITHUB_ENV
5459
fi
55-
56-
- name: Build and push Docker images optionally
60+
61+
- name: Set Historical Tag
5762
run: |
58-
cd src/backend
59-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} -f Dockerfile . && \
60-
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" ]]; then
61-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} && \
62-
echo "Backend image built and pushed successfully."
63-
else
64-
echo "Skipping Docker push for backend with tag: ${{ env.TAG }}"
65-
fi
66-
cd ../frontend
67-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} -f Dockerfile . && \
68-
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" ]]; then
69-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \
70-
echo "Frontend image built and pushed successfully."
71-
else
72-
echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}"
73-
fi
63+
DATE_TAG=$(date +'%Y-%m-%d')
64+
RUN_ID=${{ github.run_number }}
65+
# Create historical tag using TAG, DATE_TAG, and RUN_ID
66+
echo "HISTORICAL_TAG=${{ env.TAG }}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV
7467
75-
68+
- name: Build and optionally push Backend Docker image
69+
uses: docker/build-push-action@v6
70+
with:
71+
context: ./src/backend
72+
file: ./src/backend/Dockerfile
73+
push: ${{ env.TAG != 'pullrequest-ignore' }}
74+
tags: |
75+
${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }}
76+
${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }}
77+
78+
- name: Build and optionally push Frontend Docker image
79+
uses: docker/build-push-action@v6
80+
with:
81+
context: ./src/frontend
82+
file: ./src/frontend/Dockerfile
83+
push: ${{ env.TAG != 'pullrequest-ignore' }}
84+
tags: |
85+
${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }}
86+
${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }}

0 commit comments

Comments
 (0)