Skip to content

Commit

Permalink
Merge pull request #34 from ma-shulgin/v5
Browse files Browse the repository at this point in the history
Migration to V5
  • Loading branch information
vikiival authored Feb 15, 2022
2 parents 02a7936 + ba37790 commit 2a52e5c
Show file tree
Hide file tree
Showing 67 changed files with 15,507 additions and 5,822 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.git
/node_modules
/lib
/*Versions.json
37 changes: 3 additions & 34 deletions .env
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
###########################
# Common settings #
###########################

# DB config
DB_NAME=hydra
DB_USER=postgres
DB_PASS=postgres
DB_HOST=localhost
DB_PORT=27364
DEBUG=index-builder:*
TYPEORM_LOGGING=error

# Chain node address (for typegen or indexer)
CHAIN_NODE=wss://kusama-rpc.polkadot.io

###########################
# Processor options #
###########################

# Indexer GraphQL API endpoint to fetch indexed events
INDEXER_ENDPOINT_URL=https://kusama.indexer.gc.subsquid.io/v4/graphql

# use url below for self-hosted indexer defined in indexer/docker-compose.yml
# INDEXER_ENDPOINT_URL=http://localhost:8080/v1/graphql

BATCH_SIZE=500
BLOCK_WINDOW=100000

###########################
# GraphQL server #
###########################

GRAPHQL_SERVER_PORT=4000
DB_NAME=squid
DB_PORT=23798
GQL_PORT=4350
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/node_modules
/lib
.DS_Store
kusamaVersions.json
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/processor.ts",
"runtimeArgs": [
"--require=dotenv/config"
],
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/lib/**/*.js"
]
}
]
}
37 changes: 26 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
FROM node:14 AS builder
WORKDIR /hydra-build
FROM node:16-alpine AS node

FROM node AS node-with-gyp
RUN apk add g++ make python3

FROM node-with-gyp AS builder
WORKDIR /squid
ADD package.json .
ADD package-lock.json .
RUN npm ci
ADD tsconfig.json .
ADD src src
RUN npm run build


FROM node:14 AS processor
WORKDIR /hydra-project
FROM node-with-gyp AS deps
WORKDIR /squid
ADD package.json .
ADD package-lock.json .
RUN npm ci # TODO: --production
COPY --from=builder /hydra-build/lib lib
RUN npm ci --production

FROM node AS squid
WORKDIR /squid
COPY --from=deps /squid/package.json .
COPY --from=deps /squid/package-lock.json .
COPY --from=deps /squid/node_modules node_modules
COPY --from=builder /squid/lib lib
ADD db db
ADD manifest.yml .
ADD schema.graphql .
ADD .env .
# TODO: use shorter PROMETHEUS_PORT
ENV PROCESSOR_PROMETHEUS_PORT 3000
EXPOSE 3000
EXPOSE 4000


FROM squid AS processor
CMD ["npm", "run", "processor:start"]


FROM processor AS query-node
CMD ["node", "./lib/generated/server.js"]
FROM squid AS query-node
CMD ["npm", "run", "query-node:start"]
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
process: build
@node -r dotenv/config lib/processor.js


serve:
@npx squid-graphql-server

reset:
@npx sqd db drop
@npx sqd db create
@npx sqd db:migrate

migrate:
@npx sqd db:migrate


migration:
@npx sqd db:create-migration Data


build:
@npm run build


codegen:
@npx sqd codegen


typegen: kusamaVersions.json
@npx squid-substrate-typegen typegen.json


kusamaVersions.json:
@make explore


explore:
@npx squid-substrate-metadata-explorer \
--chain wss://kusama-rpc.polkadot.io \
--archive https://kusama.indexer.gc.subsquid.io/v4/graphql \
--out kusamaVersions.json


up:
@docker-compose up -d


down:
@docker-compose down


.PHONY: process serve start codegen migration migrate up down reset
31 changes: 31 additions & 0 deletions db/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require('dotenv/config')

const ormconfig = {
type: 'postgres',
// entities: [require.resolve('../lib/model')],
entities: [],
migrations: [__dirname + '/migrations/*.js'],
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: ["query", "error", "schema"],
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 5432,
database: process.env.DB_NAME || 'postgres',
username: process.env.DB_USER || 'postgres',
password: process.env.DB_PASS || 'postgres'
}

require('typeorm').createConnection(ormconfig).then(async con => {
try {
await con.runMigrations({transaction: 'all'})
} finally {
await con.close().catch(err => null)
}
}).then(
() => process.exit(),
err => {
console.error(err)
process.exit(1)
}
)
29 changes: 0 additions & 29 deletions db/migrations/1639147106950-Initial.js

This file was deleted.

31 changes: 0 additions & 31 deletions db/migrations/1640098187019-yolia.js

This file was deleted.

19 changes: 0 additions & 19 deletions db/migrations/1640873303445-tyrolia.js

This file was deleted.

15 changes: 0 additions & 15 deletions db/migrations/1641047036677-unolia.js

This file was deleted.

17 changes: 0 additions & 17 deletions db/migrations/1641051005575-lalalia.js

This file was deleted.

15 changes: 0 additions & 15 deletions db/migrations/1644279326965-cache.js

This file was deleted.

19 changes: 0 additions & 19 deletions db/migrations/1644286393911-toString.js

This file was deleted.

Loading

0 comments on commit 2a52e5c

Please sign in to comment.