113 lines
4.7 KiB
YAML
113 lines
4.7 KiB
YAML
name: Podcast API CICD
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
paths:
|
|
- 'src/Services/Podcasts/**'
|
|
- 'deploy/Services/api.deployment.json'
|
|
- '.github/workflows/podcast-api.yml'
|
|
pull_request:
|
|
branches: [ main ]
|
|
paths:
|
|
- 'src/Services/Podcasts/**'
|
|
- '.github/workflows/podcast-api.yml'
|
|
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
|
|
build-pr:
|
|
if: ${{ github.event_name == 'pull_request'}}
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
|
|
- name: Build Podcast Updater
|
|
run: docker build -f ./src/Services/Podcasts/Podcast.Updater.Worker/Dockerfile -t ${{ secrets.ACR_NAME }}.azurecr.io/podcastupdaterworker:${{ github.sha }} .
|
|
|
|
- name: Build Podcast API
|
|
run: docker build -f ./src/Services/Podcasts/Podcast.API/Dockerfile -t ${{ secrets.ACR_NAME }}.azurecr.io/podcastapi:${{ github.sha }} .
|
|
|
|
- name: Build Podcast Ingestion
|
|
run: docker build -f ./src/Services/Podcasts/Podcast.Ingestion.Worker/Dockerfile -t ${{ secrets.ACR_NAME }}.azurecr.io/podcastingestionworker:${{ github.sha }} .
|
|
|
|
build-and-push:
|
|
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.merged == true) }}
|
|
runs-on: ubuntu-latest
|
|
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: |
|
|
az deployment group create -n ghactionbgtasks${{ github.sha }} -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --template-file deploy/Services/acr.deployment.json --parameters acrName=${{secrets.ACR_NAME}}
|
|
|
|
- name: Login to ACR
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ${{ secrets.ACR_NAME }}.azurecr.io
|
|
username: ${{ fromJson(secrets.AZURE_CREDENTIALS).clientId }}
|
|
password: ${{ fromJson(secrets.AZURE_CREDENTIALS).clientSecret }}
|
|
|
|
- name: Build Podcast Updater
|
|
run: |
|
|
docker build -f ./src/Services/Podcasts/Podcast.Updater.Worker/Dockerfile -t ${{ secrets.ACR_NAME }}.azurecr.io/podcastupdaterworker:${{ github.sha }} .
|
|
docker push ${{ secrets.ACR_NAME }}.azurecr.io/podcastupdaterworker:${{ github.sha }}
|
|
|
|
- name: Build Podcast API
|
|
run: |
|
|
docker build -f ./src/Services/Podcasts/Podcast.API/Dockerfile -t ${{ secrets.ACR_NAME }}.azurecr.io/podcastapi:${{ github.sha }} .
|
|
docker push ${{ secrets.ACR_NAME }}.azurecr.io/podcastapi:${{ github.sha }}
|
|
|
|
- name: Build Podcast Ingestion
|
|
run: |
|
|
docker build -f ./src/Services/Podcasts/Podcast.Ingestion.Worker/Dockerfile -t ${{ secrets.ACR_NAME }}.azurecr.io/podcastingestionworker:${{ github.sha }} .
|
|
docker push ${{ secrets.ACR_NAME }}.azurecr.io/podcastingestionworker:${{ github.sha }}
|
|
|
|
deploy:
|
|
needs: build-and-push
|
|
environment:
|
|
name: prod
|
|
if: ${{ github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.merged == true) }}
|
|
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: |
|
|
$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)
|
|
|
|
az deployment group create -n ghaction${{ github.sha }} `
|
|
--resource-group ${{secrets.AZURE_RESOURCE_GROUP_NAME}} `
|
|
--template-file deploy/Services/api.deployment.json `
|
|
--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}}
|
|
|
|
if( $LASTEXITCODE -ne 0 ) { exit -1 }
|
|
|
|
- name: Upload Images
|
|
uses: azure/powershell@v1
|
|
with:
|
|
azPSVersion: '3.1.0'
|
|
inlineScript: |
|
|
cd deploy/Images
|
|
./Deploy-Images.ps1 -resourceGroup ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} -storageName ${{ secrets.STORAGE_NAME }}
|