Skip to content

Commit 0ec2443

Browse files
Merge pull request #196 from microsoft/PSL-US-12925
feat: Implement Consistent Versioning and Tagging for Accelerator Images
2 parents d99342b + b65de15 commit 0ec2443

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

.github/workflows/docker-build-and-push.yml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,24 @@ jobs:
3737
username: ${{ secrets.ACR_DEV_USERNAME }}
3838
password: ${{ secrets.ACR_DEV_PASSWORD }}
3939

40-
- name: Set Docker image tag
41-
id: docker_tag
42-
run: |
43-
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
44-
echo "TAG=latest" >> $GITHUB_ENV
45-
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
46-
echo "TAG=dev" >> $GITHUB_ENV
47-
elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then
48-
echo "TAG=demo" >> $GITHUB_ENV
49-
fi
50-
51-
- name: Build and push Docker image
52-
if: ${{ github.ref_name == 'main' }}
53-
run: |
54-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/webapp:${{ env.TAG }} -f WebApp.Dockerfile .
55-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/webapp:${{ env.TAG }}
40+
- name: Get current date
41+
id: date
42+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
5643

57-
- name: Build and push Docker image (Dev/Demo)
58-
if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' }}
59-
run: |
60-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/webapp:latest -f WebApp.Dockerfile .
61-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/webapp:latest
62-
44+
- name: Get registry
45+
id: registry
46+
run: echo "registry=${{ github.ref_name == 'main' && secrets.ACR_LOGIN_SERVER || secrets.ACR_DEV_LOGIN_SERVER }}" >> $GITHUB_OUTPUT
47+
48+
- name: Determine Tag Name Based on Branch
49+
id: determine_tag
50+
run: echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
51+
52+
- name: Build Docker Image and optionally push
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
file: WebApp.Dockerfile
57+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' }}
58+
tags: |
59+
${{ steps.registry.outputs.registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}
60+
${{ steps.registry.outputs.registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}

0 commit comments

Comments
 (0)