|
| 1 | +name: Build and Push Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, dev, demo, hotfix] |
| 6 | + pull_request: |
| 7 | + branches: [main, dev, demo, hotfix] |
| 8 | + types: [opened, ready_for_review, reopened, synchronize] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-push: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + env: |
| 15 | + ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} |
| 16 | + ACR_USERNAME: ${{ secrets.ACR_USERNAME }} |
| 17 | + ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v2 |
| 22 | + |
| 23 | + - name: Set up Docker Buildx |
| 24 | + uses: docker/setup-buildx-action@v1 |
| 25 | + |
| 26 | + - name: Get current date |
| 27 | + id: date |
| 28 | + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT |
| 29 | + |
| 30 | + - name: Log in to Azure Container Registry |
| 31 | + if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} |
| 32 | + uses: azure/docker-login@v2 |
| 33 | + with: |
| 34 | + login-server: ${{ env.ACR_LOGIN_SERVER }} |
| 35 | + username: ${{ env.ACR_USERNAME }} |
| 36 | + password: ${{ env.ACR_PASSWORD }} |
| 37 | + |
| 38 | + - name: Set Docker image tag with Date |
| 39 | + run: | |
| 40 | + echo "Determining tag for branch: ${{ github.ref }}" |
| 41 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 42 | + echo "TAG=latest-${{ steps.date.outputs.date }}" >> $GITHUB_ENV |
| 43 | + elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then |
| 44 | + echo "TAG=dev-${{ steps.date.outputs.date }}" >> $GITHUB_ENV |
| 45 | + elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then |
| 46 | + echo "TAG=demo-${{ steps.date.outputs.date }}" >> $GITHUB_ENV |
| 47 | + elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then |
| 48 | + echo "TAG=hotfix-${{ steps.date.outputs.date }}" >> $GITHUB_ENV |
| 49 | + else |
| 50 | + echo "TAG=pullrequest-ignore-${{ steps.date.outputs.date }}" >> $GITHUB_ENV |
| 51 | + fi |
| 52 | + echo "Tag set to: $TAG" |
| 53 | +
|
| 54 | + - name: Build and push ContentProcessor Docker image |
| 55 | + run: | |
| 56 | + cd src/ContentProcessor |
| 57 | + IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessor:${TAG}" |
| 58 | + echo "Using image name: ${IMAGE_NAME}" |
| 59 | + # Use the Dockerfile from the root folder of ContentProcessor |
| 60 | + docker build -t ${IMAGE_NAME} -f Dockerfile . |
| 61 | + if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then |
| 62 | + docker push ${IMAGE_NAME} |
| 63 | + echo "ContentProcessor image built and pushed successfully." |
| 64 | + else |
| 65 | + echo "Skipping Docker push for ContentProcessor with tag: ${TAG}" |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Build and push ContentProcessorAPI Docker image |
| 69 | + run: | |
| 70 | + cd src/ContentProcessorAPI |
| 71 | + IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorapi:${TAG}" |
| 72 | + echo "Using image name: ${IMAGE_NAME}" |
| 73 | + # Use the Dockerfile from the root folder of ContentProcessorAPI |
| 74 | + docker build -t ${IMAGE_NAME} -f Dockerfile . |
| 75 | + if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then |
| 76 | + docker push ${IMAGE_NAME} |
| 77 | + echo "ContentProcessorAPI image built and pushed successfully." |
| 78 | + else |
| 79 | + echo "Skipping Docker push for ContentProcessorAPI with tag: ${TAG}" |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Build and push ContentProcessorWeb Docker image |
| 83 | + run: | |
| 84 | + cd src/ContentProcessorWeb |
| 85 | + IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorweb:${TAG}" |
| 86 | + echo "Using image name: ${IMAGE_NAME}" |
| 87 | + # Use the Dockerfile from the root folder of ContentProcessorWeb |
| 88 | + docker build -t ${IMAGE_NAME} -f Dockerfile . |
| 89 | + if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then |
| 90 | + docker push ${IMAGE_NAME} |
| 91 | + echo "ContentProcessorWeb image built and pushed successfully." |
| 92 | + else |
| 93 | + echo "Skipping Docker push for ContentProcessorWeb with tag: ${TAG}" |
| 94 | + fi |
0 commit comments