Browse Source

Add cross platform helper scripts for docker

develop
Apostolos Fanakis 4 years ago
parent
commit
ddc361d8e8
  1. 197
      docker/docker.js
  2. 39
      package.json
  3. 25
      yarn.lock

197
docker/docker.js

@ -0,0 +1,197 @@
#! /usr/bin/env node
var shell = require("shelljs");
var target = process.argv[2];
var pwd;
switch (target) {
// ===========================================================================
// Targets for building/running/stopping the blockchain and rendezvous server
// ===========================================================================
case 'build':
shell.cd('docker');
shell.exec('docker-compose -f ./docker-compose.yml -p concordia build');
break;
case 'run':
shell.cd('docker');
shell.exec('docker-compose -f ./docker-compose.yml -p concordia up -d');
break;
case 'stop':
shell.cd('docker');
shell.exec('docker-compose -f ./docker-compose.yml -p concordia down');
break;
case 'stop-clean-data':
shell.cd('docker');
shell.exec('docker-compose -f ./docker-compose.yml -p concordia down -v');
break;
// ===========================================================================
// Ganache targets
// ===========================================================================
case 'build-ganache':
shell.cd('docker');
shell.exec('docker build ../ -f ./ganache/Dockerfile -t concordia-ganache');
break;
case 'run-ganache':
shell.cd('docker');
pwd = shell.pwd();
shell.exec('docker network create --driver bridge concordia_ganache_network');
shell.exec(`docker run
-d
-v ${pwd}/volumes/ganache_db:/home/ganache_db\
-v ${pwd}/volumes/ganache_keys:/home/ganache_keys\
-p 8545:8545\
--env-file=./env/ganache.env\
--name concordia-ganache\
--net=concordia_ganache_network\
concordia-ganache:latest`);
break;
case 'run-ganache-test':
shell.cd('docker');
shell.exec('docker network create --driver bridge concordia_ganache_test_network');
shell.exec(`docker run\
--rm\
-d\
-p 8546:8546\
--env-file=./env/ganache.test.env\
--name concordia-ganache-test\
--net=concordia_ganache_test_network\
concordia-ganache:latest`);
break;
// ===========================================================================
// Rendezvous targets
// ===========================================================================
case 'run-rendezvous':
shell.cd('docker');
shell.exec('docker network create --driver bridge concordia_rendezvous_network');
shell.exec(`docker run\
-d\
-p 9090:9090\
--name concordia-rendezvous\
libp2p/js-libp2p-webrtc-star:version-0.20.1`);
break;
// Contracts targets
case 'build-contracts':
shell.cd('docker');
shell.exec(`docker build\
../\
-f ./concordia-contracts/Dockerfile\
--target compile\
-t concordia-contracts\
--build-arg TZ=Europe/Athens`);
break;
case 'build-contracts-migrate':
shell.cd('docker');
shell.exec(`docker build\
../\
-f ./concordia-contracts/Dockerfile\
-t concordia-contracts-migrate\
--build-arg TZ=Europe/Athens`);
break;
case 'build-contracts-tests':
shell.cd('docker');
shell.exec(`docker build\
../\
-f ./concordia-contracts/Dockerfile\
--target test\
-t concordia-contracts-tests\
--build-arg TZ=Europe/Athens`);
break;
case 'run-contract-tests':
shell.cd('docker');
pwd = shell.pwd();
shell.exec(`docker run\
--rm\
-v ${pwd}/reports/contracts/:/usr/test-reports/\
--env-file=./env/contracts.docker.env\
--net=concordia_ganache_test_network\
concordia-contracts-tests:latest`);
break;
case 'run-contract-tests-host-chain':
shell.cd('docker');
pwd = shell.pwd();
shell.exec(`docker run\
--rm\
-v ${pwd}/reports/contracts/:/usr/test-reports/\
--env-file=./env/contracts.env\
--net=host concordia-contracts-tests:latest`);
break;
case 'run-contracts-migrate':
pwd = shell.pwd();
shell.exec(`docker run\
--rm\
-v ${pwd}/packages/concordia-contracts/build/:/usr/src/concordia/packages/concordia-contracts/build/\
--env-file=./docker/env/contracts.docker.env\
--net=concordia_ganache_network\
concordia-contracts-migrate:latest`);
break;
case 'run-contracts-migrate-host-chain':
pwd = shell.pwd();
shell.exec(`docker run\
--rm\
-v ${pwd}/packages/concordia-contracts/build/:/usr/src/concordia/packages/concordia-contracts/build/\
--env-file=./docker/env/contracts.env\
--net=host\
concordia-contracts-migrate:latest`);
break;
case 'get-contracts':
pwd = shell.pwd();
shell.exec(`docker run\
--rm\
-v ${pwd}/packages/concordia-contracts/build/:/build\
--entrypoint=sh\
concordia-contracts:latest\
-c 'cp /usr/src/concordia/packages/concordia-contracts/build/* /build'`);
break;
// ===========================================================================
// App targets
// ===========================================================================
case 'build-app':
shell.cd('docker');
shell.exec(`docker build\
../\
-f ./concordia-app/Dockerfile\
-t concordia-app\
--build-arg TZ=Europe/Athens`);
break;
case 'build-app-tests':
shell.cd('docker');
shell.exec(`docker build\
../\
-f ./concordia-app/Dockerfile\
--target test\
-t concordia-app-tests\
--build-arg TZ=Europe/Athens`);
break;
case 'run-app-tests':
shell.cd('docker');
pwd = shell.pwd();
shell.exec(`docker run\
--rm\
-v ${pwd}/reports/app/:/usr/test-reports/\
--env-file=./env/concordia.docker.env\
concordia-app-tests:latest`);
break;
case 'run-app':
shell.cd('docker');
shell.exec(`docker create\
--env-file=./env/concordia.docker.env\
-p 8473:80\
--name concordia-app\
--net=concordia_ganache_network\
concordia-app:latest`);
shell.exec('docker network connect concordia_rendezvous_network concordia-app');
shell.exec('docker start concordia-app');
break;
case 'run-app-host-chain':
shell.exec(`docker run\
-d\
--env-file=./env/concordia.env\
--name concordia-app\
--net=host\
concordia-app:latest`)
break;
}

