dotnet-podcasts/.github/workflows/template-api.yml

87 lines
3.9 KiB
YAML
Raw Normal View History

2022-12-05 23:52:00 +08:00
on:
workflow_call:
inputs:
environment:
required: true
type: string
2022-12-06 00:53:23 +08:00
2022-12-05 23:52:00 +08:00
jobs:
2022-12-06 00:21:58 +08:00
buildPushDeploy:
2022-12-05 23:52:00 +08:00
environment:
2022-12-06 00:53:23 +08:00
name: ${{ inputs.environment }}
runs-on: ubuntu-latest
2022-12-05 23:52:00 +08:00
steps:
- uses: actions/checkout@v3
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
- name: Deploy ACR
uses: azure/powershell@v1
with:
2022-12-06 00:53:23 +08:00
azPSVersion: "3.1.0"
inlineScript: |
2023-02-12 05:34:44 +08:00
$deploymentName = 'ghactionbgtasks${{ github.sha }}'
2023-02-12 05:31:56 +08:00
$resourceGroupName = '${{ secrets.AZURE_RESOURCE_GROUP_NAME }}'
$acrName = '${{ secrets.ACR_NAME }}'
2023-02-12 05:13:29 +08:00
az deployment group create -n "$($deploymentName)" `
--resource-group "$($resourceGroupName)" `
--template-file deploy/Services/acr.bicep `
--parameters acrName="$($acrName)"
2023-02-12 05:18:44 +08:00
2022-12-05 23:52:00 +08:00
- name: Login to ACR
2022-12-06 01:39:26 +08:00
uses: docker/login-action@v1
2022-12-05 23:52:00 +08:00
with:
2022-12-06 01:39:26 +08:00
registry: ${{ secrets.ACR_NAME }}.azurecr.io
2022-12-05 23:52:00 +08:00
username: ${{ fromJson(secrets.AZURE_CREDENTIALS).clientId }}
password: ${{ fromJson(secrets.AZURE_CREDENTIALS).clientSecret }}
- uses: actions/setup-dotnet@v3
with:
2022-12-06 00:53:23 +08:00
dotnet-version: "7.0.x"
2022-12-05 23:52:00 +08:00
- name: Build Podcast Updater
2022-12-07 08:18:22 +08:00
run: dotnet publish -c Release -r linux-x64 /t:PublishContainer src/Services/Podcasts/Podcast.Updater.Worker/Podcast.Updater.Worker.csproj -p ContainerRegistry=${{ secrets.ACR_NAME }}.azurecr.io -p ContainerImageTag=${{ github.sha }}
2022-12-05 23:52:00 +08:00
- name: Build Podcast API
run: dotnet publish -c Release -r linux-x64 -p ContainerRegistry=${{ secrets.ACR_NAME }}.azurecr.io -p ContainerImageTag=${{ github.sha }} -p PublishProfile=DefaultContainer src/Services/Podcasts/Podcast.API/Podcast.API.csproj
2022-12-05 23:52:00 +08:00
- name: Build Podcast Ingestion
2022-12-07 08:18:22 +08:00
run: dotnet publish -c Release -r linux-x64 /t:PublishContainer src/Services/Podcasts/Podcast.Ingestion.Worker/Podcast.Ingestion.Worker.csproj -p ContainerRegistry=${{ secrets.ACR_NAME }}.azurecr.io -p ContainerImageTag=${{ github.sha }}
2022-12-05 23:52:00 +08:00
- name: Deploy Container Apps
uses: azure/powershell@v1
with:
2022-12-06 00:53:23 +08:00
azPSVersion: "3.1.0"
failOnStandardError: true
inlineScript: |
2023-02-12 05:31:56 +08:00
$deploymentName = 'ghaction${{ github.sha }}'
$resourceGroupName = '${{ secrets.AZURE_RESOURCE_GROUP_NAME }}'
$acrName = '${{ secrets.ACR_NAME }}'
$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 }}'
2023-02-12 04:07:15 +08:00
az deployment group create -n "$($deploymentName)" `
--resource-group "$($resourceGroupName)" `
2022-12-06 00:53:23 +08:00
--template-file deploy/Services/api.bicep `
2023-02-12 05:27:02 +08:00
--parameters acrName="$($acrName)" imageTag="$($imageTag)" administratorLogin="$($administratorLogin)" administratorLoginPassword="$($administratorLoginPassword)" storageAccountName="$($storageAccountName)" serverName="$($serverName)" kubernetesEnvName="$($kubernetesEnvName)" workspaceName="$($workspaceName)" apiName="$($apiName)" updaterName="$($updaterName)"
2022-12-06 00:53:23 +08:00
if( $LASTEXITCODE -ne 0 ) { exit -1 }
2022-12-05 23:52:00 +08:00
- name: Upload Images
uses: azure/powershell@v1
with:
2022-12-06 00:53:23 +08:00
azPSVersion: "3.1.0"
inlineScript: |
cd deploy/Images
./Deploy-Images.ps1 -resourceGroup ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} -storageName ${{ secrets.STORAGE_NAME }}