Skip to content

Commit 023648e

Browse files
committed
switch schmema gen to helm-values-schema-json
1 parent dfd92fc commit 023648e

18 files changed

+341
-789
lines changed

.github/workflows/_helm.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jobs:
1010
package-helm-charts:
1111
name: Package and Push Helm Chart
1212
runs-on: ubuntu-latest
13-
environment: release
1413
steps:
1514
- name: Checkout
1615
uses: actions/checkout@v4
@@ -43,7 +42,7 @@ jobs:
4342
set -xe
4443
4544
mkdir -p charts
46-
for i in Charts/*; do
45+
for i in $(find Charts -type d -maxdepth 1 -mindepth 1); do
4746
if [[ ${i} =~ ^.*-ioc$ ]]; then
4847
echo "Skipping IOC schema chart: ${i}"
4948
continue
@@ -57,15 +56,16 @@ jobs:
5756
uses: actions/upload-artifact@v4
5857
with:
5958
name: helm-chart-schemas
60-
path: schemas/
59+
path: schemas/*
6160

6261
- name: Push tagged helm chart to registry
62+
# TODO - switch to using https://github.com/helm/chart-releaser-action of maybe the docker action?
6363
if: ${{ github.ref_type == 'tag' }}
6464
run: |
6565
set -x
6666
6767
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io/${{ github.repository_owner }} --username ${{ github.repository_owner }} --password-stdin
68-
REGISTRY=oci://ghcr.io/diamondlightsource/charts
68+
REGISTRY=oci://ghcr.io/${{github.repository_owner }}/charts
6969
for i in charts/*.tgz; do
70-
helm push "${i}" ${REGISTRY}
70+
helm push "${i}" ${REGISTRY,,}
7171
done

.github/workflows/_tox.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ jobs:
1818
- name: Install python packages
1919
uses: ./.github/actions/install_requirements
2020

21+
- name: Install helm plugins
22+
run: helm plugin install https://github.com/losisin/helm-values-schema-json.git
23+
2124
- name: Run tox
2225
run: tox -e ${{ inputs.tox }}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252

5353
pypi:
5454
if: github.ref_type == 'tag'
55-
needs: dist
55+
needs: [helm, dist]
5656
uses: ./.github/workflows/_pypi.yml
5757
permissions:
5858
id-token: write

.pre-commit-config.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ repos:
2424
types: [python]
2525
require_serial: true
2626

27+
- repo: https://github.com/losisin/helm-values-schema-json
28+
rev: v2.2.1
29+
hooks:
2730
- id: helm-schema
28-
name: Generate Helm schema
29-
entry: ./generate-schemas.sh
30-
language: system
31-
types: [yaml]
32-
require_serial: true
31+
args:
32+
- --config
33+
- Charts/fastcs/.schema.config.yaml

Charts/README_CHARTS.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Charts
2+
3+
This directory contains Helm charts for deploying FastCS services.
4+
5+
TODO: The implementation of helm charts in this repo is intended to be general purpose and is a proposed solution for the `python-copier-template`.
6+
7+
## Github Actions
8+
9+
This folder works in tandem with [_helm.yml](../.github/workflows/_helm.yml) github actions workflow which:
10+
11+
- Validates the stricter form of SemVer tag that helm requires.
12+
- Finds all subfolders in the `Charts` directory and packages them as Helm charts.
13+
- Publishes the packaged charts to ghcr.io/${{github.repository_owner }}/charts/CHART_NAME
14+
- Uploads the contents of /schemas to artifacts (meaning they will be published to the release)
15+
16+
This standalone Helm related workflow is independent of the rest of the workflows except that the _pypi workflow has _helm added to its `needs` in `ci.yml`, making sure we only publish to pypi with valid SemVer tags.
17+
18+
TODO: for a project that publishes containers referred to by the helm chart, the `_containers.yml` workflow should be added to the `needs` of _helm in `ci.yml`.
19+
20+
## Schema Generation
21+
22+
Schema generation for charts' `values.yaml` is handled by [helm-values-schema-json](https://github.com/losisin/helm-values-schema-json). Which is in turn controlled by annotations in the default [values.yaml](fastcs/values.yaml) file.
23+
24+
The generated schema file will be called `values.schema.json` and will be placed in the same directory as the `values.yaml` file and commited to the repo. This is done automatically by a [pre-commit hook](https://github.com/DiamondLightSource/FastCS/blob/8232393b38cc8e0eee00680e95c2ce06e7983ba6/.pre-commit-config.yaml#L27-L33). Therefore, when developing charts you can update schemas with:
25+
26+
```bash
27+
git add . ; pre-commit
28+
```
29+
30+
Note that this standard name for the schema file means that it is packaged up with the helm chart and available for schema checks in ArgoCD for example.
31+
32+
## schemas folder
33+
34+
The schemas folder allows us to declare the schemas you want to publish to the release.
35+
36+
It should contain:
37+
38+
- A symlink to each of the `values.schema.json` files in the subfolders of `Charts`. The symlink should have a unique name, e.g. `fastcs-values.schema.json`, thus allowing multiple schemas to be published per repo.
39+
- A service schema file which references the above and can be used to validate `values.yaml` in epics-containers services repos, where the these charts will be used as sub-charts. e.g. [fastcs-service.schema.json](../schemas/fastcs-service.schema.json)
40+
41+
The service schema files are hand coded as they are extremely simple. The symlinks are also manually created at present. (both of these could potentially be automated).
42+
43+
## Debuging/Development In-Cluster
44+
45+
The `fastcs` helm chart has two variables to enable debugging/development in-cluster:
46+
47+
- `editable`: When true:
48+
- a PVC is created.
49+
- The debug version of the container image is referenced.
50+
- The contents of /workspaces and /venv are copied into the PVC.
51+
- The venv from the debug image is an editable install of the project source code in /workspaces.
52+
- The PVC folders are mounted over the corresponding folders in the container.
53+
- `autostart`:
54+
- When false, the container starts with PID 1 as sleep infinity.
55+
- When true, the container starts with its normal entrypoint.
56+
57+
In combination these flags can be used to debug or develop in-cluster.
58+
59+
An initial demonstration script to use these features is provided in [debug.py](https://github.com/epics-containers/p47-services/blob/add-fastcs/debug.py) in the `p47-services` repo.
60+
61+
This script will:
62+
63+
- inspect the values of `editable` and `autostart` in the `values.yaml` file of the specified IOC (TODO: at present it uses the p47-services source code to do so but this should be determined from the cluster in future).
64+
- port forward the debugpy port (5678) from the pod to localhost.
65+
- If editable is true, it will mount the PVC locally using pv-mounter and open VSCode to the /workspaces/xxx folder.
66+
- If autostart is false, it will exec into the container and launch debugpy to run the main program.
67+
- If autostart is true, it will exec into the container and attach debugpy to PID 1.
68+
69+
This then allows you to attach VSCode to debugpy in the cluster container and if 'editable' is true, edit the source code in VSCode and have the changes reflected.
70+
71+
To attach to debugpy the following launch.json configuration is supplied in the [fastcs-example project](https://github.com/DiamondLightSource/fastcs-example/blob/77daed5f5a2bd01ab4c0e1d8c812e8754b254674/.vscode/launch.json#L7-L22). (this will also go in python-copier-template in future).

Charts/fastcs-ioc/Chart.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)