Skip to content

Commit 68ff6a5

Browse files
[Tooling] Integrate Tilt development environment (#23)
## Summary Integrate [Tilt](https://docs.tilt.dev/) (and k8s/helm) development environment. Run: ``` tilt up ``` ## Issue - pokt-network/poktroll#873 ## Type of change Select one or more: - [x] New feature, functionality or library - [ ] Bug fix - [ ] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing **Documentation changes** (only if making doc changes) - [ ] `make docusaurus_start`; only needed if you make doc changes **Local Testing** (only if making code changes) - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - See [quickstart guide](https://dev.poktroll.com/developer_guide/quickstart) for instructions **PR Testing** (only if making code changes) - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. - **THIS IS VERY EXPENSIVE**, so only do it after all the reviews are complete. - Optionally run `make trigger_ci` if you want to re-trigger tests without any code changes - If tests fail, try re-running failed tests only using the GitHub UI as shown [here](https://github.com/pokt-network/poktroll/assets/1892194/607984e9-0615-4569-9452-4c730190c1d2) ## Sanity Checklist - [ ] I have tested my changes using the available tooling - [ ] I have commented my code - [ ] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable
1 parent ec03bcd commit 68ff6a5

28 files changed

+634
-10
lines changed

README.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ To learn more about SubQuery, [see their docs](https://academy.subquery.network)
2121
- [tl;dr local development (if not your first time)](#tldr-local-development-if-not-your-first-time)
2222
- [1. Install dependencies](#1-install-dependencies)
2323
- [2. Generate types](#2-generate-types)
24-
- [3. Run](#3-run)
24+
- [3a. Run via Tilt](#3a-run-via-tilt)
25+
- [3b. Run via docker-compose](#3b-run-via-docker-compose)
2526
- [Localnet ONLY](#localnet-only)
26-
- [3.1 Debugging, errors running \& building](#31-debugging-errors-running--building)
27-
- [3.2 Using a pre-built image](#32-using-a-pre-built-image)
28-
- [3.3 Available Scripts breakdown](#33-available-scripts-breakdown)
29-
- [3.4 Using k8s](#34-using-k8s)
27+
- [3b.1 Debugging, errors running \& building](#31-debugging-errors-running--building)
28+
- [3b.2 Using a pre-built image](#32-using-a-pre-built-image)
29+
- [3b.3 Available Scripts breakdown](#33-available-scripts-breakdown)
30+
- [3c. Using k8s](#3c-using-k8s)
3031

3132
## Usage & Query Docs
3233

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

4041
```bash
4142
docker exec -it pocketdex_development-postgres-1 psql -U postgres -d postgres
43+
SET SCHEMA "testnet";
44+
# OR, if indexing localnet:
45+
# SET SCHEMA "localnet";
4246
SET search_path TO app;
4347
\dt
4448
```
@@ -160,7 +164,38 @@ Types will need to be regenerated any time the `graphql.schema` is changed.
160164
yarn run codegen
161165
```
162166

163-
### 3. Run
167+
### 3a. Run via [Tilt](https://tilt.dev/)
168+
169+
![Tilt](docs/assets/tilt_screenshot.png)
170+
171+
```bash
172+
# Start tilt
173+
tilt up
174+
175+
# Delete tilt resources
176+
tilt down
177+
```
178+
179+
#### Running against localnet
180+
181+
_NOTE: 🚨 The [poktroll](https://github.com/pokt-network/poktroll) localnet includes pocketdex in its tilt environment. 🚨_
182+
183+
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`:
184+
185+
```diff
186+
load("./tiltfiles/pocketdex.tilt", "pocketdex")
187+
pocketdex("./",
188+
genesis_file_name="testnet.json",
189+
postgres_values_path="./tiltfiles/k8s/postgres/postgres-values.yaml",
190+
pgadmin_values_path="./tiltfiles/k8s/pgadmin/pgadmin-values.yaml",
191+
- indexer_values_path="./tiltfiles/k8s/indexer/dev-testnet-indexer-values.yaml",
192+
+ indexer_values_path="./tiltfiles/k8s/indexer/dev-localnet-indexer-values.yaml",
193+
gql_engine_values_path="./tiltfiles/k8s/gql-engine/dev-gql-engine-values.yaml")
194+
```
195+
196+
Tilt will automatically apply the change on save.
197+
198+
### 3b. Run via docker-compose
164199

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

218-
#### 3.1 Debugging, errors running & building
253+
#### 3b.1 Debugging, errors running & building
219254

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

@@ -227,7 +262,7 @@ docker context use default
227262

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

230-
#### 3.2 Using a pre-built image
265+
#### 3b.2 Using a pre-built image
231266

232267
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).
233268

@@ -252,7 +287,7 @@ services:
252287
...
253288
```
254289

255-
#### 3.3 Available Scripts breakdown
290+
#### 3b.3 Available Scripts breakdown
256291

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

283-
#### 3.4 Using k8s
318+
### 3c. Using k8s
284319

285320
See the instructions in [docs/kubernetes.md](./docs/kubernetes.md) for deploying using Kubernetes.

Tiltfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("./tiltfiles/pocketdex.tilt", "pocketdex")
2+
pocketdex("./",
3+
# TODO(@bryanchriswhite): load genesis file name from env var or config file.
4+
genesis_file_name="testnet.json",
5+
postgres_values_path="./tiltfiles/k8s/postgres/postgres-values.yaml",
6+
pgadmin_values_path="./tiltfiles/k8s/pgadmin/pgadmin-values.yaml",
7+
indexer_values_path="./tiltfiles/k8s/indexer/dev-testnet-indexer-values.yaml",
8+
gql_engine_values_path="./tiltfiles/k8s/gql-engine/dev-gql-engine-values.yaml")

docker-compose.development.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ services:
4444
context: .
4545
dockerfile: ./docker/dev-node.dockerfile
4646
args:
47+
GENESIS_FILENAME: ${GENESIS_FILENAME:-testnet.json}
4748
NODE_ENV: ${ENV}
4849
CHAIN_ID: ${CHAIN_ID}
4950
ENDPOINT: ${ENDPOINT}

docker-compose.test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
context: .
55
dockerfile: ./docker/dev-node.dockerfile
66
args:
7+
GENESIS_FILENAME: ${GENESIS_FILENAME:-testnet.json}
78
NODE_ENV: ${ENV:-test}
89
CHAIN_ID: ${CHAIN_ID:-poktroll}
910
ENDPOINT: ${ENDPOINT}

docker/dev-node.dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ARG CI=false
44
ARG NODE_ENV=development
55
ARG ENDPOINT
66
ARG CHAIN_ID=poktroll
7+
ARG GENESIS_FILENAME
78

89
ENV NODE_ENV=$NODE_ENV
910
ENV ENDPOINT=$ENDPOINT
@@ -33,6 +34,7 @@ WORKDIR /app
3334
COPY package.json yarn.lock .yarnrc.yml /app/
3435
COPY scripts /app/scripts
3536
COPY .yarn /app/.yarn
37+
COPY ./genesis/${GENESIS_FILENAME} /app/genesis.json
3638

3739
# Install dev dependencies
3840
RUN yarn install

docs/assets/tilt_screenshot.png

394 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: gql-engine
3+
description: GraphQL API Server for Pocketdex
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
enable_graphiql_playground: true
2+
indexer_endpoint: "http://indexer-service:3000"
3+
port: 3000
4+
env:
5+
NODE_ENV: development
6+
# Testnet
7+
ENDPOINT: "https://testnet-validated-validator-rpc.poktroll.com"
8+
CHAIN_ID: "poktroll"
9+
# db schema name
10+
DB_SCHEMA: "testnet"
11+
12+
START_BLOCK: 1
13+
# Check docs to see what else you can set here:
14+
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-cli
15+
SUBQUERY_NODE_EXTRA_PARAMS: "--unfinalized-blocks=true"
16+
# Check docs to see what else you can set here:
17+
# Ref: https://academy.subquery.network/indexer/run_publish/references.html#subql-query
18+
SUBQUERY_GRAPHQL_EXTRA_PARAMS: ""
19+
20+
DB_HOST: postgres-service
21+
DB_PORT: 5432
22+
DB_USER: postgres
23+
DB_PASS: postgres
24+
DB_DATABASE: postgres
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: gql-engine-deployment
5+
labels:
6+
app.kubernetes.io/name: gql-engine
7+
app.kubernetes.io/part-of: pocketdex
8+
app.kubernetes.io/managed-by: helm
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/name: gql-engine
14+
app.kubernetes.io/part-of: pocketdex
15+
app.kubernetes.io/managed-by: helm
16+
template:
17+
metadata:
18+
labels:
19+
app.kubernetes.io/name: gql-engine
20+
app.kubernetes.io/part-of: pocketdex
21+
app.kubernetes.io/managed-by: helm
22+
spec:
23+
initContainers:
24+
- name: wait-for-indexer
25+
image: busybox
26+
command: [ 'sh', '-c', 'until nc -z indexer-service 3000; do echo waiting for indexer; sleep 2; done;' ]
27+
containers:
28+
- name: gql-engine
29+
image: subquerynetwork/subql-query:latest
30+
command:
31+
- /sbin/tini
32+
- --
33+
- /bin/run
34+
- -f
35+
- /app
36+
- --name={{ .Values.env.DB_SCHEMA }}
37+
- --indexer={{ .Values.indexer_endpoint }}
38+
- --port={{ .Values.port }}
39+
{{- if .Values.enable_graphiql_playground }}
40+
- --playground
41+
{{- end }}
42+
ports:
43+
- containerPort: {{ .Values.port }}
44+
env:
45+
{{- if .Values.env }}
46+
{{- range $key, $value := .Values.env }}
47+
- name: {{ $key | quote }}
48+
value: {{ $value | quote }}
49+
{{- end }}
50+
{{- end }}

0 commit comments

Comments
 (0)