Skip to content

Commit

Permalink
add api chart
Browse files Browse the repository at this point in the history
  • Loading branch information
coutug committed Mar 20, 2024
1 parent f8a4e9f commit 6dd362d
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 0 deletions.
24 changes: 24 additions & 0 deletions charts/api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions charts/api/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This should appear as readme in artifacthub
84 changes: 84 additions & 0 deletions charts/api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
17 changes: 17 additions & 0 deletions charts/api/templates/create-tables.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
41 changes: 41 additions & 0 deletions charts/api/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 10 additions & 0 deletions charts/api/templates/env.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 13 additions & 0 deletions charts/api/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
16 changes: 16 additions & 0 deletions charts/api/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
11 changes: 11 additions & 0 deletions charts/api/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
40 changes: 40 additions & 0 deletions charts/api/values.yaml
Original file line number Diff line number Diff line change
@@ -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(`/`)

0 comments on commit 6dd362d

Please sign in to comment.