Skip to content

Commit 234b43f

Browse files
tsuberimleviadam
authored andcommitted
Devops, add ganache, travis and tests support (#4)
* ops * rm volume mount * gitignore fix * rename file * bug fix * apply ganache patch + fix integration test * create abis folder if not exists * travis.yml * fix travis * cache npm & docker builds * rm `cat` cmd in travis * fix travis * update README * Updated package.json
1 parent 68a3843 commit 234b43f

22 files changed

+544
-8452
lines changed

Diff for: .dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
package-lock.json
3+
*.log
4+
.env
5+
subgraph.yaml

Diff for: .env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# daostack_mainnet__postgresPassword=<use a strong passowrd>
2+
# daostack_mainnet__ethereumProvider=https://mainnet.infura.io/v3/<replace with your api key>

Diff for: .gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
node_modules
22
dist
3-
data
4-
.env
5-
.api_key
3+
*.log
4+
subgraph.yaml
5+
docker-compose.yml
6+
config.json
7+
abis
8+
src/types

Diff for: .travis.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
language: node_js
2+
node_js:
3+
- "8"
4+
5+
sudo: required
6+
7+
services:
8+
- docker
9+
cache:
10+
directories:
11+
- node_modules
12+
- $HOME/docker
13+
14+
addons:
15+
apt:
16+
packages:
17+
- docker-ce
18+
19+
before_cache:
20+
- mkdir -p $HOME/docker && docker images -a --filter='dangling=false' --format '{{.Repository}}:{{.Tag}} {{.ID}}' | xargs -n 2 -t sh -c 'test -e $HOME/docker/$1.tar.gz || docker save $0 | gzip -2 > $HOME/docker/$1.tar.gz'
21+
22+
before_install:
23+
- if [[ -d $HOME/docker ]]; then ls $HOME/docker/*.tar.gz | xargs -I {file} sh -c "zcat {file} | docker load"; fi
24+
25+
install:
26+
- docker --version
27+
- docker-compose --version
28+
- sudo service postgresql stop
29+
- while sudo lsof -Pi :5432 -sTCP:LISTEN -t; do sleep 1; done
30+
- npm install
31+
- npm run configure:development
32+
- npm run codegen
33+
34+
script:
35+
- sudo docker-compose run subgraph test
36+
37+
after_script:
38+
- docker-compose down

Diff for: Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:8
2+
3+
# install the 'host' command used to get ip of ipfs container
4+
RUN apt-get update -y && apt-get install dnsutils -y
5+
6+
## Add the wait script to the image
7+
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.4.0/wait /wait
8+
9+
ADD ops/entry /entry
10+
RUN chmod +x /wait /entry
11+
12+
WORKDIR /usr/app
13+
COPY . .
14+
RUN npm install
15+
RUN npm run codegen
16+
17+
ENTRYPOINT [ "/entry" ]
18+
CMD [ "deploy" ]

Diff for: README.md

+55-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
1-
# daostack-subgraph
2-
A DAOstack subgraph for graph-node
1+
# DAOstack subgraph
32

4-
# Get started
3+
DAOstack subgraph for [TheGraph](https://thegraph.com/) project.
54

6-
Develop locally:
5+
## Getting started
76

8-
1. `npm i` - install dependencies.
9-
2. `npm run codegen` - generate automatic typings.
10-
3. create a `.env` file with the following environment variables (**should be kept secret**):
11-
- `POSTGRES_PASSWORD` - a secret string used as the PostgreSQL password for the created DB.
12-
- `ETHEREUM` - url to an rpc ethereum node prefixed with the network name (e.g. `mainnet:http://localhost:8545`)
13-
4. (in a seperate terminal) `docker-compose up` ([install](https://docs.docker.com/compose/install/)) - run a local graph-node with the above config.
14-
6. `npm run deploy`/`npm run deploy:watch` - deploy the subgraph.
7+
1 `git clone https://github.com/daostack/subgraph.git && cd subgraph`
158

16-
Note: All persistent data for the node will be stored in the `./data` directory, remove this directory in order to reset the node.
9+
2. `npm install`
10+
3. `npm run configure:<development|mainnet>` - configure the project to use ganache or mainnet via infura.
1711

18-
Exposed endpoints:
19-
- `http://localhost:8000/daostack` - GraphQL API.
20-
- `http://localhost:8020` - graph-node RPC server.
21-
- `postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/postgres` - postgres DB connection.
22-
- `http://localhost:5001` - ipfs node api.
12+
All npm scripts can be called within a container using `docker-compose` with all dependencies and services set up:
13+
14+
`docker-compose run subgraph -v $(pwd):/usr/app -v /usr/app/node_modules subgraph <command>`
15+
16+
## Commands
17+
18+
1. `configure:mainnet` - configure the project to run against mainnet.
19+
2. `configure:development` - configure the project to run against ganache.
20+
3. `migrate:development` - migrate contracts to ganache and update project configuration.
21+
4. `codegen` - automatically generate abi & type definitions for required contracts.
22+
5. `test` - run integration tests.
23+
6. `deploy` - deploy subgraph.
24+
7. `deploy:watch` - redeploy on file change.
25+
26+
Example: `docker-compose run subgraph -v $(pwd):/usr/app -v /usr/app/node_modules subgraph test` (run intergation tests)
27+
28+
To stop all services: `docker-compose down`
29+
30+
## Exposed endpoints
31+
32+
After running a command with docker-compose, the following endpoints will be exposed on your local machine:
33+
34+
- `http://localhost:8000/daostack` - GraphiQL graphical user interface.
35+
- `http://localhost:8000/daostack/graphql` - GraphQL api endpoint.
36+
- `http://localhost:8001/daostack` - graph-node's websockets endpoint
37+
- `http://localhost:8020` - graph-node's RPC endpoint
38+
- `http://localhost:5001` - ipfs endpoint.
39+
- (if using development) `http://localhost:8545` - ganache RPC endpoint.
40+
- `http://localhost:5432` - postgresql connection endpoint.
41+
42+
## Configuration
43+
44+
This project automatically generates `.yaml` files used by `docker-compose` & `graph-node` based on configuration.
45+
Project configuration lives under: `ops/config.yaml` (public configration), `.env` (secret configuration).
46+
47+
The following `.env` variables can be configured:
48+
49+
- `daostack_mainnet__postgresPassword` - postgres password when running on mainnet (e.g `123`).
50+
- `daostack_mainnet__ethereumProvider` - mainnet web3 provider (e.g `https://mainnet.infura.io/v3/<api key>`)
51+
52+
## Add a new contract tracker
53+
54+
In order to add support for a new contract follow these steps:
55+
56+
1. Create a mapping file at `src/<contract name>.ts`.
57+
2. Create a test file at `test/integration/<contract name>.spec.ts`.
58+
3. Configure the contract's mainnet address at `ops/config.yaml` under `addresses.<contract name>`.
59+
4. Add the contract to the migration script at the `migrate` function in `ops/index.js`.
60+
5. Add an additional datasource for the new contract at `subgraph.handlebars.yaml`, use `{{addresses.<contract name>}}` in place of the contract address.

0 commit comments

Comments
 (0)