diff --git a/.github/workflows/charts-lint-test.yaml b/.github/workflows/charts-lint-test.yaml index b3585098..6340ec5c 100644 --- a/.github/workflows/charts-lint-test.yaml +++ b/.github/workflows/charts-lint-test.yaml @@ -1,6 +1,6 @@ name: "Charts: Lint and test" -on: +on: pull_request: paths: - 'charts/**' @@ -38,14 +38,14 @@ jobs: echo "::set-output name=changed::true" fi - changed_unfiltered=$(ct list-changed --config .github/ct.yaml --excluded-charts "") + changed_unfiltered=$(ct list-changed --config .github/ct.yaml --excluded-charts ".template") if [[ $(grep -E "^charts/common(-test)?$" <<< "$changed_unfiltered") ]]; then echo "::set-output name=common::true" fi - name: Run chart-testing (lint) id: lint - run: ct lint --config .github/ct.yaml --excluded-charts "" + run: ct lint --config .github/ct.yaml --excluded-charts ".template" if: steps.list-changed.outputs.changed == 'true' || steps.list-changed.outputs.common == 'true' unittest: @@ -68,13 +68,13 @@ jobs: - name: Install Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - + ruby-version: 2.7 + - name: Install dependencies run: | export RUBYJQ_USE_SYSTEM_LIBRARIES=1 bundle install - + - name: Run tests run: | bundle exec m -r test/charts @@ -105,7 +105,7 @@ jobs: if: needs.lint.outputs.changed == 'true' || needs.lint.outputs.common == 'true' - name: Run chart-testing (install) - run: ct install --config .github/ct.yaml + run: ct install --config .github/ct.yaml --excluded-charts ".template" if: needs.lint.outputs.changed == 'true' - name: Run chart-testing (common-test) diff --git a/.gitignore b/.gitignore index 8b579320..fcbe60fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Developer dependencies +.bin + # IDE resources .vscode .idea @@ -9,4 +12,6 @@ charts/*/charts # Other rsources .env +.envrc Gemfile.lock +.helmignore diff --git a/.taskfiles/Taskfile_chart.yml b/.taskfiles/Taskfile_chart.yml new file mode 100644 index 00000000..8b5ab605 --- /dev/null +++ b/.taskfiles/Taskfile_chart.yml @@ -0,0 +1,46 @@ +--- +version: '3' + +tasks: + + create: + desc: create new chart + cmds: + - cp -r {{.GIT_ROOT}}/charts/.template {{.GIT_ROOT}}/charts/{{.CHART}} + - ./.bin/go-replace -s '${CHARTNAME}' -r "{{.CHART}}" --path={{.GIT_ROOT}}/charts/{{.CHART}} --path-pattern='*.*' + - task: dependency + - echo "Congratulations, charts/{{.CHART}} successfully generated, you can now edit chart informations ( Chart.yaml and values.yaml )" + status: + - test -d {{.GIT_ROOT}}/charts/{{.CHART}} + deps: + - check-chart + + + dependency: + cmds: + - test -d {{.GIT_ROOT}}/charts/{{.CHART}}/Chart.lock && rm {{.GIT_ROOT}}/charts/{{.CHART}}/Chart.lock || exit 0 + - test -d {{.GIT_ROOT}}/charts/{{.CHART}}/tmpcharts && rm -rf {{.GIT_ROOT}}/charts/{{.CHART}}/tmpcharts || exit 0 + - cd {{.GIT_ROOT}}/charts/{{.CHART}} && helm dependency update + silent: true + + lint: + desc: lint your chart code + cmds: + - cd {{.GIT_ROOT}}/charts/{{.CHART}} && helm lint + deps: + - dependency + - check-chart + + test: + desc: test your chart code + cmds: + - docker run --rm -it --user $(id -u):$(id -g) -e "HELM_CONFIG_HOME=/tmp/helm" -e "HELM_CACHE_HOME=/tmp/helm" -v {{.GIT_ROOT}}:/ci -w /ci quay.io/helmpack/chart-testing:latest ct lint --charts charts/{{.CHART}} --config /ci/.github/ct.yaml + deps: + - check-chart + - lint + + # Checks Parameters + check-chart: + cmds: + - cmd: test ! -z "{{.CHART}}" || (echo "Please define CHART parameter"; exit 1) + silent: true diff --git a/.taskfiles/Taskfile_darwin.yml b/.taskfiles/Taskfile_darwin.yml new file mode 100644 index 00000000..f40535ef --- /dev/null +++ b/.taskfiles/Taskfile_darwin.yml @@ -0,0 +1,10 @@ +--- +version: '3' + +# Todo: add darwin requirements + +tasks: + default: + cmds: + - task -l + silent: true diff --git a/.taskfiles/Taskfile_linux.yml b/.taskfiles/Taskfile_linux.yml new file mode 100644 index 00000000..f07c6ddc --- /dev/null +++ b/.taskfiles/Taskfile_linux.yml @@ -0,0 +1,67 @@ +--- +version: '3' + +env: + URL_GOREPLACE: https://github.com/webdevops/go-replace/releases/download/1.1.2/gr-64-linux + URL_HELM: https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 + +tasks: + + install: + desc: Install all developer dependencies + deps: + - distrib-requirements + - helm + - pre-commit + - go-replace + + distrib-requirements: + desc: Check needed distribution packages + cmds: + - task deps:need BIN=wget + - task deps:need BIN=python3 + - task deps:need BIN=docker + silent: true + + need: + desc: Check needed binary is present + cmds: + - type {{.BIN}} 2>&1 >/dev/null || (echo "Please install {{.BIN}}"; exit 1) + silent: true + + helm: + desc: Install helm client + cmds: + - wget -q -O - "$URL_HELM" | USE_SUDO=false HELM_INSTALL_DIR=.bin bash + status: + - test -e .bin/helm + deps: + - distrib-requirements + + pre-commit: + desc: Install a precommit pip package + cmds: + - python3 -m pip install --user pre-commit + status: + - type pre-commit + deps: + - distrib-requirements + + # env-replacer: + # desc: Install env-replace binary + # cmds: + # - wget -q "$URL_ENVREPLACER" -O - | tar -xz -C .bin && chmod +x .bin/env-replacer + # status: + # - test -e .bin/env-replacer + # deps: + # - distrib-requirements + + go-replace: + desc: Install go-replace + cmds: +# - echo wget -q "$URL_GOREPLACE" -O - | tar -xz -C .bin/ && chmod +x .bin/go-replace + - wget -q "$URL_GOREPLACE" -O .bin/go-replace && chmod +x .bin/go-replace + status: + - test -e .bin/go-replace + deps: + - distrib-requirements diff --git a/.taskfiles/Taskfile_windows.yml b/.taskfiles/Taskfile_windows.yml new file mode 100644 index 00000000..62e1c77f --- /dev/null +++ b/.taskfiles/Taskfile_windows.yml @@ -0,0 +1,10 @@ +--- +version: '3' + +# Todo: add windows requirements + +tasks: + default: + cmds: + - task -l + silent: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 591bd599..a41d0a6b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,23 @@ See `git help commit`: Once changes have been merged, the release job will automatically run to package and release changed charts. +### Create new chart +``` +# Clone +git clone +cd charts +sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b .bin + +# Create chart +PATH=$PATH:$PWD/.bin +task chart:create CHART=chart_name +# Don't forgot edit some chart informations in charts/char_name/Chart.yaml and charts/char_name/values.yaml + +# Lint & Test +task chart:lint CHART=chart_name +task chart:test CHART=chart_name +``` + ### Immutability Chart releases must be immutable. Any change to a chart warrants a chart version bump even if it is only changed to the documentation. diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000..2b9f5618 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,16 @@ +--- +version: '3' + +vars: + GIT_ROOT: + sh: git rev-parse --show-toplevel + +includes: + deps: .taskfiles/Taskfile_{{OS}}.yml + chart: .taskfiles/Taskfile_chart.yml + +tasks: + default: + cmds: + - task -l + silent: true diff --git a/charts/.template/Chart.yaml b/charts/.template/Chart.yaml new file mode 100644 index 00000000..60bbcf4d --- /dev/null +++ b/charts/.template/Chart.yaml @@ -0,0 +1,19 @@ +apiVersion: v2 +appVersion: 1.0.0 +description: ${CHARTNAME} helm package +name: ${CHARTNAME} +version: 1.0.0 +keywords: + - ${CHARTNAME} +home: https://github.com/k8s-at-home/charts/tree/master/charts/${CHARTNAME} +icon: https://${CHARTNAME}.org/icon +sources: + - https://github.com/${CHARTNAME}/${CHARTNAME}-docker + - https://github.com/k8s-at-home/charts/tree/master/charts/${CHARTNAME} +maintainers: + - name: ${CHARTNAME} + email: ${CHARTNAME}@${CHARTNAME}.com +dependencies: + - name: common + repository: https://k8s-at-home.com/charts/ + version: 2.2.1 diff --git a/charts/.template/OWNERS b/charts/.template/OWNERS new file mode 100644 index 00000000..1ce35762 --- /dev/null +++ b/charts/.template/OWNERS @@ -0,0 +1,8 @@ +approvers: +- billimek +- onedr0p +- bjw-s +reviewers: +- billimek +- onedr0p +- bjw-s diff --git a/charts/.template/README.md b/charts/.template/README.md new file mode 100644 index 00000000..6689e368 --- /dev/null +++ b/charts/.template/README.md @@ -0,0 +1,68 @@ +# ${CHARTNAME} + +This is a helm chart for [${CHARTNAME}](https://${CHARTNAME}.org/). + +**This chart is not maintained by the upstream project and any issues with the chart should be raised [here](https://github.com/k8s-at-home/charts/issues/new/choose)** + +## TL;DR; + +```shell +$ helm repo add k8s-at-home https://k8s-at-home.com/charts/ +$ helm install k8s-at-home/${CHARTNAME} +``` + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +helm install --name my-release k8s-at-home/${CHARTNAME} +``` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +helm delete my-release --purge +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration +Read through the charts [values.yaml](https://github.com/k8s-at-home/charts/blob/master/charts/${CHARTNAME}/values.yaml) +file. It has several commented out suggested values. +Additionally you can take a look at the common library [values.yaml](https://github.com/k8s-at-home/charts/blob/master/charts/common/values.yaml) for more (advanced) configuration options. + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, +```console +helm install ${CHARTNAME} \ + --set env.TZ="America/New_York" \ + k8s-at-home/${CHARTNAME} +``` +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the +chart. For example, +```console +helm install ${CHARTNAME} k8s-at-home/${CHARTNAME} --values values.yaml +``` + +These values will be nested as it is a dependency, for example +```yaml +image: + tag: ... +``` + +--- +**NOTE** + +If you get +```console +Error: rendered manifests contain a resource that already exists. Unable to continue with install: existing resource conflict: ...` +``` +it may be because you uninstalled the chart with `skipuninstall` enabled, you need to manually delete the pvc or use `existingClaim`. + +--- + +## Upgrading an existing Release to a new major version + +A major chart version change (like 4.0.1 -> 5.0.0) indicates that there is an incompatible breaking change potentially needing manual actions. diff --git a/charts/.template/templates/NOTES.txt b/charts/.template/templates/NOTES.txt new file mode 100644 index 00000000..90f7b653 --- /dev/null +++ b/charts/.template/templates/NOTES.txt @@ -0,0 +1 @@ +{{- include "common.notes.defaultNotes" . -}} diff --git a/charts/.template/templates/common.yaml b/charts/.template/templates/common.yaml new file mode 100644 index 00000000..a6613c2c --- /dev/null +++ b/charts/.template/templates/common.yaml @@ -0,0 +1 @@ +{{ include "common.all" . }} diff --git a/charts/.template/values.yaml b/charts/.template/values.yaml new file mode 100644 index 00000000..129da473 --- /dev/null +++ b/charts/.template/values.yaml @@ -0,0 +1,24 @@ +# Default values for ${CHARTNAME}. + +image: + repository: ${CHARTNAME}/${CHARTNAME} + pullPolicy: IfNotPresent + tag: 1.2.5 + +strategy: + type: Recreate + +# See more environment varaibles in the ${CHARTNAME} documentation +# https://${CHARTNAME}.org/docs +env: {} + # TZ: + +service: + port: + port: 1880 + +# persistence: +# data: +# enabled: false +# emptyDir: false +# mountPath: /data