Skip to content

Commit

Permalink
feat(charts): astrotrek chart (#1513)
Browse files Browse the repository at this point in the history
## Summary
Adds a Helm chart for deploying the Astrotrek sequencer explorer, which
includes the indexer, indexer-api, Postgres, and frontend components.

## Changes
- Added Helm chart for Astrotrek explorer deployment.
default endpoints:
- indexer-api host: `http://api.sequencer.localdev.me/`
- frontend : `http://astrotrek.sequencer.localdev.me/`

## Testing
Tested locally against local environment with and without storage

## Related Issues
Closes #1473

---------

Co-authored-by: Itamar Reif <[email protected]>
  • Loading branch information
quasystaty1 and itamarreif authored Oct 2, 2024
1 parent 5a567aa commit 939a689
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 1 deletion.
27 changes: 27 additions & 0 deletions charts/astrotrek/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v2
name: astrotrek
description: A Helm chart for deploying a k8s sequencer explorer for the Astria Sequencer Network.

# 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.0.1
# 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: "0.0.1"

maintainers:
- name: quasystaty1
url: astria.org
18 changes: 18 additions & 0 deletions charts/astrotrek/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{/*
Namepsace to deploy elements into.
*/}}
{{- define "astrotrek.namespace" -}}
{{- default .Release.Namespace .Values.global.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- end }}

{{- define "indexer.image" -}}
{{ .Values.images.indexer.repo }}:{{ if .Values.global.dev }}{{ .Values.images.indexer.devTag }}{{ else }}{{ .Values.images.indexer.tag }}{{ end }}
{{- end }}

{{- define "api.image" -}}
{{ .Values.images.api.repo }}:{{ if .Values.global.dev }}{{ .Values.images.api.devTag }}{{ else }}{{ .Values.images.api.tag }}{{ end }}
{{- end }}

