From bd6202523009fb1a3b73395e9c6047abca00eb95 Mon Sep 17 00:00:00 2001 From: Abdul-Microsoft Date: Wed, 7 May 2025 11:10:13 +0530 Subject: [PATCH 1/5] feat: add historical tagging to Docker image builds --- .github/workflows/docker-build-and-push.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index 383ef2fc0..30e7b39e1 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -32,7 +32,7 @@ jobs: uses: docker/setup-buildx-action@v1 - name: Log in to Azure Container Registry - if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix') }} + if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' || github.ref_name == 'feature/conregchanges') }} uses: azure/docker-login@v2 with: login-server: ${{ secrets.ACR_LOGIN_SERVER }} @@ -41,6 +41,9 @@ jobs: - name: Set Docker image tag run: | + DATE_TAG=$(date +'%Y-%m-%d') + RUN_ID=${{ github.run_number }} + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then echo "TAG=latest" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then @@ -49,24 +52,35 @@ jobs: echo "TAG=demo" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then echo "TAG=hotfix" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == "refs/heads/feature/conregchanges" ]]; then + echo "TAG=conregchanges" >> $GITHUB_ENV else echo "TAG=pullrequest-ignore" >> $GITHUB_ENV fi + + echo "HISTORICAL_TAG=${TAG}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV + - name: Build and push Docker images optionally run: | cd src/backend docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} -f Dockerfile . && \ - if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" ]]; then + docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ + + if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "conregchanges" ]]; then docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} && \ + docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ echo "Backend image built and pushed successfully." else echo "Skipping Docker push for backend with tag: ${{ env.TAG }}" fi cd ../frontend docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} -f Dockerfile . && \ - if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" ]]; then + docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ + + if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "conregchanges" ]]; then docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \ + docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ echo "Frontend image built and pushed successfully." else echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}" From 84cadee27014497f1b3b273fa72d3509620eeb50 Mon Sep 17 00:00:00 2001 From: Abdul-Microsoft Date: Wed, 7 May 2025 11:19:55 +0530 Subject: [PATCH 2/5] added changes for testing from feature branch --- .github/workflows/docker-build-and-push.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index 30e7b39e1..b5a84964f 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -18,6 +18,7 @@ on: - dev - demo - hotfix + - feature/psl-conregchanges workflow_dispatch: jobs: @@ -32,7 +33,7 @@ jobs: uses: docker/setup-buildx-action@v1 - name: Log in to Azure Container Registry - if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' || github.ref_name == 'feature/conregchanges') }} + if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' || github.ref_name == 'feature/psl-conregchanges') }} uses: azure/docker-login@v2 with: login-server: ${{ secrets.ACR_LOGIN_SERVER }} @@ -52,8 +53,8 @@ jobs: echo "TAG=demo" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then echo "TAG=hotfix" >> $GITHUB_ENV - elif [[ "${{ github.ref }}" == "refs/heads/feature/conregchanges" ]]; then - echo "TAG=conregchanges" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == "refs/heads/feature/psl-conregchanges" ]]; then + echo "TAG=psl-conregchanges" >> $GITHUB_ENV else echo "TAG=pullrequest-ignore" >> $GITHUB_ENV fi @@ -67,7 +68,7 @@ jobs: docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} -f Dockerfile . && \ docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ - if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "conregchanges" ]]; then + if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "psl-conregchanges" ]]; then docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} && \ docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ echo "Backend image built and pushed successfully." @@ -78,7 +79,7 @@ jobs: docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} -f Dockerfile . && \ docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ - if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "conregchanges" ]]; then + if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "psl-conregchanges" ]]; then docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \ docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ echo "Frontend image built and pushed successfully." From 9b8944db965e25d21cce1b2d221257ba36639955 Mon Sep 17 00:00:00 2001 From: Abdul-Microsoft Date: Wed, 7 May 2025 11:53:28 +0530 Subject: [PATCH 3/5] refactor: improve Docker build workflow by restructuring tag determination and historical tagging --- .github/workflows/docker-build-and-push.yml | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index b5a84964f..74af5699b 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -7,6 +7,7 @@ on: - dev - demo - hotfix + - feature/psl-conregchanges pull_request: types: - opened @@ -18,8 +19,7 @@ on: - dev - demo - hotfix - - feature/psl-conregchanges - workflow_dispatch: + workflow_dispatch: jobs: build-and-push: @@ -33,18 +33,20 @@ jobs: uses: docker/setup-buildx-action@v1 - name: Log in to Azure Container Registry - if: ${{ (github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' || github.ref_name == 'feature/psl-conregchanges') }} + if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' || github.ref_name == 'feature/psl-conregchanges' }} uses: azure/docker-login@v2 with: login-server: ${{ secrets.ACR_LOGIN_SERVER }} username: ${{ secrets.ACR_USERNAME }} password: ${{ secrets.ACR_PASSWORD }} - - name: Set Docker image tag + - name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + + - name: Determine Tag Name Based on Branch + id: determine_tag run: | - DATE_TAG=$(date +'%Y-%m-%d') - RUN_ID=${{ github.run_number }} - if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then echo "TAG=latest" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then @@ -58,12 +60,17 @@ jobs: else echo "TAG=pullrequest-ignore" >> $GITHUB_ENV fi - - echo "HISTORICAL_TAG=${TAG}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV - - + + - name: Set Historical Tag + run: | + DATE_TAG=$(date +'%Y-%m-%d') + RUN_ID=${{ github.run_number }} + # Create historical tag using TAG, DATE_TAG, and RUN_ID + echo "HISTORICAL_TAG=${{ env.TAG }}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV + - name: Build and push Docker images optionally run: | + # Backend Image Build and Push cd src/backend docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} -f Dockerfile . && \ docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ @@ -75,6 +82,8 @@ jobs: else echo "Skipping Docker push for backend with tag: ${{ env.TAG }}" fi + + # Frontend Image Build and Push cd ../frontend docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} -f Dockerfile . && \ docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ @@ -86,5 +95,3 @@ jobs: else echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}" fi - - From 034fb65d7e28fb9eae8627ec55ab507c0fb680e1 Mon Sep 17 00:00:00 2001 From: Abdul-Microsoft Date: Wed, 7 May 2025 15:10:06 +0530 Subject: [PATCH 4/5] refactor: streamline Docker image build and push steps using build-push-action --- .github/workflows/docker-build-and-push.yml | 44 +++++++++------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index 74af5699b..5e2e238e9 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -68,30 +68,22 @@ jobs: # Create historical tag using TAG, DATE_TAG, and RUN_ID echo "HISTORICAL_TAG=${{ env.TAG }}_${DATE_TAG}_${RUN_ID}" >> $GITHUB_ENV - - name: Build and push Docker images optionally - run: | - # Backend Image Build and Push - cd src/backend - docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} -f Dockerfile . && \ - docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ - - if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "psl-conregchanges" ]]; then - docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} && \ - docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} && \ - echo "Backend image built and pushed successfully." - else - echo "Skipping Docker push for backend with tag: ${{ env.TAG }}" - fi - - # Frontend Image Build and Push - cd ../frontend - docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} -f Dockerfile . && \ - docker tag ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ + - name: Build and optionally push Backend Docker image + uses: docker/build-push-action@v6 + with: + context: ./src/backend + file: ./src/backend/Dockerfile + push: ${{ env.TAG != 'pullrequest-ignore' }} + tags: | + ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.TAG }} + ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.HISTORICAL_TAG }} - if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" || "${{ env.TAG }}" == "hotfix" || "${{ env.TAG }}" == "psl-conregchanges" ]]; then - docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \ - docker push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} && \ - echo "Frontend image built and pushed successfully." - else - echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}" - fi + - name: Build and optionally push Frontend Docker image + uses: docker/build-push-action@v6 + with: + context: ./src/frontend + file: ./src/frontend/Dockerfile + push: ${{ env.TAG != 'pullrequest-ignore' }} + tags: | + ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} + ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.HISTORICAL_TAG }} \ No newline at end of file From 706b48a42c6604e851313caaf8b02ada2056ec82 Mon Sep 17 00:00:00 2001 From: Abdul-Microsoft Date: Wed, 7 May 2025 15:45:49 +0530 Subject: [PATCH 5/5] remove feature branch from Docker build workflow triggers --- .github/workflows/docker-build-and-push.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index 5e2e238e9..a6d2c59a4 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -7,7 +7,6 @@ on: - dev - demo - hotfix - - feature/psl-conregchanges pull_request: types: - opened @@ -33,7 +32,7 @@ jobs: uses: docker/setup-buildx-action@v1 - name: Log in to Azure Container Registry - if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' || github.ref_name == 'feature/psl-conregchanges' }} + if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} uses: azure/docker-login@v2 with: login-server: ${{ secrets.ACR_LOGIN_SERVER }} @@ -55,8 +54,6 @@ jobs: echo "TAG=demo" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then echo "TAG=hotfix" >> $GITHUB_ENV - elif [[ "${{ github.ref }}" == "refs/heads/feature/psl-conregchanges" ]]; then - echo "TAG=psl-conregchanges" >> $GITHUB_ENV else echo "TAG=pullrequest-ignore" >> $GITHUB_ENV fi