felipementel is testing out Azure Web App GitHub Actions π #20
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: Web App CI/CD | |
run-name: ${{ github.actor }} is testing out Azure Web App GitHub Actions π | |
on: | |
push: | |
branches: | |
- main | |
- '!feature/**' | |
paths: | |
- 'src/AzureWebApp/**' | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
type: choice | |
options: | |
- info | |
- warning | |
- debug | |
pull_request: | |
branches: | |
- main | |
- '!feature/**' | |
paths: | |
- 'src/AzureWebApp/**' | |
env: | |
imageName: apim-food-app | |
jobs: | |
build: | |
environment: lab | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: ['7.0.x', '8.0.x'] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: false | |
outputs: | |
imageTag: ${{ steps.get-version.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup dotnet ${{ matrix.dotnet-version }} | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Display dotnet version | |
run: dotnet --version | |
- name: Install dependencies | |
run: dotnet restore src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj | |
- name: Build and push Docker image | |
uses: docker/[email protected] | |
with: | |
registry: docker.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: Get-Version from csproj | |
id: get-version | |
shell: bash | |
run: | | |
version=$(sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p' ./src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj) | |
echo "tag=$version" >> "$GITHUB_OUTPUT" | |
- name: Build and push Docker image | |
run: | | |
docker buildx build -f ./src/AzureWebApp/DEPLOY.FoodApp.API/Dockerfile -t ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} ./src/AzureWebApp | |
docker tag ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} ${{ github.actor }}/${{ env.imageName }}:latest | |
docker push ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} | |
docker push ${{ github.actor }}/${{ env.imageName }}:latest | |
deploy: | |
if: ${{ github.event_name != 'pull_request' }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Log in to Azure | |
uses: azure/[email protected] | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Deploy to Azure Web App | |
uses: azure/webapps-deploy@v3 | |
with: | |
app-name: app-apim-food-app-lab | |
publish-profile: ${{ secrets.WEBAPP_PUBLISH_PROFILE }} | |
images: ${{ github.actor }}/${{ env.imageName }}:${{ needs.build.outputs.imageTag }} | |
- name: Set Web App ACR authentication | |
uses: Azure/appservice-settings@v1 | |
with: | |
app-name: app-apim-food-app-lab | |
app-settings-json: | | |
[ | |
{ | |
"name": "ASPNETCORE_ENVIRONMENT", | |
"value": "Development", | |
"slotSetting": false | |
} | |
] | |
- name: Log out from Azure | |
run: | | |
az logout |