Skip to content

Commit 807e7c2

Browse files
authored
Changes to deploy staging (#34)
* Cleanup terraform file * Switch traefik with nginx for ingress * small changes * build charm through github action on this branch * revert releasing charm in action as will do manually * Bug fixes * downgrade postgres to 14 cause lack of 15 charm * Rename jobs to be clearer * temporary make api docker image * Revert "temporary make api docker image" This reverts commit 3358ca2. * frontend charm bug fix * Remove unnecessary requirement to improve charm pack time * Use staging host names * pass tls secret name to nginx * Some bug fixes for charms * fix bugs with frontend charm * Make terraform file work for multiple environments * Ignore charm in docker * Fix frontend not connecting to api in staging * Use latest/edge instead of just edge channel for charms * Add release charms actions * Match staging environment tf provider version * Remove unnecessary charm relation endpoint * No need to release charms on local branch anymore * Fix terraform config to include base url * Remove unnecessary relation hostname * Changes to tf file to work better in development * Update readme * Make charm upload wait for image upload * Set application names so that tf doesn't error * Remove old info on readme * Readme improvements
1 parent 9b6d77c commit 807e7c2

22 files changed

+1037
-1476
lines changed

.github/workflows/public_backend_image.yml .github/workflows/publish_api.yml

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
name: Create and publish a Docker image
21
on:
32
push:
43
branches: ["main"]
@@ -8,7 +7,7 @@ env:
87
REGISTRY: ghcr.io
98

109
jobs:
11-
build-and-push-backend-image:
10+
build-and-push-image:
1211
runs-on: ubuntu-latest
1312
permissions:
1413
contents: read
@@ -42,3 +41,18 @@ jobs:
4241
push: true
4342
tags: ${{ steps.meta.outputs.tags }}
4443
labels: ${{ steps.meta.outputs.labels }}
44+
45+
build-and-push-charm:
46+
needs: build-and-push-image
47+
runs-on: ubuntu-latest
48+
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v2
52+
53+
- name: Upload charm to charmhub
54+
uses: canonical/charming-actions/upload-charm@2.2.0
55+
with:
56+
charm-path: "backend/charm"
57+
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
58+
github-token: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/publish_frontend_image.yml .github/workflows/publish_frontend.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
name: Create and publish a Docker image
21
on:
32
push:
43
branches: ["main"]
@@ -41,3 +40,16 @@ jobs:
4140
push: true
4241
tags: ${{ steps.meta.outputs.tags }}
4342
labels: ${{ steps.meta.outputs.labels }}
43+
44+
build-and-push-frontend-charm:
45+
needs: build-and-push-frontend-image
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v2
50+
- name: Upload charm to charmhub
51+
uses: canonical/charming-actions/upload-charm@2.2.0
52+
with:
53+
charm-path: "frontend/charm"
54+
credentials: "${{ secrets.CHARMHUB_TOKEN }}"
55+
github-token: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/release_charms.yml

-28
This file was deleted.

README.md

+33-65
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Observe the status and state of certification tests for various artefacts
44

5-
## Prerequisites for developing and deploying locally
5+
## Prerequisites for deploying locally
66

77
- `juju` 3.1 or later (`sudo snap install juju --channel=3.1/stable`)
88
- `microk8s` 1.27 or later (`sudo snap install microk8s --channel=1.27-strict/stable`) + [permission setup steps after install](https://juju.is/docs/sdk/set-up-your-development-environment#heading--install-microk8s)
@@ -22,25 +22,12 @@ mkdir -p ~/.local/share
2222
Fist configure microk8s with the needed extensions:
2323

2424
```
25-
sudo microk8s enable community # required for installing traefik
26-
sudo microk8s enable dns hostpath-storage metallb traefik # metallb setup involves choosing a free IP range for the load balancer.
25+
sudo microk8s enable dns hostpath-storage metallb ingress# metallb setup involves choosing a free IP range for the load balancer.
2726
```
2827

29-
Then help microk8s work with an authorized (private) OCI image registry at ghcr.io:
30-
31-
1. Get a GitHub personal access token at https://github.com/settings/tokens/new with the `read:packages` permission.
32-
2. Configure containerd in microk8s with the auth credentials needed to pull images from non-default, authorisation requiring OCI registries by appending the following to `/var/snap/microk8s/current/args/containerd-template.toml`:
33-
34-
```yaml
35-
[plugins."io.containerd.grpc.v1.cri".registry.configs."ghcr.io".auth]
36-
username = "your-GitHub-username"
37-
password = "your-GitHub-API-token"
38-
```
39-
40-
After this config file tweak, restart containerd and microk8s:
28+
Setup juju:
4129

4230
```bash
43-
sudo systemctl restart snap.microk8s.daemon-containerd.service && sudo microk8s.stop && sudo microk8s.start
4431
juju bootstrap microk8s
4532
juju model-config logging-config="<root>=DEBUG"
4633
```
@@ -65,7 +52,7 @@ At the time of writing, this will accomplish deploying the following:
6552
- the backend API server
6653
- the frontend served using nginx
6754
- a postgresql database
68-
- traefik as ingress
55+
- nginx as ingress
6956
- backend connected to frontend (the backend's public facing base URI passed to the frontend app)
7057
- backend connected to database
7158
- backend connected to load balancer
@@ -77,51 +64,46 @@ The terraform juju provider is documented over here: https://registry.terraform.
7764

7865
Terraform tracks its state with a .tfstate file which is created as a result of running `terraform apply` -- for production purposes this will be stored in an S3-like bucket remotely, and for local development purposes it sits in the `terraform` directory aftery you have done a `terraform apply`).
7966

80-
You can optionally get SSL certificates automatically managed for the ingress (in case you happen to have a DNS zone with Cloudflare DNS available):
67+
After all is up, you can run `juju switch test-observer-development` to use the development juju model. Then `juju status --relations` should give you output to the direction of the following:
8168

8269
```bash
83-
TF_VAR_environment=development TF_VAR_external_ingress_hostname="mah-domain.com" TF_VAR_cloudflare_acme=true TF_VAR_cloudflare_dns_api_token=... TF_VAR_cloudflare_zone_read_api_token=... TF_VAR_cloudflare_email=... terraform apply -auto-approve
84-
```
70+
$ juju status --relations
71+
Model Controller Cloud/Region Version SLA Timestamp
72+
test-observer-development juju-controller microk8s/localhost 3.1.2 unsupported 15:38:51+03:00
8573

86-
After all is up, you can run `juju switch test-observer-development` to use the development juju model. Then `juju status --relations` should give you output to the direction of the following (the acme-operator only there if `TF_VAR_cloudflare_acme` was passed in):
74+
App Version Status Scale Charm Channel Rev Address Exposed Message
75+
api active 1 test-observer-api latest/edge 15 10.152.183.182 no
76+
db 14.7 active 1 postgresql-k8s 14/stable 73 10.152.183.172 no Primary
77+
frontend active 1 test-observer-frontend latest/edge 8 10.152.183.79 no
78+
ingress 25.3.0 active 1 nginx-ingress-integrator stable 59 10.152.183.103 no Ingress IP(s): 127.0.0.1, 127.0.0.1, Service IP(s): 10.152.183.72, 10.152.183.34
8779

88-
```bash
89-
$ juju status --relations
90-
Model Controller Cloud/Region Version SLA Timestamp
91-
test-observer-development microk8s-localhost microk8s/localhost 3.1.2 unsupported 23:23:01+03:00
92-
93-
App Version Status Scale Charm Channel Rev Address Exposed Message
94-
acme-operator active 1 cloudflare-acme-operator beta 3 10.152.183.59 no
95-
ingress 2.9.6 active 1 traefik-k8s stable 110 192.168.0.202 no
96-
pg 14.7 active 1 postgresql-k8s 14/stable 73 10.152.183.106 no Primary
97-
test-observer-api active 1 test-observer-api edge 6 10.152.183.207 no
98-
test-observer-frontend active 1 test-observer-frontend edge 2 10.152.183.111 no
99-
100-
Unit Workload Agent Address Ports Message
101-
acme-operator/0* active idle 10.1.92.188
102-
ingress/0* active idle 10.1.92.182
103-
pg/0* active idle 10.1.92.137 Primary
104-
test-observer-api/0* active idle 10.1.92.143
105-
test-observer-frontend/0* active idle 10.1.92.189
106-
107-
Relation provider Requirer Interface Type Message
108-
acme-operator:certificates ingress:certificates tls-certificates regular
109-
ingress:ingress test-observer-api:ingress ingress regular
110-
ingress:ingress test-observer-frontend:ingress ingress regular
111-
pg:database test-observer-api:database postgresql_client regular
112-
pg:database-peers pg:database-peers postgresql_peers peer
113-
pg:restart pg:restart rolling_op peer
114-
test-observer-api:test-observer-rest-api test-observer-frontend:test-observer-rest-api http regular
80+
Unit Workload Agent Address Ports Message
81+
api/0* active idle 10.1.131.142
82+
db/0* active idle 10.1.131.132 Primary
83+
frontend/0* active idle 10.1.131.169
84+
ingress/0* active idle 10.1.131.167 Ingress IP(s): 127.0.0.1, 127.0.0.1, Service IP(s): 10.152.183.72, 10.152.183.34
85+
86+
Relation provider Requirer Interface Type Message
87+
api:test-observer-rest-api frontend:test-observer-rest-api http regular
88+
db:database api:database postgresql_client regular
89+
db:database-peers db:database-peers postgresql_peers peer
90+
db:restart db:restart rolling_op peer
91+
ingress:nginx-route api:nginx-route nginx-route regular
92+
ingress:nginx-route frontend:nginx-route nginx-route regular
11593
```
11694

117-
To test the application with the frontend and API server ports exposed, you need to create some aliases in `/etc/hosts` to the IP address that the ingress got from `metallb` (`juju status` above will find you the ingress IP). Let's assume you have a domain `mah-domain.com` that you want to expose service under, the backend and frontend will be present as subdomains `test-observer-frontend.mah-domain.com` and `test-observer-api.mah-domain.com`, respectively:
95+
## Add /etc/hosts entries
96+
97+
To test the application, you need to create some aliases in `/etc/hosts` to the IP address that the ingress got from `metallb` (`juju status` above will find you the ingress IP). Let's assume you have a domain `mah-domain.com` that you want to expose service under, the backend and frontend will be present as subdomains `test-observer.mah-domain.com` and `test-observer-api.mah-domain.com`, respectively:
11898

11999
```bash
120100
$ cat /etc/hosts
121-
192.168.0.202 test-observer-frontend.mah-domain.com test-observer-api.mah-domain.com
101+
192.168.0.202 test-observer.mah-domain.com test-observer-api.mah-domain.com
122102
...
123103
```
124104

105+
Note that without this step the frontend will fail to connect to api as it's trying to use `test-observer-api.mah-domain.com`
106+
125107
## Developing the charm
126108

127109
To develop and test updates to the backend and frontend charms, you would typically want to first complete the above steps to deploy a working system. Once you have done that, proceed with the following steps.
@@ -172,21 +154,7 @@ tox -e integration
172154

173155
## Releasing the charms
174156

175-
You can use [release-k8s-charm](https://github.com/mz2/release-k8s-charm) to release the charms to charmhub, until we ingroduce a GitHub action driven workflow for releasing them (the `upload-charm` action in [canonical/charming-actions](https://github.com/canonical/charming-actions) will be the longer term solution).
176-
177-
To release the backend charm:
178-
179-
```bash
180-
cd backend/charm
181-
wherever-you-stash-source-code/release-k8s-charm/main.py --charm-metadata ./metadata.yaml --channel edge
182-
```
183-
184-
To release the frontend charm:
185-
186-
```bash
187-
cd frontend/charm
188-
wherever-you-stash-source-code/release-k8s-charm/main.py --charm-metadata ./metadata.yaml --channel edge
189-
```
157+
Charms are released through GitHub actions on push to main. If however you need to release charms on your branch before merging with main you could always just add your branch as a trigger to those same GitHub actions.
190158

191159
## VS Code & charm libraries
192160

backend/.dockerignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,7 @@ venv/
9595
*.md
9696

9797
# Emacs
98-
flycheck*
98+
flycheck*
99+
100+
# Juju Charm
101+
charm/

backend/charm/actions.yaml

-2
This file was deleted.

0 commit comments

Comments
 (0)