From 0f89b9ba8dc75ca986ea6c9713b5ceb4cbfaaa9f Mon Sep 17 00:00:00 2001 From: Giacomo Guiulfo Date: Sat, 6 Oct 2018 11:38:33 -0700 Subject: [PATCH] [stable/prisma]: add Prisma chart (#6483) Signed-off-by: Giacomo Guiulfo --- stable/prisma/.helmignore | 22 +++++ stable/prisma/Chart.yaml | 13 +++ stable/prisma/OWNERS | 4 + stable/prisma/README.md | 77 +++++++++++++++ stable/prisma/ci/example-values.yaml | 2 + stable/prisma/requirements.lock | 6 ++ stable/prisma/requirements.yaml | 5 + stable/prisma/templates/NOTES.txt | 19 ++++ stable/prisma/templates/_helpers.tpl | 88 +++++++++++++++++ stable/prisma/templates/configmap.yaml | 23 +++++ stable/prisma/templates/deployment.yaml | 78 +++++++++++++++ stable/prisma/templates/ingress.yaml | 39 ++++++++ stable/prisma/templates/secret.yaml | 24 +++++ stable/prisma/templates/service.yaml | 19 ++++ stable/prisma/values.yaml | 125 ++++++++++++++++++++++++ 15 files changed, 544 insertions(+) create mode 100644 stable/prisma/.helmignore create mode 100644 stable/prisma/Chart.yaml create mode 100644 stable/prisma/OWNERS create mode 100644 stable/prisma/README.md create mode 100644 stable/prisma/ci/example-values.yaml create mode 100644 stable/prisma/requirements.lock create mode 100644 stable/prisma/requirements.yaml create mode 100644 stable/prisma/templates/NOTES.txt create mode 100644 stable/prisma/templates/_helpers.tpl create mode 100644 stable/prisma/templates/configmap.yaml create mode 100644 stable/prisma/templates/deployment.yaml create mode 100644 stable/prisma/templates/ingress.yaml create mode 100644 stable/prisma/templates/secret.yaml create mode 100644 stable/prisma/templates/service.yaml create mode 100644 stable/prisma/values.yaml diff --git a/stable/prisma/.helmignore b/stable/prisma/.helmignore new file mode 100644 index 0000000000..7c04072e13 --- /dev/null +++ b/stable/prisma/.helmignore @@ -0,0 +1,22 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj +OWNERS diff --git a/stable/prisma/Chart.yaml b/stable/prisma/Chart.yaml new file mode 100644 index 0000000000..7a7a30589a --- /dev/null +++ b/stable/prisma/Chart.yaml @@ -0,0 +1,13 @@ +name: prisma +version: 0.1.0 +appVersion: 1.15 +kubeVersion: "^1.8.0-0" +description: Prisma turns your database into a realtime GraphQL API +home: https://www.prisma.io/ +icon: https://i.imgur.com/wD4rVt4.png +sources: + - https://github.com/prismagraphql/prisma +maintainers: + - name: giacomoguiulfo + email: giacomoguiulfo@gmail.com +engine: gotpl diff --git a/stable/prisma/OWNERS b/stable/prisma/OWNERS new file mode 100644 index 0000000000..fa510b0036 --- /dev/null +++ b/stable/prisma/OWNERS @@ -0,0 +1,4 @@ +approvers: +- giacomoguiulfo +reviewers: +- giacomoguiulfo diff --git a/stable/prisma/README.md b/stable/prisma/README.md new file mode 100644 index 0000000000..1a3797ceb3 --- /dev/null +++ b/stable/prisma/README.md @@ -0,0 +1,77 @@ +# Prisma Helm Chart + +[Prisma](https://prisma.io) is a performant open-source GraphQL ORM-like layer doing the heavy lifting in your GraphQL server. + +## TL;DR; + +```bash +$ helm install stable/prisma +``` + +## Introduction + +This chart bootstraps a Prisma deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +**Note**: This chart doesn't support horizontal scaling for Prisma yet. + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```bash +$ helm install --name my-release stable/prisma +``` + +**Note**: Prisma requires a properly configured database in order to initialize. See the `values.yaml` file for the configuration values that need to be set. Also, if preferred you can set `postgresql.enabled` to `true` and Helm will deploy the PostgreSQL chart listed in the `requirements.yaml` file, and Prisma will be able to initialize properly using the default values. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```bash +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following table lists the configurable parameters of the Prisma chart and their default values. + +Parameter | Description | Default +-------------------------------- | -------------------------------------------- | --------------------------------------------------------- +`image.repository` | Prisma image repository | `prismagraphql/prisma` +`image.tag` | Prisma image tag | `1.15-heroku` +`image.pullPolicy` | Image pull policy | `IfNotPresent` +`database.connector` | Database connector | `postgres` +`database.host` | Host for the database endpoint | `""` +`database.port` | Port for the database endpoint | `""` +`database.user` | Database user | `prisma` +`database.password` | Database password | `""` +`database.migrations` | Enable database migrations | `true` +`auth.enabled` | Enable Prisma Management API authentication | `false` +`auth.secret` | Secret to use for authentication | `nil` +`service.type` | Type of Service | `ClusterIP` +`service.port` | Service TCP port | `4466` +`ingress.enabled` | Enables Ingress | `false` +`ingress.annotations` | Ingress annotations | `{}` +`ingress.path` | Ingress path | `/` +`ingress.hosts` | Ingress accepted hostnames | `[]` +`ingress.tls` | Ingress TLS configuration | `[]` +`resources` | CPU/Memory resource requests/limits | `{}` +`nodeSelector` | Node labels for pod assignment | `{}` +`affinity` | Affinity settings for pod assignment | `{}` +`tolerations` | Toleration labels for pod assignment | `[]` +`postgresql.enabled` | Install PostgreSQL chart | `false` +`postgresql.imagePullPolicy` | PostgreSQL image pull policy | `Always` if `imageTag` is `latest`, else `IfNotPresent` +`postgresql.persistence.enabled` | Persist data to a PV | `false` +`postgresql.postgresUser` | Username of new user to create | `prisma` +`postgresql.postgresPassword` | Password for the new user | `""` +`postgresql.service.port` | PostgreSQL service TCP port | `5432` +`postgresql.resources` | PostgreSQL resource requests and limits | Memory: `256Mi`, CPU: `100m` + +Additional configuration parameters for the PostgreSQL database deployed with Prisma can be found [here](https://github.com/kubernetes/charts/tree/master/stable/postgresql). + +> **Tip**: You can use the default [values.yaml](values.yaml) diff --git a/stable/prisma/ci/example-values.yaml b/stable/prisma/ci/example-values.yaml new file mode 100644 index 0000000000..dae90ef23d --- /dev/null +++ b/stable/prisma/ci/example-values.yaml @@ -0,0 +1,2 @@ +postgresql: + enabled: true diff --git a/stable/prisma/requirements.lock b/stable/prisma/requirements.lock new file mode 100644 index 0000000000..3d5b30e116 --- /dev/null +++ b/stable/prisma/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: postgresql + repository: https://kubernetes-charts.storage.googleapis.com/ + version: 0.15.0 +digest: sha256:bbc1e13abc845c3e5cad4c328105a9c50ee5692d73547065ffbf63f15e6fd533 +generated: 2018-08-09T17:19:54.160902267-07:00 diff --git a/stable/prisma/requirements.yaml b/stable/prisma/requirements.yaml new file mode 100644 index 0000000000..a6b478921d --- /dev/null +++ b/stable/prisma/requirements.yaml @@ -0,0 +1,5 @@ +dependencies: +- name: postgresql + version: ~0.15.0 + repository: "https://kubernetes-charts.storage.googleapis.com/" + condition: postgresql.enabled diff --git a/stable/prisma/templates/NOTES.txt b/stable/prisma/templates/NOTES.txt new file mode 100644 index 0000000000..80e0767701 --- /dev/null +++ b/stable/prisma/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "prisma.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ template "prisma.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "prisma.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "prisma.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:4466 +{{- end }} diff --git a/stable/prisma/templates/_helpers.tpl b/stable/prisma/templates/_helpers.tpl new file mode 100644 index 0000000000..e9f2f6c144 --- /dev/null +++ b/stable/prisma/templates/_helpers.tpl @@ -0,0 +1,88 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "prisma.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "prisma.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "prisma.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified postgresql name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "prisma.postgresql.fullname" -}} +{{- $name := default "postgresql" .Values.postgresql.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified name for the secret that contains the database password. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "prisma.databaseSecret.fullname" -}} +{{- if .Values.postgresql.enabled -}} +{{- include "prisma.postgresql.fullname" . }} +{{- else -}} +{{- include "prisma.fullname" . }} +{{- end -}} +{{- end -}} + +{{/* +Set the proper name for the secretKeyRef key that contains the database password. +*/}} +{{- define "prisma.databaseSecret.key" -}} +{{- if .Values.postgresql.enabled -}} +postgres-password +{{- else -}} +db-password +{{- end -}} +{{- end -}} + +{{/* +Set the proper database host. If postgresql is installed as part of this chart, use the default service name, +else use user-provided host +*/}} +{{- define "prisma.database.host" }} +{{- if .Values.postgresql.enabled -}} +{{- include "prisma.postgresql.fullname" . }} +{{- else -}} +{{- .Values.database.host | quote }} +{{- end -}} +{{- end -}} + +{{/* +Set the proper database port. If postgresql is installed as part of this chart, use the default postgresql port, +else use user-provided port +*/}} +{{- define "prisma.database.port" }} +{{- if .Values.postgresql.enabled -}} +{{- default "5432" ( .Values.postgresql.service.port | quote ) }} +{{- else -}} +{{- .Values.database.port | quote }} +{{- end -}} +{{- end -}} diff --git a/stable/prisma/templates/configmap.yaml b/stable/prisma/templates/configmap.yaml new file mode 100644 index 0000000000..e95d1b1d47 --- /dev/null +++ b/stable/prisma/templates/configmap.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "prisma.fullname" . }} + labels: + app: {{ template "prisma.name" . }} + chart: {{ template "prisma.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: + config: | + port: 4466 + {{- if .Values.auth.enabled }} + managementApiSecret: $PRISMA_API_SECRET + {{- end }} + databases: + default: + connector: $PRISMA_DB_CONNECTOR + host: $PRISMA_DB_HOST + port: $PRISMA_DB_PORT + user: $PRISMA_DB_USER + password: $PRISMA_DB_PASSWORD + migrations: $PRISMA_DB_MIGRATIONS diff --git a/stable/prisma/templates/deployment.yaml b/stable/prisma/templates/deployment.yaml new file mode 100644 index 0000000000..a6ac9b9cdd --- /dev/null +++ b/stable/prisma/templates/deployment.yaml @@ -0,0 +1,78 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "prisma.fullname" . }} + labels: + app: {{ template "prisma.name" . }} + chart: {{ template "prisma.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ template "prisma.name" . }} + release: {{ .Release.Name }} + strategy: + type: Recreate + template: + metadata: + labels: + app: {{ template "prisma.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: prisma + containerPort: 4466 + protocol: TCP + env: + - name: CONFIG + valueFrom: + configMapKeyRef: + name: {{ template "prisma.fullname" . }} + key: config + {{- if .Values.auth.secret }} + - name: PRISMA_API_SECRET + valueFrom: + secretKeyRef: + name: {{ template "prisma.fullname" . }} + key: api-secret + {{- end}} + - name: PRISMA_CONFIG_PATH + value: "/app/config.yml" + - name: PRISMA_DB_CONNECTOR + value: {{ .Values.database.connector | quote }} + - name: PRISMA_DB_HOST + value: {{ template "prisma.database.host" . }} + - name: PRISMA_DB_PORT + value: {{ template "prisma.database.port" . }} + - name: PRISMA_DB_USER + valueFrom: + secretKeyRef: + name: {{ template "prisma.fullname" . }} + key: db-user + - name: PRISMA_DB_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "prisma.databaseSecret.fullname" . }} + key: {{ template "prisma.databaseSecret.key" . }} + - name: PRISMA_DB_MIGRATIONS + value: {{ .Values.database.migrations | quote }} + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} diff --git a/stable/prisma/templates/ingress.yaml b/stable/prisma/templates/ingress.yaml new file mode 100644 index 0000000000..2387595e17 --- /dev/null +++ b/stable/prisma/templates/ingress.yaml @@ -0,0 +1,39 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "prisma.fullname" . -}} +{{- $servicePort := .Values.service.port -}} +{{- $ingressPath := .Values.ingress.path -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + app: {{ template "prisma.name" . }} + chart: {{ template "prisma.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{- with .Values.ingress.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $servicePort }} + {{- end }} +{{- end }} diff --git a/stable/prisma/templates/secret.yaml b/stable/prisma/templates/secret.yaml new file mode 100644 index 0000000000..65262ee85d --- /dev/null +++ b/stable/prisma/templates/secret.yaml @@ -0,0 +1,24 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ template "prisma.fullname" . }} + labels: + app: {{ template "prisma.name" . }} + chart: {{ template "prisma.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +type: Opaque +data: + {{- if and .Values.auth.enabled .Values.auth.secret }} + api-secret: {{ .Values.auth.secret | b64enc | quote }} + {{- else if .Values.auth.enabled }} + api-secret: {{ randAlphaNum 40 | b64enc | quote }} + {{- end }} + db-user: {{ .Values.database.user | b64enc | quote }} + {{- if not .Values.postgresql.enabled }} + {{- if .Values.database.password }} + db-password: {{ .Values.database.password | b64enc | quote }} + {{- else }} + db-password: {{ randAlphaNum 40 | b64enc | quote }} + {{- end }} + {{- end }} diff --git a/stable/prisma/templates/service.yaml b/stable/prisma/templates/service.yaml new file mode 100644 index 0000000000..2fbe0bae3f --- /dev/null +++ b/stable/prisma/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "prisma.fullname" . }} + labels: + app: {{ template "prisma.name" . }} + chart: {{ template "prisma.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - name: service + port: {{ .Values.service.port }} + protocol: TCP + targetPort: prisma + selector: + app: {{ template "prisma.name" . }} + release: {{ .Release.Name }} diff --git a/stable/prisma/values.yaml b/stable/prisma/values.yaml new file mode 100644 index 0000000000..fa38b8617c --- /dev/null +++ b/stable/prisma/values.yaml @@ -0,0 +1,125 @@ +# ------------------------------------------------------------------------------ +# Prisma: +# ------------------------------------------------------------------------------ + +image: + ## Prisma image repository + ## + repository: prismagraphql/prisma + + ## Prisma image version + ## + tag: 1.15-heroku + + ## Specify an imagePullPolicy + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + pullPolicy: IfNotPresent + +database: + ## The current supported connectors are [mysql, postgres] + connector: postgres + + ## If 'postgresql.enabled' is 'false', you will need to provide the + ## following values so that Prisma can use them as the database endpoint + host: "" + port: "" + + ## Database credentials + ## + user: prisma + password: "" + + ## Enable database migrations + ## + migrations: true + +auth: + ## Prisma's Management API authentication + ## + enabled: false + + ## Secret to use. If it isn't specified and 'auth.enabled' is set to 'true', + ## a random generated one will be used + ## + # secret: "" + +service: + type: ClusterIP + port: 4466 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + path: / + hosts: [] + # - prisma.local + tls: [] + # - secretName: prisma-tls + # hosts: + # - prisma.local + +resources: {} +# limits: +# cpu: 100m +# memory: 128Mi +# requests: +# cpu: 100m +# memory: 128Mi + +## Node labels for pod assignment +## ref: https://kubernetes.io/docs/user-guide/node-selection/ +## +nodeSelector: {} + +## Tolerations for pod assignment +## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ +## +tolerations: [] + +## Affinity for pod assignment +## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity +## +affinity: {} + +# ------------------------------------------------------------------------------ +# PostgreSQL: +# ------------------------------------------------------------------------------ + +postgresql: + ## If true, install the PostgreSQL chart alongside Prisma + ## ref: https://github.com/kubernetes/charts/tree/master/stable/postgresql + ## + enabled: false + + ## PostgresSQL image version + ## ref: https://hub.docker.com/r/library/postgres/tags/ + ## + imageTag: "9.6.2" + + ## Specify a PostgreSQL imagePullPolicy + ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images + ## + imagePullPolicy: "IfNotPresent" + + ## Persist data to a persistent volume + ## + persistence: + enabled: false + + ## PostgreSQL credentials + ## + postgresUser: prisma + postgresPassword: "" + + ## PostgreSQL service TCP port + ## + service: + port: 5432 + + ## Configure PostgreSQL resource requests and limits + ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ + ## + resources: {}