- Docker - https://www.docker.com/
- Docker Compose (Comes with docker) - 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- to create your env file and needed directories and to install dependencies.- Open .env file and fill missing data
npm run client:build- to build the front endnpm run docker:up:all- this will:- Download all the needed images
- Create all the containers.
- Start the web server.
- Setup the database -
docker-compose exec web sh- to run a shell inside of the web container.npm run setup:dbexit- to exit the container
- Start caching the db or copy the staging db
- Option 1 - run the worker to cache your db
docker-compose exec web shnode worker- start the worker- let it work
- Option 2 - copy the db from staging
- Follow the steps in Heroku to local
- Option 1 - run the worker to cache your db
- Setup is done - shut down server -
npm run docker:stop
- 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
- When done -
npm run docker:stopto stop all containers
npm run client:build- creates the build foldernpm run docker:up- now load http://localhost:3000
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 web 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
- GOVERNANCE_CONTRACT_ID - The contract ID of the repo voting
- governance__afterTallyBlocks - How many blocks after tally to show the vote results
- REACT_APP_PROD_ENV - staging/production
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 homein 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 shpsql -U postgres\c <db name>- Run SQL queries or use any of the psql commands (run
\?for help)