diff --git a/charts/api/Chart.yaml b/charts/api/Chart.yaml new file mode 100644 index 0000000..d6fe47f --- /dev/null +++ b/charts/api/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: api +description: api + +# 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: 1.0.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/charts/api/README b/charts/api/README new file mode 100644 index 0000000..ed1e532 --- /dev/null +++ b/charts/api/README @@ -0,0 +1 @@ +# This should appear as readme in artifacthub \ No newline at end of file diff --git a/charts/api/templates/_helpers.tpl b/charts/api/templates/_helpers.tpl new file mode 100644 index 0000000..802e601 --- /dev/null +++ b/charts/api/templates/_helpers.tpl @@ -0,0 +1,84 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "api.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 "api.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 "api.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "api.labels" -}} +helm.sh/chart: {{ include "api.chart" . }} +{{ include "api.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "api.selectorLabels" -}} +app.kubernetes.io/name: {{ include "api.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "api.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "api.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Convert camelCase to snake_case +*/}} +{{- define "api.camelToSnakeCase" -}} +{{- $result := "" -}} +{{- $prevLower := false -}} +{{- range $i, $r := . -}} + {{- $current := printf "%c" $r -}} + {{- if and (ne $i 0) (eq ($current | upper) $current) -}} + {{- if $prevLower -}} + {{- $result = print $result "_" | lower -}} + {{- end -}} + {{- $result = print $result $current | lower -}} + {{- $prevLower = false -}} + {{- else -}} + {{- $result = print $result $current -}} + {{- $prevLower = true -}} + {{- end -}} +{{- end -}} +{{- $result -}} +{{- end -}} \ No newline at end of file diff --git a/charts/api/templates/create-tables.yaml b/charts/api/templates/create-tables.yaml new file mode 100644 index 0000000..85cb0ce --- /dev/null +++ b/charts/api/templates/create-tables.yaml @@ -0,0 +1,17 @@ +{{- if .Values.initContainer.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: schema-init-{{ include "api.fullname" . }} +data: +{{- with .Values.initContainer }} + schema-init.sh: | + #!/bin/sh + until curl --location --request PUT {{ .clickhouseSink }}/schema/sql?schema-url={{ .schemaUrl }}; do + echo "Waiting for substreams-sink-clickhouse..." + sleep 5 + done + echo "Tables created successfully" + exit 0 +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/api/templates/deployment.yaml b/charts/api/templates/deployment.yaml new file mode 100644 index 0000000..64059e5 --- /dev/null +++ b/charts/api/templates/deployment.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "api.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + app: {{ include "api.fullname" . }} +spec: + selector: + matchLabels: + app: {{ include "api.fullname" . }} + replicas: 1 + template: + metadata: + labels: + app: {{ include "api.fullname" . }} + spec: + {{- if .Values.initContainer.enabled }} + initContainers: + - name: schema-init + image: curlimages/curl:8.6.0 + command: ["/bin/sh", "-c", "/scripts/schema-init.sh"] + volumeMounts: + - name: script-volume + mountPath: /scripts + {{- end }} + containers: + - name: {{ include "api.fullname" . }} + image: {{ .Values.image }}:{{ .Values.tag }} + ports: + - containerPort: {{ .Values.env.port }} + envFrom: + - configMapRef: + name: env-{{ include "api.fullname" . }} + {{- if .Values.initContainer.enabled }} + volumes: + - name: script-volume + configMap: + name: schema-init-{{ include "api.fullname" . }} + defaultMode: 0777 + {{- end }} \ No newline at end of file diff --git a/charts/api/templates/env.yaml b/charts/api/templates/env.yaml new file mode 100644 index 0000000..7e48ace --- /dev/null +++ b/charts/api/templates/env.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: env-{{ include "api.fullname" . }} +data: + {{- range $key, $val := .Values.env }} + {{- if $val }} + {{ $key | upper }}: {{ $val | quote }} + {{- end }} + {{- end }} \ No newline at end of file diff --git a/charts/api/templates/ingress.yaml b/charts/api/templates/ingress.yaml new file mode 100644 index 0000000..55f2dd2 --- /dev/null +++ b/charts/api/templates/ingress.yaml @@ -0,0 +1,13 @@ +apiVersion: traefik.containo.us/v1alpha1 +kind: IngressRoute +metadata: + name: {{ include "api.fullname" . }} +spec: + entryPoints: + - {{ .Values.ingress.entryPoints }} + routes: + - match: {{ .Values.ingress.match }} + kind: Rule + services: + - name: {{ include "api.fullname" . }} + port: {{ .Values.env.port }} diff --git a/charts/api/templates/secret.yaml b/charts/api/templates/secret.yaml new file mode 100644 index 0000000..7dc1b9e --- /dev/null +++ b/charts/api/templates/secret.yaml @@ -0,0 +1,16 @@ +{{- if .Values.secret.enabled }} +apiVersion: bitnami.com/v1alpha1 +kind: SealedSecret +metadata: + creationTimestamp: null + name: {{ .Values.secretName }} + namespace: {{ .Release.Namespace }} +spec: + encryptedData: + + metadata: + creationTimestamp: null + name: {{ .Values.secretName }} + namespace: {{ .Release.Namespace }} + type: Opaque +{{- end }} \ No newline at end of file diff --git a/charts/api/templates/service.yaml b/charts/api/templates/service.yaml new file mode 100644 index 0000000..1e6e3e1 --- /dev/null +++ b/charts/api/templates/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "api.fullname" . }} +spec: + selector: + app: {{ include "api.fullname" . }} + ports: + - protocol: TCP + port: {{ .Values.env.port }} + targetPort: {{ .Values.env.port }} \ No newline at end of file diff --git a/charts/api/values.yaml b/charts/api/values.yaml new file mode 100644 index 0000000..f57e71a --- /dev/null +++ b/charts/api/values.yaml @@ -0,0 +1,40 @@ +nameOverride: "" +fullnameOverride: "" + +replicaCount: 1 +image: ghcr.io/pinax-network/antelope-token-api +tag: v1.0.0 + +initContainer: + enabled: true + clickhouseSink: substreams-sink-clickhouse-service:3000 + schemaUrl: https://raw.githubusercontent.com/pinax-network/substreams-antelope-tokens/main/schema.sql + +env: + port: 8080 + hostname: 0.0.0.0 + host: http://clickhouse:8123 + database: default + username: default + password: "" + table: "" + max_limit: 100000 + verbose: true + +secret: + # secretName is the name of the sealed secret to use + secretName: "" + # enable to create the secret and fill it with following values + enabled: false + # each of these values should come from a sealed secret and be encrypted + # database: "" + # username: "" + # password: "" + +service: + type: ClusterIP + +ingress: + enabled: false + entryPoints: web + match: Path(`/`) \ No newline at end of file