Skip to content

Commit f45fc8c

Browse files
Merge pull request #17 from microsoft/New-Pipeline
feat: Build & Push Docker Images with Dual Tagging
2 parents 1f30b32 + e09c9ef commit f45fc8c

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

.github/workflows/build-docker-image.yml

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,60 +35,53 @@ jobs:
3535
username: ${{ env.ACR_USERNAME }}
3636
password: ${{ env.ACR_PASSWORD }}
3737

38-
- name: Set Docker image tag with Date
38+
- name: Set Docker image tags
39+
id: tag
3940
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
41+
BRANCH="${{ github.ref_name }}"
42+
DATE="${{ steps.date.outputs.date }}"
43+
if [[ "$BRANCH" == "main" ]]; then
44+
BASE_TAG="latest"
45+
elif [[ "$BRANCH" == "dev" ]]; then
46+
BASE_TAG="dev"
47+
elif [[ "$BRANCH" == "demo" ]]; then
48+
BASE_TAG="demo"
49+
elif [[ "$BRANCH" == "hotfix" ]]; then
50+
BASE_TAG="hotfix"
4951
else
50-
echo "TAG=pullrequest-ignore-${{ steps.date.outputs.date }}" >> $GITHUB_ENV
52+
BASE_TAG="pullrequest-ignore"
5153
fi
52-
echo "Tag set to: $TAG"
54+
DATE_TAG="${BASE_TAG}-${DATE}"
55+
echo "BASE_TAG=${BASE_TAG}" >> $GITHUB_ENV
56+
echo "DATE_TAG=${DATE_TAG}" >> $GITHUB_ENV
57+
echo "Base tag: $BASE_TAG, Date tag: $DATE_TAG"
5358
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
59+
- name: Build and Push ContentProcessor Docker image
60+
uses: docker/build-push-action@v6
61+
with:
62+
context: ./src/ContentProcessor
63+
file: ./src/ContentProcessor/Dockerfile
64+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
65+
tags: |
66+
${{ env.ACR_LOGIN_SERVER }}/contentprocessor:${{ env.BASE_TAG }}
67+
${{ env.ACR_LOGIN_SERVER }}/contentprocessor:${{ env.DATE_TAG }}
6768
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
69+
- name: Build and Push ContentProcessorAPI Docker image
70+
uses: docker/build-push-action@v6
71+
with:
72+
context: ./src/ContentProcessorAPI
73+
file: ./src/ContentProcessorAPI/Dockerfile
74+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
75+
tags: |
76+
${{ env.ACR_LOGIN_SERVER }}/contentprocessorapi:${{ env.BASE_TAG }}
77+
${{ env.ACR_LOGIN_SERVER }}/contentprocessorapi:${{ env.DATE_TAG }}
8178
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
79+
- name: Build and Push ContentProcessorWeb Docker image
80+
uses: docker/build-push-action@v6
81+
with:
82+
context: ./src/ContentProcessorWeb
83+
file: ./src/ContentProcessorWeb/Dockerfile
84+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }}
85+
tags: |
86+
${{ env.ACR_LOGIN_SERVER }}/contentprocessorweb:${{ env.BASE_TAG }}
87+
${{ env.ACR_LOGIN_SERVER }}/contentprocessorweb:${{ env.DATE_TAG }}

0 commit comments

Comments
 (0)