Build Docker and Optional Push v3 #399
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Docker and Optional Push | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| - demo | |
| - hotfix | |
| - feature/psl-conregchanges | |
| pull_request: | |
| types: | |
| - opened | |
| - ready_for_review | |
| - reopened | |
| - synchronize | |
| branches: | |
| - main | |
| - dev | |
| - demo | |
| - hotfix | |
| workflow_dispatch: | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Set up Docker Buildx | |
| 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' }} | |
| uses: azure/docker-login@v2 | |
| with: | |
| login-server: ${{ secrets.ACR_LOGIN_SERVER }} | |
| username: ${{ secrets.ACR_USERNAME }} | |
| password: ${{ secrets.ACR_PASSWORD }} | |
| - 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: | | |
| if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| echo "TAG=latest" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then | |
| echo "TAG=dev" >> $GITHUB_ENV | |
| elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then | |
| 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 | |
| - 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 }} && \ | |
| 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 }} && \ | |
| 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 |