Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0ee23df
wip: k8s resources from scratch
bryanchriswhite Oct 13, 2024
f7b7a38
wip: indexer running
bryanchriswhite Oct 14, 2024
fd46102
wip: gql-engine
bryanchriswhite Oct 14, 2024
30f962d
wip: fix gql-engine & depl deps
bryanchriswhite Oct 15, 2024
6684ded
refactor: Tiltfile to support external use
bryanchriswhite Oct 17, 2024
8a2cf9f
wip: splitting localnet &n testnet indexer values
bryanchriswhite Oct 17, 2024
20795c2
chore: add readiness and liveness probes
bryanchriswhite Oct 17, 2024
b5e4e13
refactor: pocketdex Tiltfile for re-use in the poktroll repo
bryanchriswhite Oct 17, 2024
71ee7e7
refactor: consolidate tilt assets & extract more template values
bryanchriswhite Oct 17, 2024
31fe923
fixup! HEAD^
bryanchriswhite Oct 17, 2024
999481f
chore: add pgadmin to tilt
bryanchriswhite Oct 21, 2024
b5290fa
chore: add hostNetwork to support separate external (to tilt) localnet
bryanchriswhite Oct 21, 2024
2831f7e
revert: package.json changes
bryanchriswhite Oct 21, 2024
6b76580
chore: restore postgres version build arg
bryanchriswhite Oct 21, 2024
08b1dbf
chore: parameterize gql-engine port
bryanchriswhite Oct 21, 2024
f877f11
chore: restore pgadmin liveness probe
bryanchriswhite Oct 21, 2024
c5cd406
chore: add missing GENESIS_FILENAME build args
bryanchriswhite Oct 21, 2024
5d5d62f
fix: typo
bryanchriswhite Oct 21, 2024
33c1acb
docs: add tilt instructions to README
bryanchriswhite Oct 23, 2024
df04aab
docs: add SET SCHEMA to README regarding psql access
bryanchriswhite Oct 23, 2024
d8d7d47
docs: add tilt screenshot to README
bryanchriswhite Oct 23, 2024
398412c
docs: italicize tilt NOTE
bryanchriswhite Oct 23, 2024
01b647f
docs: update README ToC
bryanchriswhite Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ To learn more about SubQuery, [see their docs](https://academy.subquery.network)
- [tl;dr local development (if not your first time)](#tldr-local-development-if-not-your-first-time)
- [1. Install dependencies](#1-install-dependencies)
- [2. Generate types](#2-generate-types)
- [3. Run](#3-run)
- [3a. Run via Tilt](#3a-run-via-tilt)
- [3b. Run via docker-compose](#3b-run-via-docker-compose)
- [Localnet ONLY](#localnet-only)
- [3.1 Debugging, errors running \& building](#31-debugging-errors-running--building)
- [3.2 Using a pre-built image](#32-using-a-pre-built-image)
- [3.3 Available Scripts breakdown](#33-available-scripts-breakdown)
- [3.4 Using k8s](#34-using-k8s)
- [3b.1 Debugging, errors running \& building](#31-debugging-errors-running--building)
- [3b.2 Using a pre-built image](#32-using-a-pre-built-image)
- [3b.3 Available Scripts breakdown](#33-available-scripts-breakdown)
- [3c. Using k8s](#3c-using-k8s)

## Usage & Query Docs

Expand All @@ -39,6 +40,9 @@ Connect to the postgres container, update the schema, and explore!

```bash
docker exec -it pocketdex_development-postgres-1 psql -U postgres -d postgres
SET SCHEMA "testnet";
# OR, if indexing localnet:
# SET SCHEMA "localnet";
SET search_path TO app;
\dt
```
Expand Down Expand Up @@ -160,7 +164,38 @@ Types will need to be regenerated any time the `graphql.schema` is changed.
yarn run codegen
```

### 3. Run
### 3a. Run via [Tilt](https://tilt.dev/)

![Tilt](docs/assets/tilt_screenshot.png)

```bash
# Start tilt
tilt up

# Delete tilt resources
tilt down
```

#### Running against localnet

_NOTE: 🚨 The [poktroll](https://github.com/pokt-network/poktroll) localnet includes pocketdex in its tilt environment. 🚨_

If you need to run pocketdex against poktroll localnet, but can't use the poktroll repo's tilt environment for whatever reason, update (_but don't commit_) the `indexer_values_path` in the `Tiltfile`:

```diff
load("./tiltfiles/pocketdex.tilt", "pocketdex")
pocketdex("./",
genesis_file_name="testnet.json",
postgres_values_path="./tiltfiles/k8s/postgres/postgres-values.yaml",
pgadmin_values_path="./tiltfiles/k8s/pgadmin/pgadmin-values.yaml",
- indexer_values_path="./tiltfiles/k8s/indexer/dev-testnet-indexer-values.yaml",
+ indexer_values_path="./tiltfiles/k8s/indexer/dev-localnet-indexer-values.yaml",
gql_engine_values_path="./tiltfiles/k8s/gql-engine/dev-gql-engine-values.yaml")
```

Tilt will automatically apply the change on save.

### 3b. Run via docker-compose

Dotenv files will be automatically created after the `yarn install` thanks to the `postinstall` script.
After that, feel free to modify them as you wish.
Expand Down Expand Up @@ -215,7 +250,7 @@ Or Stop & clean up (delete postgres data):
yarn run docker:clean:development
```

#### 3.1 Debugging, errors running & building
#### 3b.1 Debugging, errors running & building

If you're hitting errors with the above command, do a nuclear clean of all potential issues:

Expand All @@ -227,7 +262,7 @@ docker context use default

Now pick up from the `yarn run docker:build` step above.

#### 3.2 Using a pre-built image
#### 3b.2 Using a pre-built image

If you are unable to build locally, a pre-built image is available on Docker Hub: [bryanchriswhite/pocketdex-subquery-node:latest](https://hub.docker.com/r/bryanchriswhite/pocketdex-subquery-node).

Expand All @@ -252,7 +287,7 @@ services:
...
```

#### 3.3 Available Scripts breakdown
#### 3b.3 Available Scripts breakdown

* `preinstall` - Enforces the use of Yarn as the package manager.
* `postinstall` - Executes the `env:prepare` script after the installation process.
Expand Down Expand Up @@ -280,6 +315,6 @@ services:
* `docker:stop:<environment>` - Stops all active services for the specified environment without removing them.
* `docker:clean:<environment>` - Stops and removes all services, volumes, and networks for the specified environment.

#### 3.4 Using k8s
### 3c. Using k8s

See the instructions in [docs/kubernetes.md](./docs/kubernetes.md) for deploying using Kubernetes.
8 changes: 8 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("./tiltfiles/pocketdex.tilt", "pocketdex")
pocketdex("./",
# TODO(@bryanchriswhite): load genesis file name from env var or config file.
genesis_file_name="testnet.json",
postgres_values_path="./tiltfiles/k8s/postgres/postgres-values.yaml",
pgadmin_values_path="./tiltfiles/k8s/pgadmin/pgadmin-values.yaml",
indexer_values_path="./tiltfiles/k8s/indexer/dev-testnet-indexer-values.yaml",
gql_engine_values_path="./tiltfiles/k8s/gql-engine/dev-gql-engine-values.yaml")
1 change: 1 addition & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ services:
context: .
dockerfile: ./docker/dev-node.dockerfile
args:
GENESIS_FILENAME: ${GENESIS_FILENAME:-testnet.json}
NODE_ENV: ${ENV}
CHAIN_ID: ${CHAIN_ID}
ENDPOINT: ${ENDPOINT}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
context: .
dockerfile: ./docker/dev-node.dockerfile
args:
GENESIS_FILENAME: ${GENESIS_FILENAME:-testnet.json}
NODE_ENV: ${ENV:-test}
CHAIN_ID: ${CHAIN_ID:-poktroll}
ENDPOINT: ${ENDPOINT}
Expand Down
2 changes: 2 additions & 0 deletions docker/dev-node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ARG CI=false
ARG NODE_ENV=development
ARG ENDPOINT
ARG CHAIN_ID=poktroll
ARG GENESIS_FILENAME

ENV NODE_ENV=$NODE_ENV
ENV ENDPOINT=$ENDPOINT
Expand Down Expand Up @@ -33,6 +34,7 @@ WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml /app/
COPY scripts /app/scripts
COPY .yarn /app/.yarn
COPY ./genesis/${GENESIS_FILENAME} /app/genesis.json

# Install dev dependencies
RUN yarn install
Expand Down
Binary file added docs/assets/tilt_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tiltfiles/k8s/gql-engine/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions tiltfiles/k8s/gql-engine/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: gql-engine
description: GraphQL API Server for Pocketdex

# 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.1.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.16.0"
24 changes: 24 additions & 0 deletions tiltfiles/k8s/gql-engine/dev-gql-engine-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
enable_graphiql_playground: true
indexer_endpoint: "http://indexer-service:3000"
port: 3000
env:
NODE_ENV: development
# Testnet
ENDPOINT: "https://testnet-validated-validator-rpc.poktroll.com"
CHAIN_ID: "poktroll"
# db schema name
DB_SCHEMA: "testnet"

START_BLOCK: 1
# Check docs to see what else you can set here:
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-cli
SUBQUERY_NODE_EXTRA_PARAMS: "--unfinalized-blocks=true"
# Check docs to see what else you can set here:
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-query
SUBQUERY_GRAPHQL_EXTRA_PARAMS: ""

DB_HOST: postgres-service
DB_PORT: 5432
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
50 changes: 50 additions & 0 deletions tiltfiles/k8s/gql-engine/templates/gql-engine-depl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: gql-engine-deployment
labels:
app.kubernetes.io/name: gql-engine
app.kubernetes.io/part-of: pocketdex
app.kubernetes.io/managed-by: helm
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: gql-engine
app.kubernetes.io/part-of: pocketdex
app.kubernetes.io/managed-by: helm
template:
metadata:
labels:
app.kubernetes.io/name: gql-engine
app.kubernetes.io/part-of: pocketdex
app.kubernetes.io/managed-by: helm
spec:
initContainers:
- name: wait-for-indexer
image: busybox
command: [ 'sh', '-c', 'until nc -z indexer-service 3000; do echo waiting for indexer; sleep 2; done;' ]
containers:
- name: gql-engine
image: subquerynetwork/subql-query:latest
command:
- /sbin/tini
- --
- /bin/run
- -f
- /app
- --name={{ .Values.env.DB_SCHEMA }}
- --indexer={{ .Values.indexer_endpoint }}
- --port={{ .Values.port }}
{{- if .Values.enable_graphiql_playground }}
- --playground
{{- end }}
ports:
- containerPort: {{ .Values.port }}
env:
{{- if .Values.env }}
{{- range $key, $value := .Values.env }}
- name: {{ $key | quote }}
value: {{ $value | quote }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions tiltfiles/k8s/gql-engine/templates/gql-engine-svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: gql-engine-service
spec:
selector:
app.kubernetes.io/name: gql-engine
app.kubernetes.io/part-of: pocketdex
app.kubernetes.io/managed-by: helm
ports:
- name: http
protocol: TCP
port: {{ .Values.port }}
targetPort: {{ .Values.port }}
type: ClusterIP
23 changes: 23 additions & 0 deletions tiltfiles/k8s/indexer/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions tiltfiles/k8s/indexer/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: indexer
description: SubQuery Indexer Node for Pocketdex

# 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.1.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.16.0"
23 changes: 23 additions & 0 deletions tiltfiles/k8s/indexer/dev-localnet-indexer-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
port: 3000
hostNetwork: true
env:
NODE_ENV: development
# LocalNet
ENDPOINT: "http://localhost:26657"
CHAIN_ID: "poktroll"
# db schema name
DB_SCHEMA: "localnet"

START_BLOCK: 1
# Check docs to see what else you can set here:
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-cli
SUBQUERY_NODE_EXTRA_PARAMS: "--unfinalized-blocks=true"
# Check docs to see what else you can set here:
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-query
SUBQUERY_GRAPHQL_EXTRA_PARAMS: ""

DB_HOST: postgres-service
DB_PORT: 5432
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
23 changes: 23 additions & 0 deletions tiltfiles/k8s/indexer/dev-testnet-indexer-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
port: 3000
hostNetwork: false
env:
NODE_ENV: development
# Testnet
ENDPOINT: "https://testnet-validated-validator-rpc.poktroll.com"
CHAIN_ID: "poktroll"
# db schema name
DB_SCHEMA: "testnet"

START_BLOCK: 1
# Check docs to see what else you can set here:
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-cli
SUBQUERY_NODE_EXTRA_PARAMS: "--unfinalized-blocks=true"
# Check docs to see what else you can set here:
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-query
SUBQUERY_GRAPHQL_EXTRA_PARAMS: ""

DB_HOST: postgres-service
DB_PORT: 5432
DB_USER: postgres
DB_PASS: postgres
DB_DATABASE: postgres
Loading
Loading