Skip to content

GitHub workflow for validating terraform deploy + upgrading charms #26

GitHub workflow for validating terraform deploy + upgrading charms

GitHub workflow for validating terraform deploy + upgrading charms #26

name: Terraform deploy to a fresh microk8s model
on:
pull_request:
branches:
- '**'
paths:
- 'frontend/charm/**'
- 'backend/charm/**'
pull_request_review:
on:
pull_request_review:
types:
- submitted
paths:
- 'frontend/charm/**'
- 'backend/charm/**'
- 'terraform/**'
push:
branches: ["main"]
tags: ["v*.*.*"]
workflow_dispatch:
jobs:
deploy:
name: terraform deploy + upgrade charms
if: github.event.review.state == 'APPROVED'
runs-on: [self-hosted, jammy, xlarge]
defaults:
run:
working-directory: ./terraform
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Terraform dependencies
run: |
sudo apt-get update
sudo apt-get install unzip
- name: Set up terraform
uses: hashicorp/setup-terraform@v1
- name: Terraform init
run: terraform init
- name: Set up microk8s
uses: canonical/certification-github-workflows/.github/actions/microk8s-setup@main
# TODO: Separate this build step to its own action once custom VM images are available
# (when there is a charmcraft + LXD capable image available)
- name: Build API charm
run: charmcraft pack
working-directory: ./backend/charm
# TODO: Separate this build step to its own action once custom VM images are available
# (when there is a charmcraft + LXD capable image available)
- name: Build frontend charm
run: charmcraft pack
working-directory: ./frontend/charm
- name: Terraform apply
run: |
TF_VAR_environment=development \
TF_VAR_nginx_ingress_integrator_charm_whitelist_source_range="" \
terraform apply -auto-approve
- name: Switch model to test-observer-development
run: |
juju switch test-observer-development
- name: Replace the API charm with the locally built one
run: |
juju refresh api --path ../backend/charm/*.charm
- name: Replace the frontend charm with the locally built one
run: |
juju refresh frontend --path ../frontend/charm/*.charm
- name: Wait for deployment to complete
run: |
juju wait-for model test-observer-development \
--timeout=10m \
--query='life=="alive" && status=="available" && forEach(applications, app => app.status == "active")'