Skip to content

Commit 34ba22a

Browse files
Dav-14David Ragot
andauthored
chore: clean comments and docs (#32)
* fix: labeler diff * chore(clean): rename root as charts target & remove unused comment * feat: include license on all charts, remove unused targets, remove generated README.md * chore: update readme template * feat: wording --------- Co-authored-by: David Ragot <[email protected]>
1 parent b07fdf8 commit 34ba22a

File tree

23 files changed

+186
-225
lines changed

23 files changed

+186
-225
lines changed

.github/workflows/pull_request.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Retrieve chart changes
2626
id: chart_changes
2727
run: |
28-
CHARTS=$(git diff origin/main --stat | grep -oE 'charts/[^/]+/' | sed 's|charts/||;s|/||' | sort -u | jq -R -s -c 'split("\n") | map(select(. != ""))')
28+
CHARTS=$(git diff ${{ github.base_ref }} --stat | grep -oE 'charts/[^/]+/' | sed 's|charts/||;s|/||' | sort -u | jq -R -s -c 'split("\n") | map(select(. != ""))')
2929
echo "Changed charts: $CHARTS"
3030
echo "::set-output name=changed_charts::$CHARTS"
3131
@@ -83,4 +83,10 @@ jobs:
8383
git status
8484
echo "There are changes in the repository"
8585
exit 1
86-
fi
86+
fi
87+
- name: Archive chart
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: charts_${{ github.ref_type == 'branch' && github.sha }}.tgz
91+
path: charts/**/*.tgz
92+
retention-days: 3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
dist
77

8+
charts/**/LICENSE
9+
810
.tmp-earthly-out

CONTRIBUTING.md

Lines changed: 86 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,111 @@
11
# Helm Charts
22

3-
## Validating the PR
3+
## Working Per Chart
44

5-
```bash
6-
earthly +pre-commit
7-
```
5+
### Building the Charts
86

9-
## Working Per Chart
7+
Each chart must implement the common targets interface with the following minimum required files:
8+
9+
- `Chart.yaml`
10+
- `Earthfile`
11+
12+
Each `Earthfile` Chart **must** implement the following targets to integrate with the CI:
13+
14+
- `+sources`: Raw sources of the chart without the dependencies.
15+
> [!IMPORTANT]
16+
> A LICENSE file is included in every chart through the helper [SOURCE](./charts/Earthfile)
17+
- `+dependencies`: Raw sources with dependencies updated.
18+
- `+validate`: Validates the chart, including its dependencies.
19+
- `+package`: Packages the chart from validated sources.
20+
- `+readme`: (Optional): Include README when dependendies are validated.
21+
> The README file is generated with `helm-docs` and included in the chart through the helper [README_GENERATOR](./charts/Earthfile).
22+
23+
> [!TIP]
24+
> A file named `README.md.gotmpl` can be added to the chart to customize the README generation.
25+
- `+schema`: (Optional): Generate a values schema from the `values.yaml` and include it in the chart sources. Then it will be validated with the `+validate` target.
1026

11-
### Building the chart
1227

13-
Each chart must implement the common targets interface with the minimum required files:
14-
- Chart.yaml
15-
- Earthfile
16-
- values.yaml <--- It can be empty with {} as content
28+
### Core Library
1729

18-
Each chart **must** implement the following targets:
19-
- `+sources`: raw sources of the chart without the dependendies
20-
- `+dependencies`: raw sources + dependencies updated
21-
- `+validate`: validate the chart from the dependencies
22-
- `+package`: package the chart from validated sources
30+
Each chart must implement the core Helm library as a dependency to include the common helpers for:
2331

24-
> LICENCE is included in every chart throught the helper [SOURCE](./charts/Earthfile)
32+
- Improve resource naming
33+
- [Kubernetes recommended labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/)
34+
- Values naming
2535

26-
> README is generated with `helm-docs` and it is included in the chart throught the helper [README_GENERATOR](./charts/Earthfile)
36+
- Global values structure accross all charts, including settings
37+
- Monitoring
38+
- Traces(OTLP)
39+
- Metrics(OTLP)
40+
- Logs(JSON)
41+
- Storage
42+
- PostgreSQL (Bitnami) (Internal or External)
43+
- Nats (Nats.io) (Internal)
44+
45+
- (Optionals):
46+
47+
- AWS IAM
48+
- AWS Target Groups
49+
- Ingress
50+
- PodDisruptionBudget
51+
- HorizontalPodAutoscaler
52+
- ServiceAccount
53+
- RBAC
54+
- NetworkPolicy
2755

28-
### Core Dependencies
56+
## Validate repository changes
2957

30-
Each chart must implement the core helm library as a dependency to include the common helper:
58+
To validate the all the changes arround the repository, run the following command:
3159

32-
- resources naming
33-
- values naming
34-
- values structure
35-
- kubernetes recommended labels
36-
- (optional): aws, tgb, ingress, pdp, hpa
60+
```bash
61+
earthly +pre-commit
62+
```
63+
64+
1. First run
65+
once running it for the first time, it will build all the dependencies and validate all the charts and the charts.
66+
67+
2. Second run
68+
It will validate the future changes only where it needs to be validated thanks to caches.
3769

38-
## CI: Github Actions
70+
## Tests core and charts
3971

40-
The CI is based on github actions and it is triggered on each PR and push to the main branch.
72+
- Naming conventions for included resource
73+
- Labels selection
74+
- Default environment variables bindings
75+
- Resources disablings
76+
- HorizontalPodAutoscaler
77+
- Ingress
78+
- PodDisruptionBudget
79+
- Subchart disabling
80+
- Secret mapping
81+
- Configmap mapping
82+
- Managed Stacks Features: Disable GRPC communication with any type of Agent
4183

42-
The CI is composed by the following workflows:
84+
## CI: GitHub Actions
4385

44-
- Labeler:
45-
- It checks for changes in the `charts/` folder and labels the PR with the chart name
46-
- Main:
47-
- Validate the PR name
48-
- Check if readme has been regenerated
49-
- Validate & Package each chart labeled in the PR
50-
- Release:
51-
- Use chart-releaser to release the charts where the PR has been merged on main. It will create a new tag with the version of the chart and release it to the helm repo.
86+
The CI is based on GitHub Actions, triggered on each PR and the main branch. It is composed of the following workflows:
5287

53-
## CD
88+
- **Pull Request**: PR
89+
- Validates the PR name.
90+
- Labels the PR with the charts who have changed in the `charts/` directory.
91+
- Lint, Template, Generate Readmes for any charts who has changed. And Test Requirements accross on all charts `earthly +ci`.
92+
- **Release**: Main
93+
- Lint, Template, Generate Readmes for any charts who has changed. And Test Requirements accross on all charts `earthly +ci`.
94+
- Release any `Chart.yaml` `.version` that have been upgraded.
95+
- `chart-releaser` is based on builded Artifact. - It creates a new tag with the chart version and releases on github it to the Helm repository.
5496

55-
External repository can relies on the `+package` target and artifact to be able to deploy from specific branch or tag.
97+
## CD: from sources
98+
99+
External repositories can rely on the `+package` target and artifact to deploy from a specific branch or tag.
56100

57101
```bash
58102
earthly github.com/formancehq/helm/charts/cloudprem+package
59103
```
60104

61-
<!-- Each chart are published to the [Artifact HUB](https://artifacthub.io/packages/search?repo=formancehq) and can be installed with helm:
105+
## CD: from Helm repository
62106

63-
```bash
64-
helm repo add formancehq https://formancehq.github.io/helm
65-
helm install formancehq/cloudprem
66-
``` -->
107+
The helm repository is `ghcr.io/formancehq/helm` and can be used to deploy the charts.
67108

109+
```bash
110+
helm upgrade --install regions ghcr.io/formancehq/helm/regions --version v2.0.18
111+
```

Earthfile

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,27 @@ VERSION 0.8
33
IMPORT ./charts AS charts
44
IMPORT github.com/formancehq/earthly:tags/v0.16.2 AS core
55

6-
license:
6+
sources:
7+
ARG --required PATH
78
FROM core+base-image
89
WORKDIR /src
9-
COPY ./LICENSE .
10-
SAVE ARTIFACT LICENSE
11-
12-
formance-runner:
13-
FROM earthly/earthly:latest
14-
RUN apk add --no-cache bash
15-
ARG REPOSITORY=ghcr.io
16-
ARG tag=latest
17-
ENTRYPOINT /bin/bash
18-
DO core+SAVE_IMAGE --COMPONENT=formance-runner --REPOSITORY=${REPOSITORY} --TAG=$tag
10+
COPY --dir ./${PATH} .
11+
SAVE ARTIFACT /src
1912

2013
readme:
21-
FROM core+builder-image
14+
FROM core+base-image
15+
RUN apk add go
16+
RUN touch README.md
2217
COPY --dir charts /charts
2318
COPY (./tools/readme+sources/*) /src
2419
WORKDIR /src
25-
RUN touch README.md
26-
RUN go run ./ readme --chart-dir /charts >> README.md
20+
RUN --mount=type=cache,id=gomod,target=${GOPATH}/pkg/mod \
21+
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
22+
go run ./ readme --chart-dir /charts >> README.md
2723
SAVE ARTIFACT README.md AS LOCAL README.md
2824

2925
validate:
30-
LOCALLY
26+
FROM core+base-image
3127
FOR chart IN $(ls -d ./charts/*/)
3228
BUILD $chart+validate
3329
END
@@ -36,7 +32,7 @@ tests:
3632
BUILD ./test/helm+tests
3733

3834
package:
39-
LOCALLY
35+
FROM core+base-image
4036
FOR chart IN $(ls -d ./charts/*/)
4137
BUILD $chart+package
4238
END

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## How to use Helm charts
44

5-
| Charts | Chart Version | App Version | Description | Hub |
5+
| Readme | Chart Version | App Version | Description | Hub |
66
|--------|---------------|-------------|-------------|-----|
77
| [Cloudprem](./charts/cloudprem/README.md) | v2.0.0-beta.11 |v0.35.3 | Formance control-plane | [![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/cloudprem)](https://artifacthub.io/packages/search?repo=cloudprem) |
88
| [Console](./charts/console/README.md) | v1.0.0-beta.1 |9431e5f4b4b1a03cb8f02ef1676507b9c023f2bb | Formance Console | [![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/console)](https://artifacthub.io/packages/search?repo=console) |

charts/Earthfile

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
VERSION 0.8
22

33
IMPORT github.com/formancehq/earthly:tags/v0.16.3 AS core
4-
# IMPORT ../.. AS root
4+
IMPORT .. AS root
55

66
BASE:
77
FUNCTION
@@ -10,10 +10,9 @@ BASE:
1010

1111
SOURCES:
1212
FUNCTION
13-
# COPY (root+license/*) .
13+
COPY (root+sources/* --PATH=LICENSE) .
1414
COPY --if-exists Chart.lock .
1515
COPY Chart.yaml .
16-
COPY --if-exists README.md .
1716
COPY --if-exists values.yaml .
1817
COPY --dir --if-exists templates .
1918
SAVE ARTIFACT ./* AS LOCAL ./
@@ -45,17 +44,6 @@ PACKAGE:
4544
RUN helm package .
4645
SAVE ARTIFACT *.tgz AS LOCAL ./
4746

48-
# publish:
49-
# ARG --required PROJECT
50-
# FROM ./$PROJECT+package
51-
# WITH DOCKER
52-
# RUN --secret GITHUB_TOKEN echo $GITHUB_TOKEN | docker login ghcr.io -u NumaryBot --password-stdin
53-
# END
54-
# WITH DOCKER
55-
# RUN helm push *.tgz oci://ghcr.io/formancehq/helm
56-
# END
57-
58-
5947
README_GENERATOR:
6048
FUNCTION
6149
RUN helm-docs --chart-search-root=.. --document-dependency-values
@@ -71,6 +59,7 @@ readme-base:
7159
ARG HELM_DOCS_VERSION=v1.14
7260
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
7361
DO --pass-args core+GO_INSTALL --package=github.com/norwoodj/helm-docs/cmd/helm-docs@$HELM_DOCS_VERSION
62+
7463
SCHEMA:
7564
FUNCTION
7665
COPY values.yaml .
@@ -82,11 +71,3 @@ schema-base:
8271
DO --pass-args +BASE
8372
RUN apk add --no-cache git
8473
RUN helm plugin install https://github.com/losisin/helm-values-schema-json.git
85-
86-
increment-version:
87-
FROM core+base-image
88-
ARG --required CHART
89-
WORKDIR /src
90-
COPY $CHART/Chart.yaml .
91-
RUN yq eval '.version = "$VERSION"' -i Chart.yaml
92-
SAVE ARTIFACT Chart.yaml AS LOCAL $CHART/Chart.yaml

charts/cloudprem/Earthfile

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@ IMPORT ../console AS console
44
IMPORT ../membership AS membership
55
IMPORT ../portal AS portal
66
IMPORT ../core AS core
7-
IMPORT .. AS root
8-
9-
# svgs:
10-
# FROM minlag/mermaid-cli
11-
# COPY --dir build /data
12-
# RUN mkdir -p /data/svg
13-
# RUN /home/mermaidcli/node_modules/.bin/mmdc -p /puppeteer-config.json -i /data/build/mmd/controlplane.mmd -o /data/svg/controlplane.svg --configFile /data/build/config.json
14-
# SAVE ARTIFACT /data/svg/controlplane.svg AS LOCAL ./controlplane.svg
7+
IMPORT .. AS charts
158

169
schema:
17-
FROM root+schema-base
10+
FROM charts+schema-base
1811
WORKDIR /src
19-
DO --pass-args root+SCHEMA
12+
DO --pass-args charts+SCHEMA
2013

2114
readme:
22-
FROM root+readme-base
15+
FROM charts+readme-base
2316
WORKDIR /src/core
2417
COPY --dir (core+dependencies/*) .
2518

@@ -33,15 +26,15 @@ readme:
3326
WORKDIR /src/cloudprem
3427
COPY (+dependencies/*) .
3528
COPY (+schema/*) .
36-
# COPY (+svgs/*) .
3729
COPY *.gotmpl .
38-
DO --pass-args root+README_GENERATOR
30+
DO --pass-args charts+README_GENERATOR
31+
3932
sources:
40-
DO --pass-args root+BASE
33+
DO --pass-args charts+BASE
4134
WORKDIR /src/cloudprem
4235
COPY --dir profiles .
4336
COPY (+schema/*) .
44-
DO --pass-args root+SOURCES
37+
DO --pass-args charts+SOURCES
4538

4639
dependencies:
4740
FROM +sources
@@ -52,20 +45,15 @@ dependencies:
5245
WORKDIR /src/portal
5346
COPY --dir (portal+dependencies/*) .
5447
WORKDIR /src/cloudprem
55-
DO --pass-args root+DEPENDENCIES
48+
DO --pass-args charts+DEPENDENCIES
5649

5750
validate:
5851
FROM +dependencies
5952
WORKDIR /src/cloudprem
6053
COPY (+readme/*) .
61-
DO --pass-args root+VALIDATE
54+
DO --pass-args charts+VALIDATE
6255

6356
package:
6457
FROM +validate
6558
WORKDIR /src/cloudprem
66-
DO --pass-args root+PACKAGE
67-
68-
publish:
69-
FROM +package
70-
WORKDIR /src/cloudprem
71-
DO --pass-args root+PUBLISH
59+
DO --pass-args charts+PACKAGE

charts/cloudprem/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ helm install cloudprem oci://ghcr.io/formancehq/helm/cloudprem \
3333
- Membership > 0.28.0
3434
- Dex > 0.28.0
3535

36-
<!-- ![diagram](./controlplane.svg) -->
37-
3836
## Introduction
3937

4038
This chart bootstraps 5 different components that form the Formance Control Plane, additionally you will need to install the Formance Data Plane composed of a Kubernetes Operator.

charts/cloudprem/README.md.gotmpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ helm install cloudprem oci://ghcr.io/formancehq/helm/cloudprem \
3333
- Membership > 0.28.0
3434
- Dex > 0.28.0
3535

36-
<!-- ![diagram](./controlplane.svg) -->
37-
3836
## Introduction
3937

4038
This chart bootstraps 5 different components that form the Formance Control Plane, additionally you will need to install the Formance Data Plane composed of a Kubernetes Operator.

0 commit comments

Comments
 (0)