Skip to content

Commit d34fb1b

Browse files
feat: Implement Consistent Versioning and Tagging for Accelerator Images
1 parent d99342b commit d34fb1b

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111

1212
jobs:
1313
build-and-push:
14-
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
1514
runs-on: ubuntu-latest
1615

1716
steps:
@@ -37,26 +36,24 @@ jobs:
3736
username: ${{ secrets.ACR_DEV_USERNAME }}
3837
password: ${{ secrets.ACR_DEV_PASSWORD }}
3938

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 }}
39+
- name: Get current date
40+
id: date
41+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
5642

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

0 commit comments

Comments
 (0)