Skip to content

test: Ut 10888 backend #68

test: Ut 10888 backend

test: Ut 10888 backend #68

name: Build and Push Docker Image
on:
push:
branches:
- main
- dev
- demo
- hotfix
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: ${{ inputs.push == true && (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 }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Set Docker image tag
run: |
if [[ "${{ github.head.ref }}" == "main" ]]; then
echo "TAG=latest" >> $GITHUB_ENV
elif [[ "${{ github.head.ref }}" == "dev" ]]; then
echo "TAG=dev" >> $GITHUB_ENV
elif [[ "${{ github.head.ref }}" == "demo" ]]; then
echo "TAG=demo" >> $GITHUB_ENV
elif [[ "${{ github.head.ref }}" == "hotfix" ]]; then
echo "TAG=hotfix" >> $GITHUB_ENV
else
echo "TAG=pullrequest-ignore" >> $GITHUB_ENV
fi
- 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 push ${{ secrets.ACR_LOGIN_SERVER }}/macaebackend:${{ env.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 push ${{ secrets.ACR_LOGIN_SERVER }}/macaefrontend:${{ env.TAG }} && \
echo "Frontend image built and pushed successfully."
else
echo "Skipping Docker push for frontend with tag: ${{ env.TAG }}"
fi