Skip to content

Commit bd62025

Browse files
feat: add historical tagging to Docker image builds
1 parent bf882a9 commit bd62025

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ 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' || github.ref_name == 'feature/conregchanges') }}
3636
uses: azure/docker-login@v2
3737
with:
3838
login-server: ${{ secrets.ACR_LOGIN_SERVER }}
@@ -41,6 +41,9 @@ jobs:
4141

4242
- name: Set Docker image tag
4343
run: |
44+
DATE_TAG=$(date +'%Y-%m-%d')
45+
RUN_ID=${{ github.run_number }}
46+
4447
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
4548
echo "TAG=latest" >> $GITHUB_ENV
4649
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
@@ -49,24 +52,35 @@ jobs:
4952
echo "TAG=demo" >> $GITHUB_ENV
5053
elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then
5154
echo "TAG=hotfix" >> $GITHUB_ENV
55+
elif [[ "${{ github.ref }}" == "refs/heads/feature/conregchanges" ]]; then
56+
echo "TAG=conregchanges" >> $GITHUB_ENV
5257
else
5358
echo "TAG=pullrequest-ignore" >> $GITHUB_ENV
5459
fi
60+
61+
echo "HISTORICAL_TAG=${TAG}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV
62+
5563

5664
- name: Build and push Docker images optionally
5765
run: |
5866
cd src/backend
5967
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
68+
docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \
69+
70+
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "conregchanges" ]]; then
6171
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} && \
72+
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \
6273
echo "Backend image built and pushed successfully."
6374
else
6475
echo "Skipping Docker push for backend with tag: ${{ env.TAG }}"
6576
fi
6677
cd ../frontend
6778
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
79+
docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \
80+
81+
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "conregchanges" ]]; then
6982
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \
83+
docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \
7084
echo "Frontend image built and pushed successfully."
7185
else
7286
echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}"

0 commit comments

Comments
 (0)