- Docker - https://www.docker.com/
- Docker Compose - https://docs.docker.com/compose/install/#prerequisites
- nodejs + npm - https://nodejs.org
Server side was created from scratch using express.
Client side was bootstrapped with create-react-app.
- Make sure docker is running
- Open a terminal in the root folder of the project.
npm run setup
this will:- create your env file
- create needed directories
- install dependencies
- initialize the database in the docker container
- Option A - Server + Client
npm run dev
- Option B - Server + Zen node + Client
npm run dev:all
- Watch server/worker/other logs
npm run docker:logs -- [service]
npm run docker:logs
- all servicesnpm run docker:logs -- web
- just web server
- The site will be available at localhost:3001 via the webpack server and on localhost:3000 via the explorer actual express server (this will not auto refresh the client on change, one must build the client again and re-save one of the server files in order to refresh it)
- When done -
npm run docker:stop
to stop all containers
npm run client:build
- creates the build foldernpm run docker:up
- now load http://localhost:3000
In order to have some blockchain data in the development environment you should add data to the database:
- Option 1 - run the worker to cache your db
docker-compose exec web node worker
- let it work (long operation)
- Option 2 - copy the db from staging
- Follow the steps in Heroku to local
Running tests in development should be done from inside of the docker container, as the tests need all of the environment:
docker-compose exec web npm t
The worker layer is responsible for fetching new blocks from a node and mapping them to the database.
for further info visit the worker docs
Sometimes it is needed to reset the state of the database to a specific block number in the past:
- Reset the blocks and all related tables (run this against the database):
DELETE FROM "Blocks" WHERE "blockNumber" > X;
- Optionally delete data from
*PerDay
tables - run the script to re-calculate all addresses/assets:
(run this in the server machine or in the web container)
node worker/run-once/recalcAddressesAssetsCurState.js
- When in need to re-calculate the contracts: (in web container)
node worker/run-once/insertAllContractsFromTransactions.js
- now the database is in complete state for block X
docker-compose logs
- Watch logs from the containers - https://docs.docker.com/compose/reference/logs/docker-compose up
- start the serverdocker-compose exec <service name> sh
- start a shell inside once of the services. Replace<service name>
with the wanted service.
For example -
docker-compose exec web sh
- start a shell in the web containerdocker-compose exec db sh
- start a shell in the db containerdocker ps -a
- list all containersdocker stop $(docker ps -a -q)
stop all containersdocker rm $(docker ps -a -q -f status=exited)
- remove all exited containersdocker images
- list all imagesdocker rmi $(docker images -q)
- remove all images
we use sequelize to talk to the database
in the docker web container, run npx sequelize
to see all cli options.
- commit the code to heroku
- Client is built automatically with the npm script
heroku-postbuild
- start web:
heroku ps:scale web=1 -a <app name>
- start worker:
heroku ps:scale worker=1 -a <app name>
- Set environment variables:
- DATABASE_URL
- REDISCLOUD_URL
- zp__node - The remote node url
- GOOGLE_TRACKING_ID
- CGP_FUND_CONTRACT_ID
- CGP_VOTING_CONTRACT_ID
- CGP_FUND_PAYOUT_BALLOT
- GOVERNANCE_CONTRACT_ID - The contract ID of the repo voting
- governance__afterTallyBlocks - How many blocks after tally to show the vote results
- GENESIS_TOTAL_ZP - the amount of zp in the genesis block (in ZP, not Kalapas)
- CONTRACT_NAMING_JSON
- ASSET_NAMING_JSON
- REACT_APP_PROD_ENV - staging/production
- APP_NAME - the application name for better logs
heroku pg:backups:capture --app <app name>
- Copy from staging to production:
heroku pg:backups:restore <staging app name>::<backup name, eg b001> DATABASE_URL --app <destination app name, eg app>
heroku pg:backups:capture --app <app name>
- get latest backup url from heroku:
heroku pg:backups:url -a <app name>
- log into db container
docker-compose exec db sh
cd home
in the db container- linux download (docker):
wget -O db.dump "<url from previous step>"
- restore to a local db (replace
<db name>
with actual name):pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d <db name> db.dump
Info
- https://devcenter.heroku.com/articles/heroku-postgres-backups
- https://devcenter.heroku.com/articles/heroku-postgres-import-export
The project contain both the client and the server:
- src - client source
- src/common - common code that can be used between processes (client, server or worker)
- public - client public source files
- server - server code
- worker - server worker jobs & scheduler
- test - general code for tests
docker-compose exec db sh
psql -U postgres
\c <db name>
- Run SQL queries or use any of the psql commands (run
\?
for help)