|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + - demo |
| 9 | + - hotfix |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - ready_for_review |
| 14 | + - reopened |
| 15 | + - synchronize |
| 16 | + branches: |
| 17 | + - main |
| 18 | + - dev |
| 19 | + - demo |
| 20 | + - hotfix |
| 21 | + workflow_dispatch: |
| 22 | + |
| 23 | +jobs: |
| 24 | + build-and-push: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v2 |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@v1 |
| 33 | + |
| 34 | + - name: Log in to Azure Container Registry |
| 35 | + if: ${{ github.ref_name == 'main' }} |
| 36 | + uses: azure/docker-login@v2 |
| 37 | + with: |
| 38 | + login-server: ${{ secrets.ACR_LOGIN_SERVER }} |
| 39 | + username: ${{ secrets.ACR_USERNAME }} |
| 40 | + password: ${{ secrets.ACR_PASSWORD }} |
| 41 | + |
| 42 | + - name: Log in to Azure Container Registry (Dev/Demo) |
| 43 | + if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} |
| 44 | + uses: azure/docker-login@v2 |
| 45 | + with: |
| 46 | + login-server: ${{ secrets.ACR_DEV_LOGIN_SERVER }} |
| 47 | + username: ${{ secrets.ACR_DEV_USERNAME }} |
| 48 | + password: ${{ secrets.ACR_DEV_PASSWORD }} |
| 49 | + |
| 50 | + - name: Set Docker image tag |
| 51 | + run: | |
| 52 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 53 | + echo "TAG=latest" >> $GITHUB_ENV |
| 54 | + elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then |
| 55 | + echo "TAG=dev" >> $GITHUB_ENV |
| 56 | + elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then |
| 57 | + echo "TAG=demo" >> $GITHUB_ENV |
| 58 | + elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then |
| 59 | + echo "TAG=hotfix" >> $GITHUB_ENV |
| 60 | + fi |
| 61 | + - name: Build and push Docker images |
| 62 | + if: ${{ github.ref_name == 'main' }} |
| 63 | + run: | |
| 64 | + cd src/backend |
| 65 | + docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} -f Dockerfile . && \ |
| 66 | + docker push ${{ secrets.ACR_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} && \ |
| 67 | + echo "Backend image built and pushed successfully." |
| 68 | + cd ../frontend |
| 69 | + docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} -f Dockerfile . && \ |
| 70 | + docker push ${{ secrets.ACR_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} && \ |
| 71 | + echo "Frontend image built and pushed successfully." |
| 72 | + - name: Build and push Docker images (Dev/Demo/hotfix) |
| 73 | + if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} |
| 74 | + run: | |
| 75 | + cd src/backend |
| 76 | + docker build -t ${{ secrets.ACR_DEV_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} -f Dockerfile . && \ |
| 77 | + docker push ${{ secrets.ACR_DEV_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} && \ |
| 78 | + echo "Dev/Demo/Hotfix Backend image built and pushed successfully." |
| 79 | + cd ../frontend |
| 80 | + docker build -t ${{ secrets.ACR_DEV_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} -f Dockerfile . && \ |
| 81 | + docker push ${{ secrets.ACR_DEV_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} && \ |
| 82 | + echo "Dev/Demo/Hotfix Frontend image built and pushed successfully." |
| 83 | + |
0 commit comments