Build and push the latest build to staging #23
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: Build and push the latest build to staging | |
# This workflow will build a docker container, publish it to Azure Container Registry, and deploy it to Azure Kubernetes Service. | |
# | |
on: | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 7.0.x | |
- name: Restore dependencies | |
working-directory: ./API/ | |
run: dotnet restore | |
- name: Build | |
working-directory: ./API/ | |
run: dotnet build --no-restore | |
docker: | |
name: Docker Build & Push to ACR | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- uses: Azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Connect to Azure Container registry (ACR) | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.ACR_LOGIN }} | |
username: ${{ secrets.ACR_NAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- uses: Azure/get-keyvault-secrets@v1 | |
with: | |
keyvault: "api-template" | |
secrets: 'SqlServerStaging' | |
id: azKeyVaultSecretAction | |
- name: Replace token for appsettings.Production.json | |
uses: cschleiden/replace-tokens@v1.1 | |
with: | |
files: '["src/rest-api-template/appsettings.json"]' | |
env: | |
SqlServer: ${{ steps.azKeyVaultSecretAction.outputs.SqlServerStaging }} | |
- name: Build Image without DockerFile using Microsoft.NET.Build.Containers | |
working-directory: ./API/ | |
run: dotnet publish --os linux --arch x64 -c Release -p:ContainerImageName=${{ secrets.ACR_LOGIN }}/api-template-image | |
- name: Push Image | |
run: docker push ${{ secrets.ACR_LOGIN }}/api-template-image --all-tags |