Skip to content

Commit

Permalink
Closes #71 #73 (#74)
Browse files Browse the repository at this point in the history
* Closes #71. Add /docs. CI. Fill readme.

* Closes #71. Add /docs. CI. Fill readme.

* Closes #73. Move KYC api credentials to .env.

* Closes #71. Travis.

* Closes #71. Travis. Add storage folder to .dockerignore.

* Closes #71. Fix travis.yml.

* Closes #71. Optimize prod image size.

* Closes #71. Optimize prod image size. Fix Dockerfile.prod.
  • Loading branch information
artemii235 committed Dec 27, 2017
1 parent 8fa6f16 commit 7ff617f
Show file tree
Hide file tree
Showing 18 changed files with 842 additions and 46 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage
.nyc_output
dist
.env
storage
18 changes: 18 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
MONGO_URL='mongodb://mongo:27017/ico-dashboard'
ORM_ENTITIES_DIR="src/entities/**/*.ts"
ORM_SUBSCRIBER_DIR="src/subscriber/**/*.ts"
ORM_MIGRATIONS_DIR="src/migrations/**/*.ts"
API_URL="https://stage-ico-back.jincor.com"
FRONTEND_URL="https://invest.jincor.com"
AUTH_JWT='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNlNTc1NWZmLTQ1ZDItNGZjZi1iZjk0LTZmZGE2YWUxYzVlOCIsImxvZ2luIjoidGVuYW50OnRlc3RAdGVzdC5jb20iLCJqdGkiOiJjZTU3NTVmZi00NWQyLTRmY2YtYmY5NC02ZmRhNmFlMWM1ZTgxNTExODk1MDM3MjQzIiwiaWF0IjoxNTExODk1MDM3MjQzLCJhdWQiOiJqaW5jb3IuY29tIiwiaXNUZW5hbnQiOnRydWV9.fzV8htVMypwYV50mrPtp-0Xe4C-sDYXWL_YyOyZ1e3M'
AUTH_BASE_URL="http://auth:3000"
VERIFY_BASE_URL="http://verify:3000"
REDIS_URL="redis://redis:6379"
ICO_SC_ADDRESS='0x7672210729e053B2462D39CF3746A5d19B405aAD'
WHITELIST_SC_ADDRESS='0x3c97c521cc60e3c6bb8b568d36d7d2f7fa2435fb'
JCR_TOKEN_ADDRESS='0x1a164bd1a4bd6f26726dba43972a91b20e7d93be'
RPC_TYPE='http'
RPC_ADDRESS='https://ropsten.infura.io/ujGcHij7xZIyz2afx4h2'
WEB3_RESTORE_START_BLOCK=2015593
HTTP_SERVER=enabled
ENVIRONMENT=test
2 changes: 1 addition & 1 deletion .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"lines": 80,
"statements": 80,
"functions": 80,
"branches": 79,
"branches": 68,
"include": [
"**/*.ts"
],
Expand Down
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sudo: required
services:
- docker
before_install:
- docker login -u $DOCKER_USER -p $DOCKER_PASS
- chmod ugo+x ./build.sh
script:
- cp -r .env.test .env
- docker-compose build
- docker-compose up -d
- docker-compose exec ico npm i
- docker-compose exec ico npm test
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "production"; elif [ "$TRAVIS_BRANCH"
== "develop" ]; then echo "stage"; else echo "dev-$(git rev-parse --short HEAD)"
; fi`
- "./build.sh $TAG"
env:
global:
- secure: 37DSPYwReJU811Bj/f8Dsn9JrD/tZ1dz7rOiE9N6wAefJ1iHCzV91Ot8mxUx7er6FP8KYe4tk3XBETqgorcLpVteU0a2UjWY/Hp8LGGlO4fsGQ+GZxj4lwx9vtj8TEhnPI/b9Q94a7Kyn9HIGrIMzPJkF45W/IWEiHiyJlsrfUKpEb6ciOnw2WCnnvMmTbb/j7mwMbziRJrlA6pIeslirWxQAUenbOD6bM7EQadgqRSRQvL5w6nXR4ychjkHPC6sUZD5sDu//UJaXqN8b25gcBCcspjmvJqvhlhYOaiYauRdZAOburi8iV6lutLQaU0fMtUGByLf0N+DRobYaHKEl5KX7JfY/pW/uq0ZEJJpdBEujtHVpFziUe4wfU0IgbgQjaR2gQJyDgXzCcC/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ObhfmHnkccgAQcSmXVN+2AGva2caWNA8mA6UD3GOiv/+xzi3nW85t6wYOwNvYmCJjU1pRcA1BnCxkzvkHAxCv0xmWKGcdcSvhG1PBV2VPmPC2pEv3WDKlyEuxXDD1UrED/dXJVnMGifx+o4qp2vSQtpgIKbXk+5tH8xmQjT0BfXjP2u+ppFUKVLJQIMWxP4p9/kTxhrpiQpeQjVa5jzdUwJWzDnrIVdQNJfBXJ3euK05A/lQSBZBc+8UZBAWGKIYIHtw+I+QUTT/wFIej5no9qmCMArNP/zXIp9kt4OuvqyYB4xVLcMW9uWTqFNHs6pkk6LGpJ20RSl0MV+Hx7nP2k13MTnZFKyQK1dmS3Vkv4wLC5fJLC7Lrgk6vnqXJ502m5NHAPGpvRvQnvvBzJ0bnZkb/0YRRecXJDslQNDx7sawOdV0nACEtO997euvvKQTUSw+fVzoMUfpF7QjlT4QhnLqLK1745tqKF82JVgeZ2BQUCiZMJ6P4UBjpgDQaCXAuMVRemcn70b+dS66L39ZwjHgPI8P7/VwwwqM9egDqEIGXCGtPevT6CY7r+rP3J282U="
11 changes: 7 additions & 4 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
FROM mhart/alpine-node:8.6

RUN apk update && apk upgrade && apk add git && apk add python && apk add make && apk add g++

RUN mkdir -p /usr/src/app
ADD . /usr/src/app

WORKDIR /usr/src/app

RUN npm i
RUN npm run build
RUN cp -r src/certs dist/

RUN apk add --update --no-cache git python make g++ && \
npm install && \
npm run build && \
npm prune --production && \
apk del --purge git python make g++ && \
rm -rf ./src

CMD npm run serve
14 changes: 0 additions & 14 deletions Dockerfile.stage

This file was deleted.

37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# backend-ico-dashboard
This is backend module for Jincor ICO dashboard.
![](https://habrastorage.org/webt/59/d5/42/59d542206afbe280817420.png)

# Jincor ICO Dashboard Backend
This is backend module of Jincor ICO dashboard: https://contribute.jincor.com.

It was implemented to provide following functionality:
1. ICO investors sign up.
1. Generation of Ethereum address upon user activation.
1. KYC verification using Jumio Netverify service (https://www.jumio.com/trusted-identity/netverify).
1. Token purchase.
1. Displaying Investor's transaction history.
1. All important actions are protected with 2FA (email or google authenticator) by integration with Jincor Backend Verify service (https://github.com/JincorTech/backend-verify)
1. For more info check API docs: https://jincortech.github.io/backend-ico-dashboard

## Technology stack

1. Typescript, Express, InversifyJS (DI), TypeORM (MongoDB interaction).
1. Web3JS - interaction with Ethereum client. ICO backend supports any JSON-RPC compliant client.
1. Mocha/chai - unit/functional tests.
1. Docker.

## How to start development and run tests?

1. Clone this repo.
1. Run `docker-compose build --no-cache`.
1. Run `docker-compose up -d`.
1. Run `cp .env.test .env`.
1. To install dependencies run `docker-compose exec ico npm i`.
1. Run tests `docker-compose exec ico npm test`.

## How to generate docs?

1. Install aglio `npm install -g aglio`.
1. Run `mkdir /usr/local/lib/node_modules/aglio/node_modules/aglio-theme-olio/cache`.
1. Generate `aglio --theme-variables cyborg --theme-template triple -i apiary.apib -o ./docs/index.html`.
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -ex
IMAGE_NAME="jincort/backend-ico-dashboard"
TAG="${1}"
docker build -t ${IMAGE_NAME}:${TAG} -f Dockerfile.prod .
docker push ${IMAGE_NAME}:${TAG}
1 change: 0 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ services:
- "8546"
volumes:
- /root/parity:/root/.local/share/io.parity.ethereum
- ./passwords:/passwords
restart: always
networks:
default:
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: registry.jincor.com/backend/ico-stage:latest
build:
context: ./
dockerfile: Dockerfile.stage
dockerfile: Dockerfile.prod
ports:
- 80:3000
- 443:4000
Expand Down Expand Up @@ -58,7 +58,6 @@ services:
- "8546"
volumes:
- /root/parity:/root/.local/share/io.parity.ethereum
- ./passwords:/passwords
restart: always
networks:
default:
Expand Down
15 changes: 6 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2'
services:
ico:
image: registry.jincor.com/backend/ico-develop:latest
image: jincort/backend-ico-dashboard:develop
build:
context: ./
dockerfile: Dockerfile
Expand All @@ -25,7 +25,7 @@ services:
ipv4_address: 10.100.0.2

auth:
image: registry.jincor.com/backend/auth:latest
image: jincort/backend-auth:production
environment:
REDIS_HOST: redis
REDIS_PORT: 6379
Expand All @@ -43,7 +43,7 @@ services:
ipv4_address: 10.100.0.3

redis:
image: registry.jincor.com/backend/redis:latest
image: jincort/backend-redis:production
ports:
- "6379"
volumes:
Expand All @@ -53,15 +53,12 @@ services:
ipv4_address: 10.100.0.4

rpc:
image: registry.jincor.com/backend/parity-rpc-ropsten:latest
image: jincort/parity-rpc-dev:latest
build:
context: ./
dockerfile: rpc.ropsten.Dockerfile
dockerfile: rpc.dev.Dockerfile
ports:
- "8546"
volumes:
- /media/artem/Seagate Expansion Drive/parity:/root/.local/share/io.parity.ethereum
- ./passwords:/passwords
networks:
default:
ipv4_address: 10.100.0.5
Expand All @@ -79,7 +76,7 @@ services:
ipv4_address: 10.100.0.6

mongo:
image: registry.jincor.com/backend/mongodb:latest
image: jincort/backend-mongodb:production
volumes:
- ./storage/mongodb:/data/db
networks:
Expand Down
725 changes: 725 additions & 0 deletions docs/index.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
]
},
"dependencies": {
"@types/faker": "4.1.1",
"@types/joi": "10.4.0",
"abi-decoder": "1.0.9",
"bcrypt-nodejs": "0.0.3",
"bip39": "2.4.0",
Expand All @@ -27,28 +25,26 @@
"dotenv": "4.0.0",
"ethereumjs-wallet": "0.6.0",
"express": "~4.14.0",
"faker": "4.1.0",
"inversify": "4.2.0",
"inversify-express-utils": "4.0.0",
"joi": "10.6.0",
"jsonwebtoken": "^7.2.1",
"mailcomposer": "4.0.2",
"mailgun-js": "0.13.1",
"mocha-prepare": "0.1.0",
"mongodb": "2.2.33",
"mongodb-restore": "1.6.2",
"morgan": "1.9.0",
"node-mailjet": "3.2.1",
"node-uuid": "^1.4.7",
"qr-image": "3.2.0",
"reflect-metadata": "0.1.10",
"rolling-rate-limiter": "0.1.9",
"typemoq": "2.0.1",
"typeorm": "0.1.1",
"web-request": "1.0.7",
"web3": "1.0.0-beta.26"
},
"devDependencies": {
"@types/faker": "4.1.1",
"@types/joi": "10.4.0",
"@types/bcrypt-nodejs": "0.0.30",
"@types/bull": "3.0.2",
"@types/chai": "3.4.34",
Expand All @@ -58,6 +54,10 @@
"@types/jsonwebtoken": "7.2.0",
"@types/mocha": "2.2.38",
"@types/node-uuid": "0.0.28",
"mongodb-restore": "1.6.2",
"faker": "4.1.0",
"typemoq": "2.0.1",
"mocha-prepare": "0.1.0",
"chai": "3.5.0",
"chai-http": "3.0.0",
"mocha": "3.2.0",
Expand Down
Empty file removed passwords/testpass
Empty file.
3 changes: 3 additions & 0 deletions rpc.dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM parity/parity:v1.8.3
ENTRYPOINT /parity/parity --no-ui --config dev --ws-origins=all --ws-interface=all
EXPOSE 8546
1 change: 0 additions & 1 deletion rpc.mainnet.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM parity/parity:v1.8.3
VOLUME /passwords
ENTRYPOINT /parity/parity --no-ui --ws-origins=all --ws-interface=all
EXPOSE 8546
1 change: 0 additions & 1 deletion rpc.ropsten.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM parity/parity:v1.8.3
VOLUME /passwords
ENTRYPOINT /parity/parity --no-ui --chain=ropsten --ws-origins=all --ws-interface=all
EXPOSE 8546
14 changes: 9 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const {
MAILJET_API_KEY,
MAILJET_API_SECRET,
WEB3_RESTORE_START_BLOCK,
WL_OWNER_PK
WL_OWNER_PK,
KYC_TOKEN,
KYC_SECRET,
KYC_BASE_URL,
KYC_TOKEN_LIFETIME
} = process.env;

export default {
Expand Down Expand Up @@ -114,10 +118,10 @@ export default {
]
},
kyc: {
apiToken: '68b0d36a-46f4-4336-8f4e-e1f570cea5d9',
apiSecret: 'w37alAxYV9i5bIsiOF9bROvdzMqNlJGZ',
baseUrl: 'https://lon.netverify.com/api/netverify/v2/',
defaultTokenLifetime: 5184000 // 60 days - Jumio max allowed value
apiToken: KYC_TOKEN,
apiSecret: KYC_SECRET,
baseUrl: KYC_BASE_URL,
defaultTokenLifetime: KYC_TOKEN_LIFETIME || 5184000 // 60 days - Jumio max allowed value
},
rpc: {
type: RPC_TYPE,
Expand Down

0 comments on commit 7ff617f

Please sign in to comment.