From 01930a2b0f810edf22e507a396f799db3c2eceed Mon Sep 17 00:00:00 2001 From: NivEz Date: Mon, 29 Jan 2024 00:26:08 +0200 Subject: [PATCH] added helm chart --- .gitignore | 4 +++- .helm/.helmignore | 25 ++++++++++++++++++++++ .helm/Chart.yaml | 18 ++++++++++++++++ .helm/README.md | 18 ++++++++++++++++ .helm/templates/app-env-secret.yaml | 8 +++++++ .helm/templates/deployment.yaml | 29 ++++++++++++++++++++++++++ .helm/templates/image-pull-secret.tpl | 5 +++++ .helm/templates/image-pull-secret.yaml | 8 +++++++ .helm/templates/ingress.yaml | 18 ++++++++++++++++ .helm/templates/service.yaml | 15 +++++++++++++ .helm/values.yaml | 15 +++++++++++++ .prettierignore | 5 ++++- 12 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 .helm/.helmignore create mode 100644 .helm/Chart.yaml create mode 100644 .helm/README.md create mode 100644 .helm/templates/app-env-secret.yaml create mode 100644 .helm/templates/deployment.yaml create mode 100644 .helm/templates/image-pull-secret.tpl create mode 100644 .helm/templates/image-pull-secret.yaml create mode 100644 .helm/templates/ingress.yaml create mode 100644 .helm/templates/service.yaml create mode 100644 .helm/values.yaml diff --git a/.gitignore b/.gitignore index 4a354ff..5c71c44 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ yarn-error.log* .env -data \ No newline at end of file +data + +values-local.yaml \ No newline at end of file diff --git a/.helm/.helmignore b/.helm/.helmignore new file mode 100644 index 0000000..222a0e5 --- /dev/null +++ b/.helm/.helmignore @@ -0,0 +1,25 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ + +README.md \ No newline at end of file diff --git a/.helm/Chart.yaml b/.helm/Chart.yaml new file mode 100644 index 0000000..9743da3 --- /dev/null +++ b/.helm/Chart.yaml @@ -0,0 +1,18 @@ +apiVersion: v2 +name: movie-info-bot +description: A Helm chart for movie-info-bot + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 diff --git a/.helm/README.md b/.helm/README.md new file mode 100644 index 0000000..24f156a --- /dev/null +++ b/.helm/README.md @@ -0,0 +1,18 @@ +# Helm setup + +The file `values-local.yaml` is git ignored so it can be used with sensitive data. + +### Install the chart (using values-local.yaml from local machine) +``` +helm install -f .helm/values-local.yaml movie-info-bot ./.helm --atomic --debug --namespace movie-info-bot --create-namespace +``` + +### Upgrade the chart +``` +helm upgrade -f .helm/values-local.yaml movie-info-bot ./.helm --atomic --debug --reuse-values +``` + +### Uninstall +``` +helm uninstall movie-info-bot --namespace movie-info-bot +``` \ No newline at end of file diff --git a/.helm/templates/app-env-secret.yaml b/.helm/templates/app-env-secret.yaml new file mode 100644 index 0000000..9fa01c5 --- /dev/null +++ b/.helm/templates/app-env-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: 'app-env-vars' + namespace: {{ .Values.appName }} +type: Opaque +stringData: + API_TOKEN: {{ .Values.appEnv.apiToken }} diff --git a/.helm/templates/deployment.yaml b/.helm/templates/deployment.yaml new file mode 100644 index 0000000..d43a4d0 --- /dev/null +++ b/.helm/templates/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.appName }} + namespace: {{ .Values.appName }} + labels: + app: {{ .Values.appName }} +spec: + selector: + matchLabels: + app: {{ .Values.appName }} + template: + metadata: + labels: + app: {{ .Values.appName }} + spec: + containers: + - name: {{ .Values.appName }} + image: {{ .Values.deployment.image }} + ports: + - containerPort: 3000 + env: + - name: API_TOKEN + valueFrom: + secretKeyRef: + name: app-env-vars + key: API_TOKEN + imagePullSecrets: + - name: registry-credentials diff --git a/.helm/templates/image-pull-secret.tpl b/.helm/templates/image-pull-secret.tpl new file mode 100644 index 0000000..5de4af3 --- /dev/null +++ b/.helm/templates/image-pull-secret.tpl @@ -0,0 +1,5 @@ +{{- define "imagePullSecret" }} +{{- with .Values.imageCredentials }} +{{- printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .registry .username .password .email (printf "%s:%s" .username .password | b64enc) | b64enc }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/.helm/templates/image-pull-secret.yaml b/.helm/templates/image-pull-secret.yaml new file mode 100644 index 0000000..f70aff2 --- /dev/null +++ b/.helm/templates/image-pull-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: registry-credentials + namespace: {{ .Values.appName }} +type: kubernetes.io/dockerconfigjson +data: + .dockerconfigjson: {{ template "imagePullSecret" . }} diff --git a/.helm/templates/ingress.yaml b/.helm/templates/ingress.yaml new file mode 100644 index 0000000..54591d0 --- /dev/null +++ b/.helm/templates/ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + namespace: {{ .Values.appName }} + name: {{ .Values.appName }} +spec: + ingressClassName: nginx + rules: + - host: {{ .Values.ingress.host }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ .Values.appName }} + port: + number: 80 diff --git a/.helm/templates/service.yaml b/.helm/templates/service.yaml new file mode 100644 index 0000000..c25a1c6 --- /dev/null +++ b/.helm/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.appName }} + namespace: {{ .Values.appName }} + labels: + app: {{ .Values.appName }} +spec: + selector: + app: {{ .Values.appName }} + ports: + - name: http + protocol: TCP + port: 80 + targetPort: 3000 diff --git a/.helm/values.yaml b/.helm/values.yaml new file mode 100644 index 0000000..6e484a6 --- /dev/null +++ b/.helm/values.yaml @@ -0,0 +1,15 @@ +appName: movie-info-bot + +deployment: + image: '' + +ingress: + host: '' + +appEnv: + apiToken: '' + +imageCredentials: + registry: '' + username: '' + password: '' diff --git a/.prettierignore b/.prettierignore index 4f49a14..f17da42 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,4 +8,7 @@ node_modules README.md package-lock.json -yarn.lock \ No newline at end of file +yarn.lock + +.helm/**/*.yaml +.helm/**/*.yml \ No newline at end of file