Fixes #15: Add Azure build and push to ACR workflow #12
This file contains 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: Docker Azure deployment | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Login to Azure Container Registry (ACR). | |
- name: Login to ACR | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ secrets.ACR_REGISTRY_NAME }} | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
# Checkout the current repository. | |
- uses: actions/checkout@v3 | |
# Setup Docker Buildx for advanced build features. | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
# Cache Docker layers to improve build speed. | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-${{ github.event.repository.name }}-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-${{ github.event.repository.name }} | |
# Build and push the Docker image with the specified tag. | |
- name: Build and push the Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.ACR_REGISTRY_NAME }}/${{ github.event.repository.name }}:${{ github.sha }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
# Cleanup and move cache for future builds. | |
- name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v2 | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Azure Docker Login | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.AZURE_CONTAINER_REGISTRY }} | |
username: ${{ secrets.AZURE_REGISTRY_USERNAME }} | |
password: ${{ secrets.AZURE_REGISTRY_PASSWORD }} | |
- name: Build and push Docker image | |
run: | | |
docker build -t ${{ secrets.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ github.sha }} . | |
docker push ${{ secrets.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ github.sha }} | |
- name: Deploy to Azure App Service | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ github.event.repository.name }} | |
slot-name: production | |
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }} | |
images: ${{ secrets.AZURE_CONTAINER_REGISTRY }}/${{ github.event.repository.name }}:${{ github.sha }} |