Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub workflow for validating terraform deploy + upgrading charms #81

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0b4b3b9
Adds a workflow for doing a terraform deploy
mz2 Dec 12, 2023
58fe669
Tweaks to trigger conditions of the terraform_test_deploy workflow
mz2 Dec 12, 2023
a5bca3d
Loosens up the filter conditions
mz2 Dec 12, 2023
24b4078
Install terraform dependency: unzip
mz2 Dec 12, 2023
e787914
Remove redundant terraform apply
mz2 Dec 12, 2023
bb49570
min => m as unit
mz2 Dec 12, 2023
0c0ccf8
Updates trigger conditions for tests, adds manual dispatching around
mz2 Dec 12, 2023
1a33fa2
Updates to the new charm format, updates charm libraries, removes sta…
mz2 Dec 12, 2023
2558fed
Merge branch 'main' of github.com:canonical/test_observer into terraf…
mz2 Dec 12, 2023
567d6b3
Charm now happily works with multiple units
mz2 Dec 12, 2023
d154e5c
Drops some stray whitespaces
mz2 Dec 12, 2023
22f8fb1
Removes an accidentally added, redundant .dockerignore
mz2 Dec 12, 2023
a23cf00
Drops the template for vscode-settings-default.json
mz2 Dec 12, 2023
487370c
Removes the bit in the README about copying in the vscode settings in…
mz2 Dec 12, 2023
762d37a
Build the charm locally, upgrade to it
mz2 Dec 12, 2023
b1392f2
Adjusted triggers
mz2 Dec 12, 2023
600770c
Adjusted triggers once again
mz2 Dec 12, 2023
cddd434
Adjusted triggers once again
mz2 Dec 12, 2023
79d33e6
Remove the dependency for now
mz2 Dec 12, 2023
96ab78b
Adds a type hint back to faults.py
mz2 Dec 12, 2023
e42ef9d
Deploy also the frontend charm
mz2 Dec 12, 2023
3f02329
Switch the model
mz2 Dec 12, 2023
5729678
Adjust the triggers
mz2 Dec 12, 2023
c789d9c
Oops, refresh the frontend app with the frontend charm
mz2 Dec 12, 2023
075bff2
Remove the if condition for now
mz2 Dec 12, 2023
bbc885c
Changes to terraform plan should also lead to a deploy
mz2 Dec 12, 2023
80303b8
Wait for application to have deployed
mz2 Dec 12, 2023
aaf3826
Wait for _frontend_ before refreshing the frontend charm
mz2 Dec 12, 2023
99f6d89
Add crashdump uploading
mz2 Dec 12, 2023
a81ba86
Output juju status and juju crashdump
mz2 Dec 12, 2023
fa6a77f
Remove redundant SystemExit(0)
mz2 Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/frontend_charm_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Run charm tests
on:
pull_request:
branches:
- main
- '**'
paths:
- 'frontend/charm/**'
push:
branches: ["main"]
tags: ["v*.*.*"]
Expand Down Expand Up @@ -35,7 +37,7 @@ jobs:
working-directory: ./frontend/charm

unit-tests-with-coverage:
name: Unit tests
name: Frontend charm unit tests
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
push:
branches: ["main"]
tags: ["v*.*.*"]
workflow_dispatch:

env:
REGISTRY: ghcr.io
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish_frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
push:
branches: ["main"]
tags: ["v*.*.*"]
workflow_dispatch:

env:
REGISTRY: ghcr.io
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/terraform_test_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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
9 changes: 7 additions & 2 deletions .github/workflows/test_backend.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Test Backend
on: [push]
# Cancel inprogress runs if new commit pushed
on:
push:
paths:
- 'backend/**'
tags:
- "v*.*.*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: [self-hosted, linux, large]
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test_frontend.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Test Frontend
on: [push]
# Cancel inprogress runs if new commit pushed
on:
push:
paths:
- 'frontend/**'
tags:
- "v*.*.*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: [self-hosted, linux, large]
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Visual Studio Code configurations
.vscode
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"python.analysis.extraPaths": [
"./backend/charm/lib"
],
"cmake.sourceDirectory": "/home/mz2/Developer/test_observer/frontend/linux"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure about including this path to settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was intentional since VS Code looked like it was now doing relative path updates. However, what I committed was the wrong state of the file 🤦

}
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,9 @@ Charms are released through GitHub actions on push to main. If however you need

## VS Code & charm libraries

VS Code fails to find (for autocompletions and code navigation purposes) the charm libraries under `lib` in each of `backend/charm` and `frontend/charm`. There is a .vscode-settings-default.json found under each of these directories which you can copy to the `.gitignore`d path `.vscode/settings.json` to make them fly. Taking the backend charm as an example:
VS Code fails to find (for autocompletions and code navigation purposes) the charm libraries under `lib` in each of `backend/charm` and `frontend/charm`. There is therafore a .vscode/settings..json found under each of the directories that will plausibly used as a VS Code workspace.

```bash
mkdir -p backend/charm/.vscode
cp backend/charm/.vscode-settings-default.json backend/charm/.vscode/settings.json

mkdir -p frontend/charm/.vscode
cp frontend/charm/.vscode-settings-default.json frontend/charm/.vscode/settings.json
```

Now if you use as your project the directory `backend/charm` and `frontend/charm` respectively (which you'll want to do also for them to keep their own virtual environments), VS Code should be happy.
If you use as your project the directory `backend/charm` and `frontend/charm` respectively (which you'll want to do also for them to keep their own virtual environments), VS Code should be happy.

## Handy documentation pointers about charming

Expand Down
3 changes: 3 additions & 0 deletions backend/charm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.charm
venv
prime
stage
parts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"python.autoComplete.extraPaths": ["./lib"],
"python.autoComplete.extraPaths": [
"./lib"
],
"python.analysis.extraPaths": [
"./lib"
],
"yaml.schemas": {
"https://json.schemastore.org/yamllint.json": [
"./metadata.yaml",
"./metadata.yaml"
]
},
"ansible.python.interpreterPath": "./venv/bin/python3"
Expand Down
6 changes: 6 additions & 0 deletions backend/charm/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"python.analysis.extraPaths": [
"./lib/charms",
"./lib"
]
}
26 changes: 26 additions & 0 deletions backend/charm/charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
name: test-observer-api
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I migrated to the new one-yaml format.

type: charm
summary: |
API to observe the status of artifact (snaps, debs, etc) testing
description: |
API and dashboard to observe the status of artifact (snaps, debs, etc) test status
bases:
- build-on:
- name: ubuntu
channel: "22.04"
run-on:
- name: ubuntu
channel: "22.04"
assumes:
- juju >= 2.9
- k8s-api
containers:
api:
resource: api-image
requires:
database:
interface: postgresql_client
limit: 1
nginx-route:
interface: nginx-route
provides:
test-observer-rest-api:
interface: http
scope: global
resources:
api-image:
type: oci-image
description: OCI image from GitHub Container Repository
upstream-source: ghcr.io/canonical/test_observer/api:main
Loading
Loading