Merge pull request #62 from Permissionless-Software-Foundation/ct-unstable

Kicking off v2.0.0
This commit is contained in:
Chris Troutner
2021-12-29 18:04:29 -08:00
committed by GitHub
11 changed files with 13826 additions and 16129 deletions
+1
View File
@@ -65,5 +65,6 @@ system-user-*.json
orbitdb orbitdb
ipfsdata ipfsdata
.ipfsdata .ipfsdata
data/
!README.md !README.md
+10
View File
@@ -104,8 +104,18 @@ class Server {
return app return app
} catch (err) { } catch (err) {
console.error('Could not start server. Error: ', err) console.error('Could not start server. Error: ', err)
console.log(
'Exiting after 5 seconds. Depending on process manager to restart.'
)
await sleep(5000)
process.exit(1)
} }
} }
} }
function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
module.exports = Server module.exports = Server
+8 -1
View File
@@ -78,5 +78,12 @@ module.exports = {
// BCH Mnemonic for generating encryption keys and payment address // BCH Mnemonic for generating encryption keys and payment address
mnemonic: process.env.MNEMONIC ? process.env.MNEMONIC : '', mnemonic: process.env.MNEMONIC ? process.env.MNEMONIC : '',
debugLevel: process.env.DEBUG_LEVEL ? parseInt(process.env.DEBUG_LEVEL) : 2 debugLevel: process.env.DEBUG_LEVEL ? parseInt(process.env.DEBUG_LEVEL) : 2,
// Settings for production, using external go-ipfs node.
isProduction: process.env.SVC_ENV === 'production' ? true : false,
ipfsHost: process.env.IPFS_HOST ? process.env.IPFS_HOST : 'localhost',
ipfsApiPort: process.env.IPFS_API_PORT
? parseInt(process.env.IPFS_API_PORT)
: 5001
} }
+13701 -16107
View File
File diff suppressed because it is too large Load Diff
+6 -5
View File
@@ -1,6 +1,6 @@
{ {
"name": "ipfs-service-provider", "name": "ipfs-service-provider",
"version": "1.3.0", "version": "2.0.0",
"description": "A Koa-based combination of a REST API and IPFS JSON RPC. Boilerplate for starting new projects.", "description": "A Koa-based combination of a REST API and IPFS JSON RPC. Boilerplate for starting new projects.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@@ -23,12 +23,13 @@
}, },
"repository": "Permissionless-Software-Foundation/ipfs-service-provider", "repository": "Permissionless-Software-Foundation/ipfs-service-provider",
"dependencies": { "dependencies": {
"@chris.troutner/ipfs": "2.0.2", "@psf/bch-js": "4.20.28",
"@psf/bch-js": "4.20.20",
"axios": "0.21.1", "axios": "0.21.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"glob": "7.1.6", "glob": "7.1.6",
"ipfs-coord": "6.7.6", "ipfs": "0.60.0",
"ipfs-coord": "6.8.0",
"ipfs-http-client": "55.0.0",
"jsonrpc-lite": "2.2.0", "jsonrpc-lite": "2.2.0",
"jsonwebtoken": "8.5.1", "jsonwebtoken": "8.5.1",
"jwt-bch-lib": "1.3.0", "jwt-bch-lib": "1.3.0",
@@ -42,7 +43,7 @@
"koa-passport": "4.1.3", "koa-passport": "4.1.3",
"koa-router": "10.0.0", "koa-router": "10.0.0",
"koa-static": "5.0.0", "koa-static": "5.0.0",
"koa2-ratelimit": "0.9.0", "koa2-ratelimit": "0.9.1",
"line-reader": "0.4.0", "line-reader": "0.4.0",
"mongoose": "5.11.15", "mongoose": "5.11.15",
"node-fetch": "npm:@achingbrain/node-fetch@2.6.7", "node-fetch": "npm:@achingbrain/node-fetch@2.6.7",
+3 -3
View File
@@ -33,8 +33,8 @@ WORKDIR /home/safeuser
#RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'" #RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'"
# Update to the latest version of npm. # Update to the latest version of npm.
# Working with npm@7.21.1 #RUN npm install -g npm@7.23.0
RUN npm install -g npm@7.23.0 RUN npm install -g npm
# npm mirror to prevent direct dependency on npm. # npm mirror to prevent direct dependency on npm.
RUN npm set registry http://94.130.170.209:4873/ RUN npm set registry http://94.130.170.209:4873/
@@ -66,7 +66,7 @@ RUN npm run docs
VOLUME /home/safeuser/keys VOLUME /home/safeuser/keys
# Expose the port the API will be served on. # Expose the port the API will be served on.
EXPOSE 5001 EXPOSE 5010
# Start the application. # Start the application.
COPY start-production.sh start-production.sh COPY start-production.sh start-production.sh
+32 -4
View File
@@ -1,6 +1,6 @@
# Start the service with the command 'docker-compose up -d' # Start the service with the command 'docker-compose up -d'
version: '2' version: '3.9'
services: services:
mongo-ipfs-service: mongo-ipfs-service:
@@ -13,6 +13,35 @@ services:
command: mongod --logpath=/dev/null # -- quiet command: mongod --logpath=/dev/null # -- quiet
restart: always restart: always
ipfs:
image: ipfs/go-ipfs:latest
container_name: ipfs
environment:
MY_ENV_VAR: 'placeholder'
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '10'
mem_limit: 2000mb
ports:
- 4001:4001
- 5001:5001
- 8080:8080
volumes:
- ../data/go-ipfs/data:/data/ipfs
- ../data/go-ipfs/export:/export
# https://docs.docker.com/compose/compose-file/compose-file-v3/#command
# https://github.com/ipfs/go-ipfs/blob/91c52657166bcf86f2476926e4fe56694dc26562/Dockerfile#L115
command:
[
'daemon',
'--migrate=true',
'--agent-version-suffix=docker',
'--enable-pubsub-experiment'
]
restart: always
ipfs-service: ipfs-service:
build: . build: .
container_name: ipfs-service container_name: ipfs-service
@@ -24,10 +53,9 @@ services:
mem_limit: 500mb mem_limit: 500mb
links: links:
- mongo-ipfs-service - mongo-ipfs-service
- ipfs
ports: ports:
- '5001:5001' # <host port>:<container port> - '5010:5010' # <host port>:<container port>
- '5268:5268' # IPFS TCP
- '5269:5269' # IPFS WS
volumes: volumes:
- ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata - ../data/ipfsdata:/home/safeuser/ipfs-service-provider/.ipfsdata
restart: always restart: always
+7 -3
View File
@@ -26,12 +26,16 @@ export DEBUG_LEVEL=1
export DBURL=mongodb://172.17.0.1:5555/ipfs-service-prod export DBURL=mongodb://172.17.0.1:5555/ipfs-service-prod
# Configure IPFS ports # Configure IPFS ports
export IPFS_TCP_PORT=5268 #export IPFS_TCP_PORT=5268
export IPFS_WS_PORT=5269 #export IPFS_WS_PORT=5269
# Configure REST API port # Configure REST API port
export PORT=5001 export PORT=5010
# Production settings using external go-ipfs node.
export SVC_ENV=production export SVC_ENV=production
export IPFS_HOST=172.17.0.1
export IPFS_API_PORT=5001
npm start npm start
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
# This script is an example for running a production environment, which is
# defined by running an external go-ipfs node.
# Ports
export PORT=5010 # REST API port
# The human-readible name that is used when displaying data about this node.
export COORD_NAME=ipfs-service-provider-generic
# This is used for end-to-end encryption (e2ee).
export MNEMONIC="churn aisle shield silver ladder swear hunt slim pen demand spoil veteran"
# 0 = less verbose. 3 = most verbose
export DEBUG_LEVEL=1
# Production settings that use external IPFS node.
# https://github.com/christroutner/docker-ipfs
export SVC_ENV=production
export IPFS_HOST=localhost
export IPFS_API_PORT=5001
# MongoDB connection string.
export DBURL=mongodb://localhost:27017/ipfs-service-dev
npm start
+9 -2
View File
@@ -57,7 +57,7 @@ class IpfsCoordAdapter {
} }
} }
this.ipfsCoord = new this.IpfsCoord({ const ipfsCoordOptions = {
ipfs: this.ipfs, ipfs: this.ipfs,
type: 'node.js', type: 'node.js',
// type: 'browser', // type: 'browser',
@@ -68,7 +68,14 @@ class IpfsCoordAdapter {
apiInfo: this.config.apiInfo, apiInfo: this.config.apiInfo,
announceJsonLd: this.config.announceJsonLd, announceJsonLd: this.config.announceJsonLd,
debugLevel: this.config.debugLevel debugLevel: this.config.debugLevel
}) }
// Production env uses external go-ipfs node.
if (this.config.isProduction) {
ipfsCoordOptions.nodeType = 'external'
}
this.ipfsCoord = new this.IpfsCoord(ipfsCoordOptions)
// Wait for the ipfs-coord library to signal that it is ready. // Wait for the ipfs-coord library to signal that it is ready.
await this.ipfsCoord.start() await this.ipfsCoord.start()
+22 -4
View File
@@ -10,7 +10,9 @@
// Global npm libraries // Global npm libraries
// const IPFS = require('ipfs') // const IPFS = require('ipfs')
const IPFS = require('@chris.troutner/ipfs') // const IPFS = require('@chris.troutner/ipfs')
const IPFSembedded = require('ipfs')
const IPFSexternal = require('ipfs-http-client')
const fs = require('fs') const fs = require('fs')
// Local libraries // Local libraries
@@ -21,11 +23,17 @@ const IPFS_DIR = './.ipfsdata/ipfs'
class IpfsAdapter { class IpfsAdapter {
constructor (localConfig) { constructor (localConfig) {
// Encapsulate dependencies // Encapsulate dependencies
this.IPFS = IPFS this.config = config
// Choose the IPFS constructor based on the config settings.
this.IPFS = IPFSembedded // default
if (this.config.isProduction) {
this.IPFS = IPFSexternal
}
// Properties of this class instance. // Properties of this class instance.
this.isReady = false this.isReady = false
this.config = config
this.fs = fs this.fs = fs
} }
@@ -33,7 +41,7 @@ class IpfsAdapter {
async start () { async start () {
try { try {
// Ipfs Options // Ipfs Options
const ipfsOptions = { const ipfsOptionsEmbedded = {
repo: IPFS_DIR, repo: IPFS_DIR,
start: true, start: true,
config: { config: {
@@ -64,6 +72,16 @@ class IpfsAdapter {
} }
} }
const ipfsOptionsExternal = {
host: this.config.ipfsHost,
port: this.config.ipfsApiPort
}
let ipfsOptions = ipfsOptionsEmbedded
if (this.config.isProduction) {
ipfsOptions = ipfsOptionsExternal
}
// Create a new IPFS node. // Create a new IPFS node.
this.ipfs = await this.IPFS.create(ipfsOptions) this.ipfs = await this.IPFS.create(ipfsOptions)