Skip to content

GitHub workflow for validating terraform deploy + upgrading charms #38

GitHub workflow for validating terraform deploy + upgrading charms

GitHub workflow for validating terraform deploy + upgrading charms #38

name: Terraform deploy to a fresh microk8s model
on:
pull_request:
branches:
- '**'
paths:
- 'frontend/charm/**'
- 'backend/charm/**'
- 'terraform/**'
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
sleep 10 # hack hack, the below wait-for condition is not actually correct, so let's wait a bit
- name: Replace the API charm with the locally built one
run: |
juju wait-for application api --timeout=10m --query='life=="alive"'
juju refresh api --path ../backend/charm/*.charm
- name: Replace the frontend charm with the locally built one
run: |
juju wait-for application frontend --timeout=10m --query='life=="alive"'
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")'
- name: Echo juju status on failure
if: failure()
run: |
juju status --color
- name: Run juju crashdump on failure
if: failure()
run: |
sudo juju crashdump -o ./ -m test-observer-development --as-root -a juju-show-unit -a juju-show-status-log -a juju-show-machine -a config
sudo chown $USER ./**/juju-crashdump-*.tar.xz
- name: Archive juju crashdump on failure
if: failure()
uses: actions/upload-artifact@v3
with:
name: juju-crashdump
path: ./**/juju-crashdump-*.tar.xz