Skip to content

Commit

Permalink
Abilities to create BCD Frontend + to Use External DB (#553)
Browse files Browse the repository at this point in the history
* Working BCD frontend

* Expose port 8080 on bcd service for gui

* update sandbox config and mount to indexer container

* Make pg volume storage configurable

* update sandbox config

* require rpcUrl and apiUrl to be set for gui

* Clean up prop access

* Optionally create a postgres db container + make DB_HOSTNAME a secret

* Update error msg

* Make postgres image configurable

* b64enc hostname

* Only set PGDATA if using internal postgres db

* bug fix
  • Loading branch information
harryttd authored Feb 23, 2023
1 parent 7fc11a2 commit 8e247fc
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 18 deletions.
3 changes: 1 addition & 2 deletions charts/tezos/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ metadata:
Returns the true type or empty string which is falsey.
*/}}
{{- define "tezos.shouldDeployBcdIndexer" -}}
{{- $indexConfig := .Values.bcdIndexer | default dict }}
{{- if and $indexConfig.indexerRpcUrl $indexConfig.dbPassword }}
{{- if and .indexerRpcUrl .db.password }}
{{- "true" }}
{{- else }}
{{- "" }}
Expand Down
128 changes: 117 additions & 11 deletions charts/tezos/templates/bcd_indexer.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if (include "tezos.shouldDeployBcdIndexer" .) }}
{{- $indexerConfig := .Values.bcdIndexer | default dict }}
{{- if (include "tezos.shouldDeployBcdIndexer" $indexerConfig) }}

apiVersion: v1
kind: Service
Expand All @@ -10,6 +11,11 @@ spec:
- port: 14000
name: bcd
targetPort: bcd
{{- if $indexerConfig.gui.enabled }}
- port: 8080
name: gui
targetPort: gui
{{- end }}
selector:
app: {{ .Values.bcd_indexer_statefulset.name }}
type: NodePort
Expand All @@ -23,8 +29,7 @@ metadata:
data:
BCD_ENV: sandbox
GIN_MODE: debug
DB_HOSTNAME: localhost
SANDBOX_NODE_URI: {{ .Values.bcdIndexer.indexerRpcUrl }}
SANDBOX_NODE_URI: {{ $indexerConfig.indexerRpcUrl }}

---
apiVersion: v1
Expand All @@ -33,10 +38,72 @@ metadata:
name: db-creds
namespace: {{ .Release.Namespace }}
data:
POSTGRES_USER: {{ b64enc .Values.bcdIndexer.dbUser }}
POSTGRES_PASSWORD: {{ b64enc .Values.bcdIndexer.dbPassword }}
POSTGRES_DB: {{ b64enc .Values.bcdIndexer.dbName }}
# `DB_HOSTNAME` is the env var looked up by the app
DB_HOSTNAME: {{ b64enc ($indexerConfig.db.hostname | default "localhost") }}
POSTGRES_USER: {{ b64enc $indexerConfig.db.user }}
POSTGRES_PASSWORD: {{ b64enc $indexerConfig.db.password }}
POSTGRES_DB: {{ b64enc $indexerConfig.db.name }}
{{- if not $indexerConfig.db.isExternal }}
PGDATA: {{ b64enc "/var/lib/postgresql/data/pgdata" }}
{{- end }}

