|
| 1 | +# The Charm for the snapcraft.io website |
| 2 | + |
| 3 | +This charm was created using the [PaaS App Charmer](https://juju.is/docs/sdk/paas-charm) |
| 4 | + |
| 5 | +## Local development |
| 6 | + |
| 7 | +To work on this charm locally, you first need to set up an environment, follow [this section](https://juju.is/docs/sdk/write-your-first-kubernetes-charm-for-a-flask-app#heading--set-things-up) of the tutorial. |
| 8 | + |
| 9 | +Then, you can run the following command to pack and upload the rock: |
| 10 | + |
| 11 | +```bash |
| 12 | +rockcraft pack |
| 13 | +rockcraft.skopeo --insecure-policy copy --dest-tls-verify=false oci-archive:snapcraft-io*.rock docker://localhost:32000/snapcraft-io:1 |
| 14 | +``` |
| 15 | + |
| 16 | +This will pack the application into a [rock](https://documentation.ubuntu.com/rockcraft/en/latest/explanation/rocks/) (OCI image) and upload it to the local registry. |
| 17 | + |
| 18 | +You can deploy the charm locally with: |
| 19 | + |
| 20 | +```bash |
| 21 | +cd charm |
| 22 | +charmcraft fetch-libs |
| 23 | +charmcraft pack |
| 24 | +juju deploy ./*.charm --resource flask-app-image=localhost:32000/snapcraft-io:1 |
| 25 | +``` |
| 26 | + |
| 27 | +This will deploy the charm with the rock image you just uploaded attached as a resource. |
| 28 | + |
| 29 | +once `juju status` reports the charm as `active`, you can test the webserver: |
| 30 | + |
| 31 | +```bash |
| 32 | +curl {IP_OF_SNAPCRAFT_IO_UNIT}:8000 |
| 33 | +``` |
| 34 | + |
| 35 | +to connect using a browser, the easiest way is to integrate with `nginx-ingress-integrator`: |
| 36 | + |
| 37 | +```bash |
| 38 | +juju deploy nginx-ingress-integrator --trust |
| 39 | +juju config nginx-ingress-integrator service-hostname=snapcraft.local path-routes=/ |
| 40 | +juju integrate nginx-ingress-integrator snapcraft-io |
| 41 | +``` |
| 42 | + |
| 43 | +You can then add `snapcraft.local` to your `/etc/hosts` file with the IP of the multipass vm: |
| 44 | + |
| 45 | +```bash |
| 46 | +multipass ls # Get the IP of the VM |
| 47 | +echo "{IP_OF_VM} snapcraft.local" | sudo tee -a /etc/hosts |
| 48 | +``` |
| 49 | + |
| 50 | +> Note: login will not work using this setup, if you'd like to access publisher pages, change the domain to `staging.snapcraft.io`, but make sure to remove the line from `/etc/hosts/` after you're done. |
| 51 | +
|
| 52 | + |
| 53 | +## Design Decisions: |
| 54 | +- To keep the codebase clean and charm libraries updated, they are only fetched before packing the charm in the [Github Actions workflow](https://github.com/canonical/snapcraft.io/blob/main/.github/workflows/publish_charm.yaml#L25). |
| 55 | +- As all our work is open source, the charm is publicly available on [snapcraft](https://charmhub.io/snapcraft-io), the rock image is also included as a resource. This significantly simplifies deployment. |
0 commit comments