dotnet-podcasts/.github/workflows/podcast-api-pr.yml

116 lines
4.6 KiB
YAML
Raw Normal View History

2022-12-01 00:07:38 +08:00
name: Podcast API CICD - Staging
on:
pull_request:
branches: [ main ]
paths:
- 'src/Services/Podcasts/**'
- 'deploy/Services/api.bicep'
2022-12-01 00:44:40 +08:00
- '.github/workflows/podcast-api-pr.yml'
2022-12-01 00:07:38 +08:00
workflow_dispatch:
jobs:
build-pr:
if: ${{ github.event_name == 'pull_request'}}
2022-12-01 00:39:10 +08:00
environment:
name: staging
2022-12-01 00:07:38 +08:00
runs-on: ubuntu-latest
2022-12-01 07:05:06 +08:00
env:
# all built containers have the same tag
ContainerImageTag: "${{ github.sha }}"
2022-12-01 00:07:38 +08:00
steps:
- uses: actions/checkout@v2
- name: Build Podcast Updater
2022-12-01 07:05:06 +08:00
run: dotnet publish -c Release -r linux-x64 /t:PublishContainer src/Services/Podcasts/Podcast.Updater.Worker/Podcast.Updater.Worker.csproj
2022-12-01 00:07:38 +08:00
- name: Build Podcast API
2022-12-01 07:05:06 +08:00
run: dotnet publish -c Release -r linux-x64 -p PublishProfile=DefaultContainer src/Services/Podcasts/Podcast.API/Podcast.API.csproj
2022-12-01 00:07:38 +08:00
- name: Build Podcast Ingestion
2022-12-01 07:05:06 +08:00
run: dotnet publish -c Release -r linux-x64 /t:PublishContainer src/Services/Podcasts/Podcast.Ingestion.Worker/Podcast.Ingestion.Worker.csproj
2022-12-01 00:07:38 +08:00
build-and-push:
2022-12-01 00:39:10 +08:00
environment:
name: staging
2022-12-01 00:07:38 +08:00
runs-on: ubuntu-latest
2022-12-01 07:05:06 +08:00
env:
# all containers have the same parent registry
ContainerRegistry: "${{ secrets.ACR_NAME }}.azurecr.io"
# all built containers have the same tag
ContainerImageTag: "${{ github.sha }}"
2022-12-01 00:07:38 +08:00
steps:
- uses: actions/checkout@v2
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Deploy ACR
uses: azure/powershell@v1
with:
azPSVersion: '3.1.0'
inlineScript: |
2022-12-01 04:08:21 +08:00
az deployment group create -n ghactionbgtasks${{ github.sha }} -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --template-file deploy/Services/acr.bicep --parameters acrName=${{secrets.ACR_NAME}}
2022-12-01 00:07:38 +08:00
- name: Login to ACR
uses: docker/login-action@v1
with:
2022-12-01 04:08:21 +08:00
registry: ${{ secrets.ACR_NAME }}.azurecr.io
2022-12-01 00:07:38 +08:00
username: ${{ fromJson(secrets.AZURE_CREDENTIALS).clientId }}
password: ${{ fromJson(secrets.AZURE_CREDENTIALS).clientSecret }}
2022-12-01 07:05:06 +08:00
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
2022-12-01 00:07:38 +08:00
- name: Build Podcast Updater
2022-12-01 07:05:06 +08:00
run: dotnet publish -c Release -r linux-x64 /t:PublishContainer src/Services/Podcasts/Podcast.Updater.Worker/Podcast.Updater.Worker.csproj
2022-12-01 00:07:38 +08:00
- name: Build Podcast API
2022-12-01 07:05:06 +08:00
run: dotnet publish -c Release -r linux-x64 -p ContainerImageTag=${{ github.sha }} -p PublishProfile=DefaultContainer src/Services/Podcasts/Podcast.API/Podcast.API.csproj
2022-12-01 00:07:38 +08:00
- name: Build Podcast Ingestion
2022-12-01 07:05:06 +08:00
run: dotnet publish -c Release -r linux-x64 /t:PublishContainer src/Services/Podcasts/Podcast.Ingestion.Worker/Podcast.Ingestion.Worker.csproj
2022-12-01 00:07:38 +08:00
deploy:
needs: build-and-push
environment:
2022-12-01 00:39:10 +08:00
name: staging
2022-12-01 00:07:38 +08:00
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Deploy Container Apps
uses: azure/powershell@v1
with:
azPSVersion: '3.1.0'
failOnStandardError: true
inlineScript: |
2022-12-01 04:08:21 +08:00
$ACR_LOGIN_SERVER="${{secrets.ACR_NAME}}.azurecr.io"
$ACR_PASSWORD=$(az acr credential show -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} -n ${{secrets.ACR_NAME}} -o tsv --query passwords[0].value)
2022-12-01 00:07:38 +08:00
az deployment group create -n ghaction${{ github.sha }} `
--resource-group ${{secrets.AZURE_RESOURCE_GROUP_NAME}} `
--template-file deploy/Services/api.bicep `
2022-12-01 05:30:25 +08:00
--parameters acrPassword=$ACR_PASSWORD acrLogin=${{secrets.ACR_NAME}} acrLoginServer=$ACR_LOGIN_SERVER imageTag=${{ github.sha }} administratorLogin=${{secrets.PODCASTDB_USER_LOGIN}} administratorLoginPassword=${{secrets.PODCASTDB_USER_PASSWORD}} storageAccountName=${{ secrets.STORAGE_NAME }} serverName=${{secrets.PODCASTDB_SERVER_NAME}} kubernetesEnvName=${{secrets.KUBERNETES_ENV_NAME}} workspaceName=${{secrets.WORKSPACE_NAME}} apiName=${{secrets.API_RESOURCE_NAME}} updaterName=${{secrets.UPDATER_RESOURCE_NAME}}
2022-12-01 00:07:38 +08:00
if( $LASTEXITCODE -ne 0 ) { exit -1 }
- name: Upload Images
uses: azure/powershell@v1
with:
azPSVersion: '3.1.0'
inlineScript: |
cd deploy/Images
2022-12-01 04:08:21 +08:00
./Deploy-Images.ps1 -resourceGroup ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} -storageName ${{ secrets.STORAGE_NAME }}