---
apiVersion: v1
kind: ConfigMap
metadata:
name: sandbox-config
namespace: {{ .Release.Namespace }}
data:
# Based on:
# https://github.com/baking-bad/bcdhub/blob/fa7e36f6c890d543d72a3d494f7a2509cd41871a/configs/sandbox.yml
sandbox.yml: |
rpc:
sandboxnet:
uri: ${SANDBOX_NODE_URI}
timeout: 10
requests_per_second: 10
storage:
pg:
host: ${DB_HOSTNAME:-db}
port: 5432
user: ${POSTGRES_USER}
dbname: ${POSTGRES_DB:-bcd}
password: ${POSTGRES_PASSWORD}
sslmode: disable
timeout: 10
share_path: /etc/bcd
base_url: http://localhost:8000
api:
project_name: api
bind: ":14000"
swagger_host: "localhost:8000"
cors_enabled: true
sentry_enabled: false
seed_enabled: true
page_size: ${PAGE_SIZE:-10}
frontend:
ga_enabled: false
mempool_enabled: false
sandbox_mode: true
rpc:
sandboxnet: {{ $indexerConfig.gui.rpcUrl | default "" }}
networks:
- sandboxnet
connections:
max: 20
idle: 10
indexer:
project_name: indexer
sentry_enabled: false
networks:
sandboxnet:
receiver_threads: 5
connections:
max: 5
idle: 5
scripts:
networks:
- sandboxnet
---
apiVersion: apps/v1
Expand All @@ -55,8 +122,12 @@ spec:
labels:
app: {{ .Values.bcd_indexer_statefulset.name }}
spec:
volumes:
- name: sandbox-config
configMap:
name: sandbox-config
containers:
- image: {{ .Values.bcdIndexer.images.api }}
- image: {{ $indexerConfig.images.api }}
name: api
ports:
- containerPort: 14000
Expand All @@ -66,14 +137,48 @@ spec:
name: bcd-env
- secretRef:
name: db-creds
- image: {{ .Values.bcdIndexer.images.indexer }}
volumeMounts:
- name: sandbox-config
mountPath: /app/api/sandbox.yml
subPath: sandbox.yml
- image: {{ $indexerConfig.images.indexer }}
name: indexer
envFrom:
- configMapRef:
name: bcd-env
- secretRef:
name: db-creds
- image: postgres:14
volumeMounts:
- name: sandbox-config
mountPath: /app/indexer/sandbox.yml
subPath: sandbox.yml
{{- if $indexerConfig.gui.enabled }}
{{- $_ := required "gui.apiUrl is required" $indexerConfig.gui.apiUrl }}
{{- $_ := required "gui.rpcUrl is required" $indexerConfig.gui.rpcUrl }}
- image: {{ $indexerConfig.images.gui }}
name: gui
ports:
- containerPort: 80
name: gui
command: ["/bin/sh"]
args:
- -c
- |
set -ex
api_url="{{ $indexerConfig.gui.apiUrl }}/v1"
for file in js/*; do
echo $file
sed -i -E \
"s~http://localhost:14000/v1~$api_url~g; s~process\.env.VUE_APP_API_URI~\"$api_url\"~g" \
"$file"
done
/docker-entrypoint.sh nginx -g "daemon off;"
{{- end }}
{{- if not $indexerConfig.db.isExternal }}
- image: {{ $indexerConfig.images.postgres }}
name: db
imagePullPolicy: IfNotPresent
volumeMounts:
Expand All @@ -88,9 +193,10 @@ spec:
spec:
accessModes:
- ReadWriteOnce
storageClassName: {{ .Values.bcdIndexer.storageClassName }}
storageClassName: {{ $indexerConfig.storageClassName }}
resources:
requests:
storage: "300Gi"
storage: {{ $indexerConfig.storage | default "300Gi" }}
{{- end }}

{{- end }}
30 changes: 25 additions & 5 deletions charts/tezos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ nodes:
config:
shell:
history_mode: rolling
metrics_addr: [ "0.0.0.0:9932" ]
metrics_addr: ["0.0.0.0:9932"]
# End nodes

## Configuration for K8s Service resources. Configuring the labels selector of a
Expand Down Expand Up @@ -492,13 +492,33 @@ protocols:
# # api_log_level: Debug
# # indexer_log_level: Debug

## Set values `indexerRpcUrl` and `db.password` for an indexer to be created.
bcdIndexer:
images:
api: ghcr.io/baking-bad/bcdhub-api:4.4.0
indexer: ghcr.io/baking-bad/bcdhub-indexer:4.4.0
# dbName: bcd
# dbPassword: bcd-password
# dbUser: bcd
# storageClassName: ""
gui: ghcr.io/baking-bad/bcdhub-gui:4.4.0
postgres: postgres:14

gui:
enabled: false
## Url of the BCD api for the frontend to hit
apiUrl: http://localhost:14000
## Url to the RPC backend for the frontend to hit
rpcUrl: http://localhost:8732

## RPC url of the node to be indexed
# indexerRpcUrl: http://archive-baking-node-0.archive-baking-node:8732

db:
# By default creates a postgres db container. Setting to true won't create
# it and instead expects credentials for an external postgres database.
isExternal: false
hostname: localhost
name: bcd
password: bcd-password
user: bcd

# For the pv for the optional postgres container
storageClassName: ""
storage: "300Gi"

0 comments on commit 8e247fc

Please sign in to comment.