{{- define "frontend.image" -}}
{{ .Values.images.frontend.repo }}:{{ if .Values.global.dev }}{{ .Values.images.frontend.devTag }}{{ else }}{{ .Values.images.frontend.tag }}{{ end }}
{{- end }}
29 changes: 29 additions & 0 deletions charts/astrotrek/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: api-env
name: env
data:
API_HOST: "{{ .Values.config.api.host }}"
API_PORT: "{{ .Values.ports.api }}"
API_PROMETHEUS_ENABLED: "{{ .Values.metrics.enabled }}"
API_RATE_LIMIT: "{{ .Values.config.api.rateLimit }}"
API_REQUEST_TIMEOUT: "{{ .Values.config.api.requestTimeout }}"
ASTRIA_ENV: "{{ .Values.config.astriaEnv }}"
INDEXER_BLOCK_PERIOD: "{{ .Values.config.indexer.indexerBlockPeriod }}"
INDEXER_SCRIPTS_DIR: "{{ .Values.config.indexer.indexerScriptDir }}"
INDEXER_THREADS_COUNT: "{{ .Values.config.indexer.indexerThreadsCount }}"
INDEXER_VIEWS_DIR: "{{ .Values.config.indexer.indexerViewsDir }}"
LOG_LEVEL: "{{ .Values.config.logLevel }}"
POSTGRES_DB: "{{ .Values.config.database.postgresDb }}"
POSTGRES_HOST: "{{ .Values.config.database.postgresHost }}"
POSTGRES_PASSWORD: "{{ .Values.config.database.postgresPassword }}"
POSTGRES_PORT: "{{ .Values.ports.db}}"
POSTGRES_USER: "{{ .Values.config.database.postgresUser }}"
PROFILER_SERVER: "{{ .Values.config.profilerServer }}"
SEQUENCER_RPC_RPS: "{{ .Values.config.sequencerRpcRps }}"
SEQUENCER_RPC_TIMEOUT: "{{ .Values.config.sequencerRpcTimeout }}"
SEQUENCER_RPC_URL: "{{ .Values.config.sequencerRpcUrl }}"
NUXT_PUBLIC_API_DEV: "{{ .Values.config.frontend.rpcApiUrl }}"
NUXT_PUBLIC_WSS_DEV: "{{ .Values.config.frontend.wsApiUrl }}"
63 changes: 63 additions & 0 deletions charts/astrotrek/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.config.name }}-indexer
labels:
app: {{ .Values.config.name }}-indexer
namespace: {{ .Values.global.namespace }}
spec:
replicas: {{ .Values.global.replicaCount }}
selector:
matchLabels:
app: {{ .Values.config.name }}-indexer
template:
metadata:
labels:
app: {{ .Values.config.name }}-indexer
spec:
containers:
- name: {{ .Values.config.name }}-indexer
image: {{ include "indexer.image" . }}
envFrom:
- configMapRef:
name: env
restartPolicy: Always
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Values.config.name }}-frontend
name: {{ .Values.config.name }}-frontend
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.config.name }}-frontend
template:
metadata:
labels:
app: {{ .Values.config.name }}-frontend
spec:
containers:
- args:
- npm
- run
- start
envFrom:
- configMapRef:
name: env
image: {{ include "frontend.image" . }}
name: {{ .Values.config.name }}-frontend
ports:
- containerPort: {{ .Values.ports.frontend }}
protocol: TCP
resources:
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
limits:
cpu: {{ .Values.resources.limits.cpu }}
memory: {{ .Values.resources.limits.memory }}
restartPolicy: Always
71 changes: 71 additions & 0 deletions charts/astrotrek/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.config.name }}-api-ingress
namespace: {{ .Values.global.namespace }}
annotations:
{{- with .Values.ingress.api.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.api.className }}
ingressClassName: {{ .Values.ingress.api.className }}
{{- end }}
rules:
- host: {{ .Values.ingress.api.host | quote }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Values.config.name }}-indexer-api-service
port:
name: indexer-api
{{- if .Values.ingress.api.tls }}
tls:
{{- range .Values.ingress.api.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.config.name }}-frontend-ingress
namespace: {{ .Values.global.namespace }}
annotations:
{{- with .Values.ingress.frontend.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.frontend.className }}
ingressClassName: {{ .Values.ingress.frontend.className }}
{{- end }}
rules:
- host: {{ .Values.ingress.frontend.host | quote }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ .Values.config.name }}-frontend-service
port:
number: {{ .Values.ports.frontend }}
{{- if .Values.ingress.frontend.tls }}
tls:
{{- range .Values.ingress.frontend.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- end }}
44 changes: 44 additions & 0 deletions charts/astrotrek/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Values.config.name }}
name: {{ .Values.config.name }}-db-service
namespace: {{ .Values.global.namespace }}
spec:
ports:
- name: "{{ .Values.ports.db }}"
port: {{ .Values.ports.db }}
targetPort: {{ .Values.ports.db }}
selector:
app: {{ .Values.config.name }}-db
---
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Values.config.name }}-indexer-api
name: {{ .Values.config.name }}-indexer-api-service
namespace: {{ .Values.global.namespace }}
spec:
ports:
- name: indexer-api
port: {{ .Values.ports.api}}
targetPort: {{ .Values.ports.api}}
selector:
app: {{ .Values.config.name }}-indexer-api
---
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Values.config.name }}-frontend
name: {{ .Values.config.name }}-frontend-service
namespace: {{ .Values.global.namespace }}
spec:
ports:
- name: "{{ .Values.ports.frontend }}"
port: {{ .Values.ports.frontend }}
targetPort: {{ .Values.ports.frontend }}
selector:
app: {{ .Values.config.name }}-frontend
36 changes: 36 additions & 0 deletions charts/astrotrek/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: astria-indexer-metrics
labels:
app: inderxer
{{- with .Values.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
jobLabel: astria-indexer-metrics
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
app: astria-indexer
endpoints:
- port: metrics
path: /metrics
{{- with .Values.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
- port: astria-indexer-metrics
path: /metrics
{{- with .Values.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
{{- end }}
87 changes: 87 additions & 0 deletions charts/astrotrek/templates/statefulsets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Values.config.name }}-indexer-api
name: {{ .Values.config.name }}-indexer-api
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.config.name }}-indexer-api
name: {{ .Values.config.name }}-indexer-api
template:
metadata:
labels:
app: {{ .Values.config.name }}-indexer-api
name: {{ .Values.config.name }}-indexer-api
spec:
containers:
- name: {{ .Values.config.name }}-indexer-api
image: {{ include "api.image" . }}
envFrom:
- configMapRef:
name: env
ports:
- containerPort: {{ .Values.ports.api }}
name: indexer-api
protocol: TCP
resources:
requests:
cpu: {{ .Values.resources.requests.cpu }}
memory: {{ .Values.resources.requests.memory }}
limits:
cpu: {{ .Values.resources.limits.cpu }}
memory: {{ .Values.resources.limits.memory }}
restartPolicy: Always
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: {{ .Values.global.namespace }}
labels:
app: {{ .Values.config.name }}-db
name: {{ .Values.config.name }}-db
spec:
serviceName: "{{ .Values.config.name }}-db"
replicas: 1
selector:
matchLabels:
app: {{ .Values.config.name }}-db
template:
metadata:
labels:
app: {{ .Values.config.name }}-db
spec:
containers:
- args:
- -cshared_preload_libraries=timescaledb,pg_stat_statements
- -cpg_stat_statements.track=all
envFrom:
- configMapRef:
name: env
image: timescale/timescaledb-ha:pg15-latest
livenessProbe:
exec:
command:
- pg_isready -U -d astria
failureThreshold: 5
periodSeconds: 10
timeoutSeconds: 5
name: {{ .Values.config.name }}-db
ports:
- containerPort: {{ .Values.ports.db }}
protocol: TCP
volumeMounts:
- mountPath: /home/postgres/pgdata
name: db
restartPolicy: Always
volumes:
- name: db
{{- if .Values.storage.enabled }}
persistentVolumeClaim:
claimName: astrotrek-shared-local-pvc
{{- else }}
emptyDir: {}
{{- end }}
14 changes: 14 additions & 0 deletions charts/astrotrek/templates/storageclasses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{/* We only want to create a storage class if we are local. */}}
{{/* For production, you need to create a StorageClass on GKE. */}}
{{- if and .Values.storage.enabled .Values.storage.local }}
{{- range $key, $value := .Values.storage.entities }}
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: astrotrek-shared-vol-local
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Retain
---
{{- end }}
{{- end }}
Loading

0 comments on commit 939a689

Please sign in to comment.