diff --git a/.github/workflows/check-PRs.yml b/.github/workflows/check-PRs.yml index 331f32a90..f9f4683a7 100644 --- a/.github/workflows/check-PRs.yml +++ b/.github/workflows/check-PRs.yml @@ -30,12 +30,15 @@ jobs: run: | docker build --no-cache -t ghcr.io/eyblockchain/local-zokrates -f zokrates.Dockerfile . docker-compose build - ./start-nightfall -g &> ganache-test.log &disown + ./start-nightfall -g -d &> ganache-test.log &disown - name: debug logs - after container startup if: always() run: cat ganache-test.log + - name: wait 1200s for Containers startup and setup completion + run: sleep 1200 + - name: Run integration test run: | npm ci diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6b7366233 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode" +} diff --git a/README.md b/README.md index 6aa3d7342..34a3ed8a5 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,15 @@ You need to run a setup script the first time that you use nightfall_3. This wi If running for first time, do the setup as above and then run this script: ```sh -./start-nightfall -l | -g | -r [-s] +./start-nightfall -l | -g | -r [-s] [-d] ``` - -This will bring up the application. You can run it either with a Ganache blockchain simulator, a real blockchain client which exposes a websocket connection on localHost:8546, or a public/private VM runing public testnet node (for example Ropsten, Rinkeby, Kovan, etc. Code is tested on Ropsten testnet, but ideally it should work on all testnet network). See below for more details on how to do the latter as there are some additional considerations. Use -g for Ganache, -l for localhost and -r for testnet node (Note: with option -r set environment variable $ROPSTEN_NODE, $FROM_ADDRESS and $ETH_PRIVATE_KEY to testnet node URL, EOA address and EOA address's private key, respectively). We recommend using Ganache first to check everything works, because it's considerably faster. Additionally, you can use the -s flag. If you do that, Nightfall_3 will run with stubbed ZKP circuits, which generate proofs that always verify. That's useful for development work because tests will run much faster but clearly you should run without stubs, as a final check. +This will bring up the application. You can run it either with a Ganache blockchain simulator or a real blockchain client which exposes a websocket connection on localHost:8546. See below for more details on how to do the latter as there are some additional considerations. +- Environment + - Use `-g` to use a Ganache client inside the container + - Use `-l` to use some localhost client running on your machine. We recommend using Ganache first to check everything works, because it's considerably faster. + - Use `-r` to use ropsten node hosted by the dev team. Note: with option -r set environment variable $ROPSTEN_NODE, $FROM_ADDRESS and $ETH_PRIVATE_KEY to testnet node URL, EOA address and EOA address's private key, respectively +- Additionally, you can use the `-s` flag. If you do that, Nightfall_3 will run with stubbed ZKP circuits, which generate proofs that always verify. That's useful for development work because tests will run much faster but clearly you should run without stubs, as a final check. +- Use the `-d` or `--dev` flag to bind mount the development folders inside the containers, making it useful for development purposes. Omit it to deploy the services using the existing `ghcr` images. Startup will take a minute or so, depending on your machine. You'll see lots of warnings as it runs up from the `optimist` and `timber` containers. That's entirely fine, they're just waiting for the other services that they need to start up. You should see no errors however. If you do, something has broken. @@ -47,6 +52,10 @@ nightfall_3_deployer_1 exited with code 0 ``` This means that deployment is complete and the application is ready to use. You can run the tests at this point. +### To end the application + +To stop the application, you can run ```docker-compose down``` and it should exit cleanly. + ## Testing Open a separate terminal window, cd to the nightfall_3 repo and run diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 000000000..a1c816e07 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,113 @@ +version: '3.5' +# Use this script for running up nightfall_3 in 'developer' mode with local +# bindings. See the readme for more information. +services: + client1: + build: + dockerfile: client.Dockerfile + context: . + volumes: + - type: bind + source: ./nightfall-client/src + target: /app/src + - type: bind + source: ./common-files + target: /common-files + - type: bind + source: ./config/default.js + target: /app/config/default.js + + client2: + build: + dockerfile: client.Dockerfile + context: . + volumes: + - type: bind + source: ./nightfall-client/src + target: /app/src + - type: bind + source: ./common-files + target: /common-files + - type: bind + source: ./config/default.js + target: /app/config/default.js + + worker: + # image: 3800decac71d + build: + dockerfile: worker.Dockerfile + context: . + volumes: + - type: bind + source: ./nightfall-deployer/circuits + target: /app/circuits/ + - type: bind + source: ./zokrates-worker/src + target: /app/src/ + - type: bind + source: ./config/default.js + target: /app/config/default.js + deployer: + #image: docker.pkg.github.com/eyblockchain/nightfall-deployer/nightfall_deployer:1.1.0 + + build: + dockerfile: deployer.Dockerfile + context: . + volumes: + - type: bind + source: ./nightfall-deployer/contracts + target: /app/contracts/ + - type: bind + source: ./nightfall-deployer/circuits + target: /app/circuits/ + - type: bind + source: ./nightfall-deployer/src + target: /app/src/ + - type: bind + source: ./common-files + target: /common-files + - type: bind + source: ./config/default.js + target: /app/config/default.js + - type: bind + source: ./nightfall-deployer/migrations + target: /app/migrations + - type: bind + source: ./nightfall-deployer/truffle-config.js + target: /app/truffle-config.js + - type: bind + source: ./nightfall-deployer/entrypoint.sh + target: /app/entrypoint.sh + + optimist1: + + build: + dockerfile: optimist.Dockerfile + context: . + volumes: + + - type: bind + source: ./nightfall-optimist/src + target: /app/src + - type: bind + source: ./common-files + target: /common-files + - type: bind + source: ./config/default.js + target: /app/config/default.js + optimist2: + + build: + dockerfile: optimist.Dockerfile + context: . + volumes: + + - type: bind + source: ./nightfall-optimist/src + target: /app/src + - type: bind + source: ./common-files + target: /common-files + - type: bind + source: ./config/default.js + target: /app/config/default.js diff --git a/docker-compose.yml b/docker-compose.yml index 489148549..39c5b620b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,19 +3,8 @@ version: '3.5' # bindings. See the readme for more information. services: client1: - build: - dockerfile: client.Dockerfile - context: . + image: ghcr.io/eyblockchain/nightfall3-client:latest volumes: - - type: bind - source: ./nightfall-client/src - target: /app/src - - type: bind - source: ./common-files - target: /common-files - - type: bind - source: ./config/default.js - target: /app/config/default.js - type: volume source: build target: /app/build @@ -44,23 +33,11 @@ services: OPTIMIST_HOST: optimist1 OPTIMIST_PORT: 80 USE_STUBS: 'false' # make sure this flag is the same as in deployer service - RETRIES: 80 command: [ 'npm', 'run', 'dev' ] client2: - build: - dockerfile: client.Dockerfile - context: . + image: ghcr.io/eyblockchain/nightfall3-client:latest volumes: - - type: bind - source: ./nightfall-client/src - target: /app/src - - type: bind - source: ./common-files - target: /common-files - - type: bind - source: ./config/default.js - target: /app/config/default.js - type: volume source: build target: /app/build @@ -93,22 +70,12 @@ services: worker: # image: 3800decac71d - build: - dockerfile: worker.Dockerfile - context: . + image: ghcr.io/eyblockchain/nightfall3-worker:latest volumes: - type: volume source: proving_files target: /app/output/ - - type: bind - source: ./nightfall-deployer/circuits - target: /app/circuits/ - - type: bind - source: ./zokrates-worker/src - target: /app/src/ - - type: bind - source: ./config/default.js - target: /app/config/default.js + depends_on: - deployer networks: @@ -118,37 +85,11 @@ services: # Temporary container to deploy contracts and circuits and populate volumes deployer: #image: docker.pkg.github.com/eyblockchain/nightfall-deployer/nightfall_deployer:1.1.0 - build: - dockerfile: deployer.Dockerfile - context: . + image: ghcr.io/eyblockchain/nightfall3-deployer:latest volumes: - type: volume source: build target: /app/build/ - - type: bind - source: ./nightfall-deployer/contracts - target: /app/contracts/ - - type: bind - source: ./nightfall-deployer/circuits - target: /app/circuits/ - - type: bind - source: ./nightfall-deployer/src - target: /app/src/ - - type: bind - source: ./common-files - target: /common-files - - type: bind - source: ./config/default.js - target: /app/config/default.js - - type: bind - source: ./nightfall-deployer/migrations - target: /app/migrations - - type: bind - source: ./nightfall-deployer/truffle-config.js - target: /app/truffle-config.js - - type: bind - source: ./nightfall-deployer/entrypoint.sh - target: /app/entrypoint.sh networks: - nightfall_network environment: @@ -178,9 +119,7 @@ services: - nightfall_network optimist1: - build: - dockerfile: optimist.Dockerfile - context: . + image: ghcr.io/eyblockchain/nightfall3-optimist:latest depends_on: - deployer networks: @@ -193,15 +132,6 @@ services: - type: volume source: build target: /app/build/ - - type: bind - source: ./nightfall-optimist/src - target: /app/src - - type: bind - source: ./common-files - target: /common-files - - type: bind - source: ./config/default.js - target: /app/config/default.js environment: WEBSOCKET_PORT: 8080 BLOCKCHAIN_WS_HOST: blockchain1 @@ -213,9 +143,7 @@ services: command: [ 'npm', 'run', 'dev' ] optimist2: - build: - dockerfile: optimist.Dockerfile - context: . + image: ghcr.io/eyblockchain/nightfall3-optimist:latest depends_on: - deployer networks: @@ -228,15 +156,6 @@ services: - type: volume source: build target: /app/build/ - - type: bind - source: ./nightfall-optimist/src - target: /app/src - - type: bind - source: ./common-files - target: /common-files - - type: bind - source: ./config/default.js - target: /app/config/default.js environment: WEBSOCKET_PORT: 8080 BLOCKCHAIN_WS_HOST: blockchain1 @@ -248,11 +167,12 @@ services: command: [ 'npm', 'run', 'dev' ] volumes: - mongodb1: - mongodb2: - proving_files: + mongodb1: null + mongodb2: null + proving_files: null build: + null networks: nightfall_network: driver: bridge diff --git a/start-nightfall b/start-nightfall index faef5475b..f169ba8ab 100755 --- a/start-nightfall +++ b/start-nightfall @@ -12,6 +12,7 @@ usage() echo " -l or --localhost; to connect to an already running blockchain on ws://localhost:8546" echo " -s or --stubs; runs with circuits stubbed out (faster but no checking of ZKP code) - use with either -g or -l" echo " -h or --help; to print this message" + echo " -d or --dev; to bind mount the filesystem and use it for development" echo " -i or --infura; to connect infura ropsten testnet" echo " -r or --ropsten to connect testnet node (Note: please set environment variable ROPSTEN_NODE, FROM_ADDRESS, and ETH_PRIVATE_KEY. Find more description in README.md)" } @@ -48,6 +49,8 @@ while [ -n "$1" ]; do ;; -s | --stubs ) STUBS="-f docker-compose.stubs.yml" ;; + -d | --dev ) DEV="-f docker-compose.dev.yml" + ;; * ) usage exit 1 esac @@ -59,9 +62,9 @@ if [ -z "$FILE" ]; then exit 1 fi # shut down cleanly in the event of a cntl-c etc. We don't want to leave containers running -trap "docker-compose $FILE $STUBS down --remove-orphans -t 1; exit 1" SIGHUP SIGINT SIGTERM +trap "docker-compose $FILE $STUBS $DEV down --remove-orphans -t 1; exit 1" SIGHUP SIGINT SIGTERM -docker-compose -f docker-compose.yml $FILE $STUBS down --remove-orphans +docker-compose -f docker-compose.yml $FILE $STUBS $DEV down --remove-orphans # if-else block checks - volume exist and then removes it. if [[ $(echo $VOLUME_LIST | grep nightfall_3_mongodb1) ]]; then @@ -114,4 +117,5 @@ if [[ -d "$DIR" ]]; then rm -dr common-files/node_modules fi #docker-compose -f docker-compose.yml $FILE up -d deployer -docker-compose $FILE $STUBS up +docker-compose $FILE $STUBS $DEV up -d --remove-orphans +docker-compose logs -f