canonical / discourse-gatekeeper

Experimental GitHub Action to upload charm documentation to charmhub
Apache License 2.0
7 stars 7 forks source link

Draft publish docs output should be more readable #226

Open mthaddon opened 8 months ago

mthaddon commented 8 months ago

Here's an example of current output:

NFO:root:Base branch: main (commit 5dc033bfe8dc94f74dd6202dafc689f4acf4fb6f)
INFO:root:executing in git repository in the directory: /tmp/tmpskhp2481/cwd
INFO:root:Repository at b5b0c256899d7024d8e909530aa50fb9b2e7b7f7 (b5b0c256899d7024d8e909530aa50fb9b2e7b7f7)
INFO:root:executing in git repository in the directory: /tmp/tmpjjc58qi_/cwd
INFO:root:action: NoopGroupAction(level=1, path=('explanation',), navlink=Navlink(title='Explanation', link=None, hidden=False))
INFO:root:report: ActionReport(table_row=TableRow(level=1, path=('explanation',), navlink=Navlink(title='Explanation', link=None, hidden=False)), location=None, result=<ActionResult.SUCCESS: 'success'>, reason=None)
INFO:root:action: NoopPageAction(level=2, path=('explanation', 'charm-architecture'), navlink=Navlink(title='Charm architecture', link='/t/content-cache-k8s-docs-charm-architecture/8712', hidden=False), content='# Charm architecture\n\nAt its core, Content-cache-k8s is a NGINX cache application that helps another charm serving static content for it.\n\nThe charm design leverages the [sidecar](https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns/#example-1-sidecar-containers) pattern to allow multiple containers in each pod with [Pebble](https://juju.is/docs/sdk/pebble) running as the workload container’s entrypoint.\n\nPebble is a lightweight, API-driven process supervisor that is responsible for configuring processes to run in a container and controlling those processes throughout the workload lifecycle.\n\nPebble `services` are configured through [layers](https://github.com/canonical/pebble#layer-specification), and the following containers represent each one a layer forming the effective Pebble configuration, or `plan`:\n\n1. An [NGINX](https://www.nginx.com/) container with caching features, which can be used to efficiently serve static resources, as well as be the incoming point for all web traffic to the pod. This is the content cache container itself.\n2. A [NGINX Prometheus Exporter](https://github.com/nginxinc/nginx-prometheus-exporter) container that can be used to provide statistics on web traffic.\n\nAs a result, if you run a `kubectl get pods` on a namespace named for the Juju model you\'ve deployed the Content-cache-k8s charm into, you\'ll see something like the following:\n\n```bash\nNAME                             READY   STATUS    RESTARTS   AGE\ncontent-cache-k8s-0              3/3     Running   0          97s\n\n```\n\nThis shows there are 3 containers - the two named above, as well as a container for the charm code itself.\n\nAnd if you run `kubectl describe pod content-cache-k8s-0`, all the containers will have as Command ```/charm/bin/pebble```. That\'s because Pebble is responsible for the processes startup as explained above.\n\n## Containers\n\nConfiguration files for the containers can be found in [the files directory of the charm repository](https://github.com/canonical/content-cache-k8s-operator/tree/main/files) and in [the templates directory of the charm repository](https://github.com/canonical/content-cache-k8s-operator/tree/main/templates)\n\n### Content cache\n\nThis container is the entry point for all web traffic to the pod (on port `80`). Serves static files directly.\n\nThe workload that this container is running is defined in the [Content-cache dockerfile in the charm repository](https://github.com/canonical/content-cache-k8s-operator/blob/main/content-cache.Dockerfile).\n\n### NGINX prometheus exporter\n\nThis container runs the `nginx/nginx-prometheus-exporter` image.\n\nThe `NGINX Prometheus Exporter` is started with `-nginx.scrape-uri=http://localhost:9080/stub_status` so will scrape metrics from the NGINX container.\n\nThis has been configured in the NGINX container to return NGINX\'s [stub_status](http://nginx.org/en/docs/http/ngx_http_stub_status_module.html). The exporter listens on port `91[13](https://github.com/canonical/content-cache-k8s-operator/actions/runs/7032606663/job/19136691099?pr=60#step:6:14)` and metrics about web traffic to the pod can be scraped by Prometheus there.\n\n## Docker images\n\nThe image defined in [Content-cache dockerfile](https://github.com/canonical/content-cache-k8s-operator/blob/main/content-cache.Dockerfile) in the charm repository is published to [Charmhub](https://charmhub.io/), the official repository of charms.\n\nThis is done by publishing a resource to Charmhub as described in the [Juju SDK How-to guides](https://juju.is/docs/sdk/publishing).\n\n## Integrations\n\n### Grafana\n\nGrafana is an open-source visualization tool that allows to query, visualize, alert on, and visualize metrics from mixed datasources in configurable dashboards for observability. This charm is shipped with its own Grafana dashboard and supports integration with the [Grafana Operator](https://charmhub.io/grafana-k8s) to simplify observability.\n\n### Ingress\n\nThe Content-cache charm also supports being integrated with [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/#what-is-ingress) by using [NGINX Ingress Integrator](https://charmhub.io/nginx-ingress-integrator/).\n\nIn this case, an existing Ingress controller is required. For more information, see [Adding the Ingress Relation to a Charm](https://charmhub.io/nginx-ingress-integrator/docs/adding-ingress-relation).\n\n### Loki\n\nLoki is an open-source fully-featured logging system. This charm is shipped with support for the [Loki Operator](https://charmhub.io/loki-k8s) to collect the generated logs.\n\n### Prometheus\n\nPrometheus is an open-source system monitoring and alerting toolkit with a dimensional data model, flexible query language, efficient time series database, and modern alerting approach. This charm is shipped with a Prometheus exporter, alerts, and support for integrating with the [Prometheus Operator](https://charmhub.io/prometheus-k8s) to automatically scrape the targets.\n\n## Juju events\n\nAccordingly to the [Juju SDK](https://juju.is/docs/sdk/event): "an event is a data structure that encapsulates part of the execution context of a charm".\n\nFor this charm, the following events are observed:\n\n1. [<container name>_pebble_ready](https://juju.is/docs/sdk/container-name-pebble-ready-event): fired on Kubernetes charms when the requested container is ready.\nAction: wait for the integrations, and configure the containers.\n2. [config_changed](https://juju.is/docs/sdk/config-changed-event): usually fired in response to a configuration change using the CLI.\nAction: wait for the integrations, validate the configuration, update Ingress, and restart the containers.\n3. [report_visits_by_ip](https://charmhub.io/content-cache-k8s/actions): fired when report-visits-by-ip action is executed.\nAction: Report the amount of visits grouped by IP that have visited the service ordered by amount of visits.\n\n## Charm code overview\n\nThe `src/charm.py` is the default entry point for a charm and has the ContentCacheCharm Python class which inherits from CharmBase.\n\nCharmBase is the base class from which all Charms are formed, defined by [Ops](https://juju.is/docs/sdk/ops) (Python framework for developing charms).\n\nSee more information in [Charm](https://juju.is/docs/sdk/constructs#heading--charm).\n\nThe `__init__` method guarantees that the charm observes all events relevant to its operation and handles them.\n\nTake, for example, when a configuration is changed by using the CLI.\n\n1. User runs the command\n```bash\njuju config smtp_login=user1\n```\n2. A `config-changed` event is emitted\n3. In the `__init__` method is defined how to handle this event like this:\n```python\nself.framework.observe(self.on.config_changed, self._on_config_changed)\n```\n4. The method `_on_config_changed`, for its turn,  will take the necessary actions such as waiting for all the relations to be ready and then configuring the containers.')
INFO:root:report: ActionReport(table_row=TableRow(level=2, path=('explanation', 'charm-architecture'), navlink=Navlink(title='Charm architecture', link='/t/content-cache-k8s-docs-charm-architecture/8712', hidden=False)), location='https://discourse.charmhub.io/t/content-cache-k8s-docs-charm-architecture/8712', result=<ActionResult.SUCCESS: 'success'>, reason=None)
...

This could be much more readable if it was formatted as a human-readable diff.