Skip to content

Terra Python CI/CD

Terra Python CI/CD #25

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Terra Python CI/CD
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to registry
uses: docker/login-action@v1
with:
registry: https://istatcosmo.azurecr.io/
username: ${{ secrets.AzureAppService_ContainerUsername }}
password: ${{ secrets.AzureAppService_ContainerPassword }}
- name: Build and push container image to registry
uses: docker/build-push-action@v2
with:
push: true
tags: istatcosmo.azurecr.io/cosmo-python-service:2.0.${{ github.run_number }},istatcosmo.azurecr.io/cosmo-python-service:latest
context: ./terra-backend/python-server/
build-args: "DOCKER_TAG=2.0.${{ github.run_number }}"
deploy-dev:
runs-on: ubuntu-latest
needs: build
environment:
name: 'development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'istat-cosmo-python'
slot-name: 'dev'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_PYTHONSERVICE }}
images: 'istatcosmo.azurecr.io/cosmo-python-service:2.0.${{ github.run_number }}'
deploy:
if: ${{ github.ref_name == 'main' }}
runs-on: ubuntu-latest
needs: [build, deploy-dev]
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'istat-cosmo-python'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_PYTHONSERVICE }}
images: 'istatcosmo.azurecr.io/cosmo-python-service:2.0.${{ github.run_number }}'
#deployaca:
# runs-on: ubuntu-latest
# needs: build
# environment:
# name: 'development-aca'
#
# steps:
# - name: Azure Login
# uses: Azure/login@v1.4.3
# with:
# client-id: ${{ secrets.AZ_CLIENT_ID }}
# tenant-id: ${{ secrets.AZ_TENANT_ID }}
# subscription-id: ${{ secrets.AZ_SUBSCRIPTION_ID }}
#
# - name: Deploy Container App
# shell: pwsh
# env:
# CONTAINERAPP_NAME: ${{ vars.PYTHON_CONTAINERAPP_NAME }}
# CONTAINERAPP_RG: ${{ vars.TERRA_RG }}
# run: |
# az containerapp update --image 'istatcosmo.azurecr.io/cosmo-python-service:run-${{ github.run_number }}' -n $env:CONTAINERAPP_NAME -g $env:CONTAINERAPP_RG