From b5cbfb5689493981567ff3d7e0d7410bc96ee2a4 Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Thu, 3 Apr 2025 10:40:33 +0530 Subject: [PATCH 1/3] pipeline --- .github/workflows/build-docker-image.yml | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/build-docker-image.yml diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml new file mode 100644 index 00000000..b0b917ec --- /dev/null +++ b/.github/workflows/build-docker-image.yml @@ -0,0 +1,87 @@ +name: Build and Push Docker Images + +on: + push: + branches: [main, dev, demo, hotfix] + pull_request: + branches: [main, dev, demo, hotfix] + types: [opened, ready_for_review, reopened, synchronize] + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + env: + ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }} + ACR_USERNAME: ${{ secrets.ACR_USERNAME }} + ACR_PASSWORD: ${{ secrets.ACR_PASSWORD }} + + 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' }} + uses: azure/docker-login@v2 + with: + login-server: ${{ env.ACR_LOGIN_SERVER }} + username: ${{ env.ACR_USERNAME }} + password: ${{ env.ACR_PASSWORD }} + + - name: Set Docker image tag + run: | + echo "Determining tag for branch: ${{ github.ref }}" + 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 + else + echo "TAG=pullrequest-ignore" >> $GITHUB_ENV + fi + echo "Tag set to: $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}" + docker build -t ${IMAGE_NAME} -f .devcontainer/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 ContentProcessorAPI Docker image + run: | + cd src/ContentProcessorAPI + IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorapi:${TAG}" + echo "Using image name: ${IMAGE_NAME}" + docker build -t ${IMAGE_NAME} -f .devcontainer/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 ContentProcessorWeb Docker image + run: | + cd src/ContentProcessorWeb + IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorweb:${TAG}" + echo "Using image name: ${IMAGE_NAME}" + docker build -t ${IMAGE_NAME} -f .devcontainer/base.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 From 9095016f933a49a64218e6ec950cd43d5a2050bf Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Thu, 3 Apr 2025 11:52:30 +0530 Subject: [PATCH 2/3] pipeline new --- .github/workflows/build-docker-image.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index b0b917ec..6bfebd7d 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -23,6 +23,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + - name: Log in to Azure Container Registry if: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} uses: azure/docker-login@v2 @@ -31,19 +35,19 @@ jobs: username: ${{ env.ACR_USERNAME }} password: ${{ env.ACR_PASSWORD }} - - name: Set Docker image tag + - name: Set Docker image tag with Date run: | echo "Determining tag for branch: ${{ github.ref }}" if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then - echo "TAG=latest" >> $GITHUB_ENV + echo "TAG=latest-${{ steps.date.outputs.date }}" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then - echo "TAG=dev" >> $GITHUB_ENV + echo "TAG=dev-${{ steps.date.outputs.date }}" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then - echo "TAG=demo" >> $GITHUB_ENV + echo "TAG=demo-${{ steps.date.outputs.date }}" >> $GITHUB_ENV elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then - echo "TAG=hotfix" >> $GITHUB_ENV + echo "TAG=hotfix-${{ steps.date.outputs.date }}" >> $GITHUB_ENV else - echo "TAG=pullrequest-ignore" >> $GITHUB_ENV + echo "TAG=pullrequest-ignore-${{ steps.date.outputs.date }}" >> $GITHUB_ENV fi echo "Tag set to: $TAG" @@ -53,7 +57,7 @@ jobs: IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessor:${TAG}" echo "Using image name: ${IMAGE_NAME}" docker build -t ${IMAGE_NAME} -f .devcontainer/Dockerfile . - if [[ "${TAG}" == "latest" || "${TAG}" == "dev" || "${TAG}" == "demo" || "${TAG}" == "hotfix" ]]; then + if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then docker push ${IMAGE_NAME} echo "ContentProcessor image built and pushed successfully." else @@ -66,7 +70,7 @@ jobs: IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorapi:${TAG}" echo "Using image name: ${IMAGE_NAME}" docker build -t ${IMAGE_NAME} -f .devcontainer/Dockerfile . - if [[ "${TAG}" == "latest" || "${TAG}" == "dev" || "${TAG}" == "demo" || "${TAG}" == "hotfix" ]]; then + if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then docker push ${IMAGE_NAME} echo "ContentProcessorAPI image built and pushed successfully." else @@ -79,7 +83,7 @@ jobs: IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorweb:${TAG}" echo "Using image name: ${IMAGE_NAME}" docker build -t ${IMAGE_NAME} -f .devcontainer/base.Dockerfile . - if [[ "${TAG}" == "latest" || "${TAG}" == "dev" || "${TAG}" == "demo" || "${TAG}" == "hotfix" ]]; then + if [[ "${TAG}" == latest-* || "${TAG}" == dev-* || "${TAG}" == demo-* || "${TAG}" == hotfix-* ]]; then docker push ${IMAGE_NAME} echo "ContentProcessorWeb image built and pushed successfully." else From b0b243df18646e6a3127426ffae41d99c2352393 Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Thu, 3 Apr 2025 13:07:18 +0530 Subject: [PATCH 3/3] pipeline latest --- .github/workflows/build-docker-image.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 6bfebd7d..747e6d1e 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -56,7 +56,8 @@ jobs: cd src/ContentProcessor IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessor:${TAG}" echo "Using image name: ${IMAGE_NAME}" - docker build -t ${IMAGE_NAME} -f .devcontainer/Dockerfile . + # 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." @@ -69,7 +70,8 @@ jobs: cd src/ContentProcessorAPI IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorapi:${TAG}" echo "Using image name: ${IMAGE_NAME}" - docker build -t ${IMAGE_NAME} -f .devcontainer/Dockerfile . + # 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." @@ -82,7 +84,8 @@ jobs: cd src/ContentProcessorWeb IMAGE_NAME="$ACR_LOGIN_SERVER/contentprocessorweb:${TAG}" echo "Using image name: ${IMAGE_NAME}" - docker build -t ${IMAGE_NAME} -f .devcontainer/base.Dockerfile . + # 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."