diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 747e6d1e..23b8355c 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -35,60 +35,53 @@ jobs: username: ${{ env.ACR_USERNAME }} password: ${{ env.ACR_PASSWORD }} - - name: Set Docker image tag with Date + - name: Set Docker image tags + id: tag run: | - echo "Determining tag for branch: ${{ github.ref }}" - if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then - echo "TAG=latest-${{ steps.date.outputs.date }}" >> $GITHUB_ENV - elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then - echo "TAG=dev-${{ steps.date.outputs.date }}" >> $GITHUB_ENV - elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then - echo "TAG=demo-${{ steps.date.outputs.date }}" >> $GITHUB_ENV - elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then - echo "TAG=hotfix-${{ steps.date.outputs.date }}" >> $GITHUB_ENV + BRANCH="${{ github.ref_name }}" + DATE="${{ steps.date.outputs.date }}" + if [[ "$BRANCH" == "main" ]]; then + BASE_TAG="latest" + elif [[ "$BRANCH" == "dev" ]]; then + BASE_TAG="dev" + elif [[ "$BRANCH" == "demo" ]]; then + BASE_TAG="demo" + elif [[ "$BRANCH" == "hotfix" ]]; then + BASE_TAG="hotfix" else - echo "TAG=pullrequest-ignore-${{ steps.date.outputs.date }}" >> $GITHUB_ENV + BASE_TAG="pullrequest-ignore" fi - echo "Tag set to: $TAG" + DATE_TAG="${BASE_TAG}-${DATE}" + echo "BASE_TAG=${BASE_TAG}" >> $GITHUB_ENV + echo "DATE_TAG=${DATE_TAG}" >> $GITHUB_ENV + echo "Base tag: $BASE_TAG, Date tag: $DATE_TAG" - - name: Build and push ContentProcessor Docker image - run: | - cd src/ContentProcessor - IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessor:${TAG}" - echo "Using image name: ${IMAGE_NAME}" - # Use the Dockerfile from the root folder of ContentProcessor - docker build -t ${IMAGE_NAME} -f Dockerfile . - if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then - docker push ${IMAGE_NAME} - echo "ContentProcessor image built and pushed successfully." - else - echo "Skipping Docker push for ContentProcessor with tag: ${TAG}" - fi + - name: Build and Push ContentProcessor Docker image + uses: docker/build-push-action@v6 + with: + context: ./src/ContentProcessor + file: ./src/ContentProcessor/Dockerfile + push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} + tags: | + ${{ env.ACR_LOGIN_SERVER }}/contentprocessor:${{ env.BASE_TAG }} + ${{ env.ACR_LOGIN_SERVER }}/contentprocessor:${{ env.DATE_TAG }} - - name: Build and push ContentProcessorAPI Docker image - run: | - cd src/ContentProcessorAPI - IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorapi:${TAG}" - echo "Using image name: ${IMAGE_NAME}" - # Use the Dockerfile from the root folder of ContentProcessorAPI - docker build -t ${IMAGE_NAME} -f Dockerfile . - if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then - docker push ${IMAGE_NAME} - echo "ContentProcessorAPI image built and pushed successfully." - else - echo "Skipping Docker push for ContentProcessorAPI with tag: ${TAG}" - fi + - name: Build and Push ContentProcessorAPI Docker image + uses: docker/build-push-action@v6 + with: + context: ./src/ContentProcessorAPI + file: ./src/ContentProcessorAPI/Dockerfile + push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} + tags: | + ${{ env.ACR_LOGIN_SERVER }}/contentprocessorapi:${{ env.BASE_TAG }} + ${{ env.ACR_LOGIN_SERVER }}/contentprocessorapi:${{ env.DATE_TAG }} - - name: Build and push ContentProcessorWeb Docker image - run: | - cd src/ContentProcessorWeb - IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorweb:${TAG}" - echo "Using image name: ${IMAGE_NAME}" - # Use the Dockerfile from the root folder of ContentProcessorWeb - docker build -t ${IMAGE_NAME} -f Dockerfile . - if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then - docker push ${IMAGE_NAME} - echo "ContentProcessorWeb image built and pushed successfully." - else - echo "Skipping Docker push for ContentProcessorWeb with tag: ${TAG}" - fi + - name: Build and Push ContentProcessorWeb Docker image + uses: docker/build-push-action@v6 + with: + context: ./src/ContentProcessorWeb + file: ./src/ContentProcessorWeb/Dockerfile + push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} + tags: | + ${{ env.ACR_LOGIN_SERVER }}/contentprocessorweb:${{ env.BASE_TAG }} + ${{ env.ACR_LOGIN_SERVER }}/contentprocessorweb:${{ env.DATE_TAG }}