Skip to content

Commit

Permalink
feat: copy charts from clients repo (#30)
Browse files Browse the repository at this point in the history
* feat: copy chart, improve CI with label chart change

* tools(readme): template readme.md

* wip: readme

* feat: new cloudprem release

* refactor(workflows): update release and PR workflows (#31)

Change release trigger to push on main branch. Add test job
to release workflow, ensuring no changes post-tests. Rename
main.yml to pull_request.yml and update triggers. Use
ubuntu-latest for all jobs. Simplify Earthfile by adding a
ci target for pre-commit, tests, and package.

* 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]>

* feat(Earthfile): update version and simplify chart processing

Update Earthfile to use --wildcard-builds with version 0.8. Simplify
the validation and packaging steps by removing the loop over chart
directories and using wildcard builds for both processes.

* feat: add release target (#33)

* feat: add release workflow

* fix: is mandatory

* chore: clean test sources

---------

Co-authored-by: David Ragot <[email protected]>

---------

Co-authored-by: David Ragot <[email protected]>
Co-authored-by: Maxence Maireaux <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2024
1 parent e0764a7 commit 0f8b332
Show file tree
Hide file tree
Showing 112 changed files with 8,401 additions and 684 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[Earthfile]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2

[*.tpl]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2

[*.{yaml,yml}]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2
12 changes: 12 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
docs:
- changed-files:
- any-glob-to-any-file: "**/*.md"

feature:
- head-branch: ["^feat", "feat"]

bug:
- head-branch: ["^fix", "fix"]

release:
- base-branch: "main"
55 changes: 0 additions & 55 deletions .github/workflows/main.yaml

This file was deleted.

92 changes: 92 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Pull Request
on:
merge_group:
pull_request:
types: [ assigned, opened, synchronize, reopened, labeled, unlabeled ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
labeler:
name: Chart Diff Labeler
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- uses: actions/labeler@v5
with:
sync-labels: true
- name: Retrieve chart changes
id: chart_changes
run: |
CHARTS=$(git diff ${{ github.base_ref }} --stat | grep -oE 'charts/[^/]+/' | sed 's|charts/||;s|/||' | sort -u | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "Changed charts: $CHARTS"
echo "::set-output name=changed_charts::$CHARTS"
- name: Label PR based on chart changes
if: steps.chart_changes.outputs.changed_charts != ''
uses: actions/github-script@v7
env:
CHARTS: ${{ steps.chart_changes.outputs.changed_charts }}
with:
script: |
const charts = JSON.parse(process.env.CHARTS);
const labels = charts.map(chart => `chart-${chart.trim()}`).filter(label => label.length > 0);
if (labels.length > 0) {
console.log(`Applying labels: ${labels.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels
});
} else {
console.log('No charts changed, skipping labeling.');
}
pr_name:
if: github.event_name == 'pull_request'
name: Check PR Title
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Install earthly
uses: earthly/actions-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Tests
run: earthly +ci
- name: Get changed files
id: changed-files
shell: bash
run: |
hasChanged=$(git status --porcelain)
if (( $(echo ${#hasChanged}) != 0 )); then
git status
echo "There are changes in the repository"
exit 1
fi
- name: Archive chart
uses: actions/upload-artifact@v4
with:
name: charts_${{ github.ref_type == 'branch' && github.sha }}.tgz
path: charts/**/*.tgz
retention-days: 3
54 changes: 54 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release
on:
push:
branches:
- main

permissions:
contents: write
packages: write

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Install earthly
uses: earthly/actions-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Tests
run: earthly +ci
- name: Get changed files
id: changed-files
shell: bash
run: |
hasChanged=$(git status --porcelain)
if (( $(echo ${#hasChanged}) != 0 )); then
git status
echo "There are changes in the repository"
exit 1
fi
release:
name: Release
needs:
- tests
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Release
run: earthly +release
env:
EARTHLY_SECRETS: "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}"
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
./dist/
*.tgz
Chart.lock

.DS_Store

dist

charts/**/LICENSE

.tmp-earthly-out
111 changes: 111 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Helm Charts

## Working Per Chart

### Building the Charts

Each chart must implement the common targets interface with the following minimum required files:

- `Chart.yaml`
- `Earthfile`

Each `Earthfile` Chart **must** implement the following targets to integrate with the CI:

- `+sources`: Raw sources of the chart without the dependencies.
> [!IMPORTANT]
> A LICENSE file is included in every chart through the helper [SOURCE](./charts/Earthfile)
- `+dependencies`: Raw sources with dependencies updated.
- `+validate`: Validates the chart, including its dependencies.
- `+package`: Packages the chart from validated sources.
- `+readme`: (Optional): Include README when dependendies are validated.
> The README file is generated with `helm-docs` and included in the chart through the helper [README_GENERATOR](./charts/Earthfile).
> [!TIP]
> A file named `README.md.gotmpl` can be added to the chart to customize the README generation.
- `+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.


### Core Library

Each chart must implement the core Helm library as a dependency to include the common helpers for:

- Improve resource naming
- [Kubernetes recommended labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/)
- Values naming

- Global values structure accross all charts, including settings
- Monitoring
- Traces(OTLP)
- Metrics(OTLP)
- Logs(JSON)
- Storage
- PostgreSQL (Bitnami) (Internal or External)
- Nats (Nats.io) (Internal)

- (Optionals):

- AWS IAM
- AWS Target Groups
- Ingress
- PodDisruptionBudget
- HorizontalPodAutoscaler
- ServiceAccount
- RBAC
- NetworkPolicy

## Validate repository changes

To validate the all the changes arround the repository, run the following command:

```bash
earthly +pre-commit
```

1. First run
once running it for the first time, it will build all the dependencies and validate all the charts and the charts.

2. Second run
It will validate the future changes only where it needs to be validated thanks to caches.

## Tests core and charts

- Naming conventions for included resource
- Labels selection
- Default environment variables bindings
- Resources disablings
- HorizontalPodAutoscaler
- Ingress
- PodDisruptionBudget
- Subchart disabling
- Secret mapping
- Configmap mapping
- Managed Stacks Features: Disable GRPC communication with any type of Agent

## CI: GitHub Actions

The CI is based on GitHub Actions, triggered on each PR and the main branch. It is composed of the following workflows:

- **Pull Request**: PR
- Validates the PR name.
- Labels the PR with the charts who have changed in the `charts/` directory.
- Lint, Template, Generate Readmes for any charts who has changed. And Test Requirements accross on all charts `earthly +ci`.
- **Release**: Main
- Lint, Template, Generate Readmes for any charts who has changed. And Test Requirements accross on all charts `earthly +ci`.
- Release any `Chart.yaml` `.version` that have been upgraded.
- `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.

## CD: from sources

External repositories can rely on the `+package` target and artifact to deploy from a specific branch or tag.

```bash
earthly github.com/formancehq/helm/charts/cloudprem+package
```

## CD: from Helm repository

The helm repository is `ghcr.io/formancehq/helm` and can be used to deploy the charts.

```bash
helm upgrade --install regions ghcr.io/formancehq/helm/regions --version v2.0.18
```
Loading

0 comments on commit 0f8b332

Please sign in to comment.