felipementel is testing out Azure Container Apps GitHub Actions π #27
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: Container Apps CI/CD | |
run-name: ${{ github.actor }} is testing out Azure Container Apps GitHub Actions π | |
on: | |
push: | |
branches: | |
- main | |
- '!feature/**' | |
paths: | |
- 'src/AzureContainerApps/**' | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
type: choice | |
options: | |
- info | |
- warning | |
- debug | |
pull_request: | |
branches: | |
- main | |
- '!feature/**' | |
paths: | |
- 'src/AzureContainerApps/**' | |
env: | |
app_path: ./src/AzureContainerApps/DEPLOY.CarApp.API | |
app_root: ./src/AzureContainerApps | |
image_name: apim-car-api | |
resource_group: rg-apim-canal-deploy-apps-lab | |
app_name: ca-apim-car-app-lab | |
aca_env: cae-apim-canal-deploy-apps-lab | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: ['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/[email protected] | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Display dotnet version | |
run: dotnet --version | |
- name: Install dependencies | |
run: dotnet restore ${{ env.app_path }}/**.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/AzureContainerApps/DEPLOY.CarApp.API/DEPLOY.CarApp.API.csproj) | |
echo "tag=$version" >> "$GITHUB_OUTPUT" | |
- name: Build and push Docker image | |
run: | | |
docker buildx build -f ${{ env.app_path }}/Dockerfile -t ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} ${{ env.app_root }} | |
docker tag ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} ${{ github.actor }}/${{ env.image_name }}:latest | |
docker push ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} | |
docker push ${{ github.actor }}/${{ env.image_name }}: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 Container App | |
uses: azure/container-apps-deploy-action@v2 | |
with: | |
containerAppName: ${{ env.app_name }} | |
containerAppEnvironment: ${{ env.aca_env }} | |
registryUrl: docker.io | |
imageToDeploy: docker.io/${{ github.actor }}/${{ env.image_name }}:${{ needs.build.outputs.imageTag }} | |
resourceGroup: ${{ env.resource_group }} | |
targetPort: 8080 | |
location: brazilsouth | |
environmentVariables: | | |
ASPNETCORE_ENVIRONMENT=Development | |
- name: Log out from Azure | |
run: | | |
az logout |