Merge pull request #412 from microsoft/refactor/bicep-use-abbreviations #375
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker and Optional Push | |
on: | |
push: | |
branches: [main, dev, demo] | |
pull_request: | |
branches: [main, dev, demo] | |
types: | |
- opened | |
- ready_for_review | |
- reopened | |
- synchronize | |
merge_group: | |
workflow_dispatch: | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
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 - External Registry | |
if: ${{ github.ref_name == 'main' }} | |
uses: azure/docker-login@v2 | |
with: | |
login-server: ${{ secrets.ACR_LOGIN_SERVER }} | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- name: Log in to Azure Container Registry (Main/Dev/Demo/Dependabotchanges) - Internal Registry | |
if: ${{ github.ref_name == 'main' ||github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'dependabotchanges' }} | |
uses: azure/docker-login@v2 | |
with: | |
login-server: ${{ secrets.ACR_DEV_LOGIN_SERVER }} | |
username: ${{ secrets.ACR_DEV_USERNAME }} | |
password: ${{ secrets.ACR_DEV_PASSWORD }} | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
- name: Get registry | |
id: registry | |
run: | | |
if [[ "${{ github.ref_name }}" == "main" ]]; then | |
echo "ext_registry=${{ secrets.ACR_LOGIN_SERVER }}" >> $GITHUB_OUTPUT | |
echo "int_registry=${{ secrets.ACR_DEV_LOGIN_SERVER }}" >> $GITHUB_OUTPUT | |
else | |
echo "int_registry=${{ secrets.ACR_DEV_LOGIN_SERVER }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Determine Tag Name Based on Branch | |
id: determine_tag | |
run: | | |
if [[ "${{ github.ref_name }}" == "main" ]]; then | |
echo "tagname=latest" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref_name }}" == "dev" ]]; then | |
echo "tagname=dev" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref_name }}" == "demo" ]]; then | |
echo "tagname=demo" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref_name }}" == "dependabotchanges" ]]; then | |
echo "tagname=dependabotchanges" >> $GITHUB_OUTPUT | |
else | |
echo "tagname=default" >> $GITHUB_OUTPUT | |
fi | |
- name: Build Docker Image and optionally push - Internal Registry | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./src | |
file: ./src/WebApp.Dockerfile | |
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'dependabotchanges' }} | |
tags: | | |
${{ steps.registry.outputs.int_registry }}/webapp:${{ steps.determine_tag.outputs.tagname }} | |
${{ steps.registry.outputs.int_registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }} | |
- name: Build Docker Image and optionally push - External Registry | |
if: ${{ github.ref_name == 'main' }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./src | |
file: ./src/WebApp.Dockerfile | |
push: ${{github.ref_name == 'main' }} | |
tags: | | |
${{ steps.registry.outputs.ext_registry }}/webapp:${{ steps.determine_tag.outputs.tagname }} | |
${{ steps.registry.outputs.ext_registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }} | |