39
package.json

@ -2,7 +2,42 @@
"name": "concordia", "name": "concordia",
"private": true, "private": true,
"workspaces": { "workspaces": {
"packages": ["packages/*"], "packages": [
"nohoist": ["**/web3", "**/web3/**"] "packages/*"
],
"nohoist": [
"**/web3",
"**/web3/**"
]
},
"scripts": {
"build": "docker/docker.js build",
"run": "docker/docker.js run",
"stop": "docker/docker.js stop",
"stop-clean-data": "docker/docker.js stop-clean-data",
"build-ganache": "docker/docker.js build-ganache",
"run-ganache": "docker/docker.js run-ganache",
"run-ganache-test": "docker/docker.js run-ganache-test",
"run-rendezvous": "docker/docker.js run-rendezvous",
"build-contracts": "docker/docker.js build-contracts",
"build-contracts-migrate": "docker/docker.js build-contracts-migrate",
"build-contracts-tests": "docker/docker.js build-contracts-tests",
"run-contract-tests": "docker/docker.js run-contract-tests",
"run-contract-tests-host-chain": "docker/docker.js run-contract-tests-host-chain",
"run-contracts-migrate": "docker/docker.js run-contracts-migrate",
"run-contracts-migrate-host-chain": "docker/docker.js run-contracts-migrate-host-chain",
"get-contracts": "docker/docker.js get-contracts",
"build-app": "docker/docker.js build-app",
"build-app-tests": "docker/docker.js build-app-tests",
"run-app-tests": "docker/docker.js run-app-tests",
"run-app": "docker/docker.js run-app",
"run-app-host-chain": "docker/docker.js run-app-host-chain"
},
"devDependencies": {
"shelljs": "^0.8.4"
} }
} }

25
yarn.lock

@ -7146,7 +7146,7 @@ glob-to-regexp@^0.3.0:
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs= integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=
glob@7.1.6, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: glob@7.1.6, glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
version "7.1.6" version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@ -7991,6 +7991,11 @@ internal-slot@^1.0.2:
has "^1.0.3" has "^1.0.3"
side-channel "^1.0.2" side-channel "^1.0.2"
interpret@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
invariant@^2.2.2, invariant@^2.2.4: invariant@^2.2.2, invariant@^2.2.4:
version "2.2.4" version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@ -14539,6 +14544,13 @@ receptacle@^1.3.2:
dependencies: dependencies:
ms "^2.1.1" ms "^2.1.1"
rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
dependencies:
resolve "^1.1.6"
recursive-readdir@2.2.2: recursive-readdir@2.2.2:
version "2.2.2" version "2.2.2"
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f" resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f"
@ -14822,7 +14834,7 @@ resolve@1.15.0:
dependencies: dependencies:
path-parse "^1.0.6" path-parse "^1.0.6"
resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.3.2, resolve@^1.8.1: resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.3.2, resolve@^1.8.1:
version "1.19.0" version "1.19.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.19.0.tgz#1af5bf630409734a067cae29318aac7fa29a267c"
integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg== integrity sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==
@ -15311,6 +15323,15 @@ shell-quote@1.7.2:
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2" resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg== integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
shelljs@^0.8.4:
version "0.8.4"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2"
integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"
shellwords@^0.1.1: shellwords@^0.1.1:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"

Loading…
Cancel
Save