From 2a2d940e7ccf8d2599549056e96a4cc8daabd5f4 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 26 Aug 2021 09:21:08 -0700 Subject: [PATCH] fix(startup): Adding startup and env var settings --- bin/server.js | 6 ++++++ config/env/common.js | 7 ++++++- config/env/production.js | 5 ++++- docker-compose.yml | 25 ------------------------- production/cleanup-images.sh | 5 +++++ production/docker-compose.yml | 26 ++++++++++++++++++++++++++ production/start-production | 27 +++++++++++++++++++++++++++ src/adapters/ipfs/ipfs-coord.js | 3 ++- 8 files changed, 76 insertions(+), 28 deletions(-) delete mode 100644 docker-compose.yml create mode 100755 production/cleanup-images.sh create mode 100644 production/docker-compose.yml diff --git a/bin/server.js b/bin/server.js index 04638b6..e8b37d0 100644 --- a/bin/server.js +++ b/bin/server.js @@ -39,11 +39,17 @@ class Server { // Connect to the Mongo Database. mongoose.Promise = global.Promise mongoose.set('useCreateIndex', true) // Stop deprecation warning. + console.log( + `Connecting to MongoDB with this connection string: ${config.database}` + ) await mongoose.connect(config.database, { useUnifiedTopology: true, useNewUrlParser: true }) + console.log(`Starting environment: ${config.env}`) + console.log(`Debug level: ${config.debugLevel}`) + // MIDDLEWARE START app.use(convert(logger())) diff --git a/config/env/common.js b/config/env/common.js index 92003ff..4f00938 100644 --- a/config/env/common.js +++ b/config/env/common.js @@ -71,5 +71,10 @@ module.exports = { // IPFS Ports ipfsTcpPort: process.env.IPFS_TCP_PORT ? process.env.IPFS_TCP_PORT : 4001, - ipfsWsPort: process.env.IPFS_WS_PORT ? process.env.IPFS_WS_PORT : 4003 + ipfsWsPort: process.env.IPFS_WS_PORT ? process.env.IPFS_WS_PORT : 4003, + + // BCH Mnemonic for generating encryption keys and payment address + mnemonic: process.env.MNEMONIC ? process.env.MNEMONIC : '', + + debugLevel: process.env.DEBUG_LEVEL ? parseInt(process.env.DEBUG_LEVEL) : 2 } diff --git a/config/env/production.js b/config/env/production.js index b4b2f1c..c138976 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -10,6 +10,9 @@ module.exports = { session: 'secret-boilerplate-token', token: 'secret-jwt-token', - database: 'mongodb://172.17.0.1:5555/ipfs-service-prod', + // database: 'mongodb://172.17.0.1:5555/ipfs-service-prod', + database: process.env.DBURL + ? process.env.DBURL + : 'mongodb://172.17.0.1:5555/ipfs-service-prod', env: 'prod' } diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 67d0af8..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,25 +0,0 @@ -# Start the testnet server with the command 'docker-compose up -d' - -koa-mongodb: - image: mongo - container_name: mongo-koa - ports: - - "5555:27017" # : - volumes: - - ./database:/data/db - command: mongod --smallfiles --logpath=/dev/null # -- quiet - restart: always - -koa: - build: ./production/ - dockerfile: Dockerfile - container_name: koa - links: - - koa-mongodb - ports: - - "5001:5001" # : - volumes: -# - ./logs:/home/coinjoin/consolidating-coinjoin/logs - - ./keys:/home/safeuser/keys - - restart: always diff --git a/production/cleanup-images.sh b/production/cleanup-images.sh new file mode 100755 index 0000000..405d9f5 --- /dev/null +++ b/production/cleanup-images.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Remove all untagged docker images. +docker rmi $(docker images | grep "^" | awk '{print $3}') + diff --git a/production/docker-compose.yml b/production/docker-compose.yml new file mode 100644 index 0000000..325c9eb --- /dev/null +++ b/production/docker-compose.yml @@ -0,0 +1,26 @@ +# Start the testnet server with the command 'docker-compose up -d' + +mongo-ipfs-service: + image: mongo + container_name: mongo-ipfs-service + ports: + - '5555:27017' # : + volumes: + - ./database:/data/db + command: mongod --logpath=/dev/null # -- quiet + restart: always + +ipfs-service: + build: . + dockerfile: Dockerfile + container_name: ipfs-service + links: + - mongo-ipfs-service + ports: + - '5001:5001' # : + volumes: + # - ./logs:/home/coinjoin/consolidating-coinjoin/logs + #- ./keys:/home/safeuser/keys + - ../.ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata + + restart: always diff --git a/production/start-production b/production/start-production index 46433e1..d09f909 100755 --- a/production/start-production +++ b/production/start-production @@ -1,3 +1,30 @@ #!/bin/bash + +# BEGIN: Optional configuration settings + +# This mnemonic is used to set up persistent public key for e2ee +export MNEMONIC="olive two muscle bottom coral ancient wait legend bronze useful process session" + +# The human readable name this IPFS node identifies as. +export COORD_NAME=ipfs-service-provider-generic + +# Allow this node to function as a circuit relay. It must not be behind a firewall. +#export ENABLE_CIRCUIT_RELAY=true + +export DEBUG_LEVEL=2 + +# END: Optional configuration settings + + +# Production database connection string. +export DBURL=mongodb://172.17.0.1:5555/ipfs-service-prod + +# Configure IPFS ports +export IPFS_TCP_PORT=4001 +export IPFS_WS_PORT=4003 + +# Configure REST API port +export PORT=5001 + export SVC_ENV=production npm start diff --git a/src/adapters/ipfs/ipfs-coord.js b/src/adapters/ipfs/ipfs-coord.js index 1477679..feb4ec9 100644 --- a/src/adapters/ipfs/ipfs-coord.js +++ b/src/adapters/ipfs/ipfs-coord.js @@ -46,7 +46,8 @@ class IpfsCoordAdapter { privateLog: console.log, // Default to console.log isCircuitRelay: this.config.isCircuitRelay, apiInfo: this.config.apiInfo, - announceJsonLd: this.config.announceJsonLd + announceJsonLd: this.config.announceJsonLd, + debugLevel: this.config.debugLevel }) // Wait for the ipfs-coord library to signal that it is ready.