Skip to content

Commit

Permalink
Merge pull request #16 from lacchain/didCreation
Browse files Browse the repository at this point in the history
Did creation
  • Loading branch information
eum602 authored May 26, 2023
2 parents 445e52c + 0adab43 commit dd35c90
Show file tree
Hide file tree
Showing 37 changed files with 2,082 additions and 24 deletions.
26 changes: 24 additions & 2 deletions .example.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#PORT

PORT = 3000
PORT = 80 # use port 80 when running with docker
EXPOSED_CONTAINER_SERVER_PORT = 3001

#DOCS

Expand All @@ -12,17 +13,19 @@ TYPEORM_TYPE = postgres
TYPEORM_HOST = localhost
TYPEORM_USERNAME = postgres
TYPEORM_PASSWORD = postgres
TYPEORM_DATABASE = express_api_base_development
TYPEORM_DATABASE = laccpass_identity
TYPEORM_PORT = 5432
TYPEORM_SYNCHRONIZE = false
TYPEORM_LOGGING = true
TYPEORM_MIGRATIONS_RUN = true
EXPOSED_CONTAINER_TYPEORM_PORT = 5433

#REDIS

REDIS_HOST = redis
REDIS_PORT = 6379
REDIS_PASSWORD = redis
EXPOSED_CONTAINER_REDIS_PORT = 6380

#TOKEN

Expand All @@ -49,3 +52,22 @@ SENDGRID_API_KEY=<API-KEY>

#Email
EMAIL_TRANSPORTER = AWS

# EXTERNAL SERVICES
# IS_DEPENDENT_SERVICE = true # uncomment this only if the service communicates with the other components by way of external services
KEY_MANAGER_BASE_URL=http://laccpass-key-manager/api/v1
SECP256K1_KEY=/secp256k1
SECP256K1_SIGN_ETHEREUM_TRANSACTION=/secp256k1/sign/ethereum-tx
SECP256K1_SIGN_LACCHAIN_TRANSACTION=/secp256k1/sign/lacchain-tx

# Did Registry
CHAIN_ID = 0x9e55c
# DID_REGISTRY_ADDRESS = 0x00f23cda3cbec27ae630894dd84e88033676d136 # optional address, just in case you are willing to use another did registry
# DOMAIN_NAME = lacchain.id # optional param just in case you are willing to use another domain name

# Blockchain Connection
# for open protestnet: 'http://35.185.112.219'
# for mainnet: TBD
NODE_RPC_URL = http://35.185.112.219
#Node Address depends on the lacchain node you are connecting with
NODE_ADDRESS = 0xad730de8c4bfc3d845f7ce851bcf2ea17c049585
4 changes: 4 additions & 0 deletions .example.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ SENDGRID_API_KEY=<API-KEY>

#Email
EMAIL_TRANSPORTER = AWS

# EXTERNAL SERVICES
KEY_MANAGER_BASE_URL=http://laccpass-key-manager/api/v1
SECP256K1_KEY=/secp256k1
1 change: 1 addition & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FROM node:16.20.0-alpine
WORKDIR /app
COPY ./package.json .
COPY ./yarn.lock .
COPY tsconfig* ./
COPY ormconfig* ./
COPY src ./src
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FROM node:16.20.0-alpine AS production
WORKDIR /app
COPY --from=builder ./app/dist ./dist
COPY package* ./
COPY ./yarn.lock .
COPY tsconfig* ./
COPY prod-paths* ./
COPY ormconfig* ./
Expand Down
58 changes: 58 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: '3'
services:
postgres:
image: postgres:latest
ports:
- '${EXPOSED_CONTAINER_TYPEORM_PORT}:${TYPEORM_PORT}'
environment:
POSTGRES_PASSWORD: ${TYPEORM_PASSWORD}
volumes:
- ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
networks:
- backend
redis:
image: redis:latest
command: redis-server --requirepass ${REDIS_PASSWORD}
ports:
- '${EXPOSED_CONTAINER_REDIS_PORT}:${REDIS_PORT}'
networks:
- backend
node-api-base:
build:
context: ./
dockerfile: Dockerfile.dev
environment:
PORT: "${PORT}"
JWT_SECRET: "${JWT_SECRET}"
TYPEORM_TYPE: postgres
TYPEORM_HOST: postgres
TYPEORM_USERNAME: postgres
TYPEORM_PASSWORD: postgres
TYPEORM_DATABASE: "${TYPEORM_DATABASE}"
TYPEORM_PORT: "${TYPEORM_PORT}"
TYPEORM_SYNCHRONIZE: "true"
TYPEORM_LOGGING: "true"
TYPEORM_MIGRATIONS_RUN: "${TYPEORM_MIGRATIONS_RUN}"
ACCESS_TOKEN_LIFE: "${ACCESS_TOKEN_LIFE}"
RATE_LIMIT_WINDOW: "${RATE_LIMIT_WINDOW}"
RATE_LIMIT_MAX_REQUESTS: "${RATE_LIMIT_MAX_REQUESTS}"
ports:
- '${EXPOSED_CONTAINER_SERVER_PORT}:${PORT}'
restart: on-failure
container_name: laccpass-identity-manager
depends_on:
- postgres
- redis
links:
- postgres
- redis
volumes:
- "./src:/app/src"
- /src/node_modules
- ".env.dev:/app/.env.dev"
networks:
- backend
networks:
backend:
name: backend
external: true
28 changes: 21 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ services:
postgres:
image: postgres:latest
ports:
- '${TYPEORM_PORT}:${TYPEORM_PORT}'
- '${EXPOSED_CONTAINER_TYPEORM_PORT}:${TYPEORM_PORT}'
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_PASSWORD: ${TYPEORM_PASSWORD}
volumes:
- ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
- type: bind
source: ./pg-prod-db
target: /var/lib/postgresql/data
volume:
nocopy: true
networks:
- backend
redis:
image: redis:latest
command: redis-server --requirepass ${REDIS_PASSWORD}
ports:
- '${REDIS_PORT}:${REDIS_PORT}'
- '${EXPOSED_CONTAINER_REDIS_PORT}:${REDIS_PORT}'
networks:
- backend
node-api-base:
build:
context: ./
dockerfile: Dockerfile.dev
dockerfile: Dockerfile.prod
environment:
PORT: "${PORT}"
JWT_SECRET: "${JWT_SECRET}"
Expand All @@ -33,7 +42,7 @@ services:
RATE_LIMIT_WINDOW: "${RATE_LIMIT_WINDOW}"
RATE_LIMIT_MAX_REQUESTS: "${RATE_LIMIT_MAX_REQUESTS}"
ports:
- '${PORT}:${PORT}'
- '${EXPOSED_CONTAINER_SERVER_PORT}:${PORT}'
restart: on-failure
container_name: laccpass-identity-manager
depends_on:
Expand All @@ -43,5 +52,10 @@ services:
- postgres
- redis
volumes:
- "./src:/app/src"
- /src/node_modules
- ".env.prod:/app/.env.prod"
networks:
- backend
networks:
backend:
name: backend
external: true
4 changes: 2 additions & 2 deletions docker_postgres_init.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE USER docker WITH PASSWORD 'password' CREATEDB;

CREATE DATABASE express_api_base_development
CREATE DATABASE laccpass_identity_development
WITH OWNER = docker
CONNECTION LIMIT = -1;

CREATE DATABASE express_api_base_test
CREATE DATABASE laccpass_identity
WITH OWNER = docker
CONNECTION LIMIT = -1;

29 changes: 27 additions & 2 deletions docs/tech/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,36 @@ In order to run the app with Docker, you should install or update to the latest
The following commands will build and run all you need to start working on the base, without any other installation requirements. Important: if you already have postgres running locally, you'll need to kill the service before run `docker-compose up`.

```
docker-compose --env-file .env.dev build
docker network create backend
```

```
docker-compose --env-file .env.dev up
docker-compose -f docker-compose-dev.yml --env-file .env.dev build
```

```
docker-compose -f docker-compose-dev.yml --env-file .env.dev up
```


### Testing Docker production images with docker-compose

The following commands will build and run all you need to start working on the base, without any other installation requirements. Important: if you already have postgres running locally, you'll need to kill the service before run `docker-compose up`.

```
docker network create backend
```

```
mkdir pg-prod-db
```

```
docker-compose -f docker-compose.yml --env-file .env.prod build
```

```
docker-compose -f docker-compose.yml --env-file .env.prod up
```

### Deployment with Docker (only for production)
Expand Down
19 changes: 17 additions & 2 deletions ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import {
TYPEORM_LOGGING,
TYPEORM_MIGRATIONS_RUN,
PRODUCTION_ENV,
TYPEORM_TYPE
TYPEORM_TYPE,
IS_DEPENDENT_SERVICE,
log4TSProvider
} from '@config';

import { Secp256k1, Secp256k1DbService } from 'lacpass-key-manager';

const log = log4TSProvider.getLogger('ormConfig');

const config: ConnectionOptions = {
type: TYPEORM_TYPE as 'mysql' | 'postgres' | 'mongodb',
host: TYPEORM_HOST,
Expand All @@ -20,7 +26,7 @@ const config: ConnectionOptions = {
database: TYPEORM_DATABASE,
port: Number.parseInt(TYPEORM_PORT || '5432'),
synchronize: TYPEORM_SYNCHRONIZE === 'true',
logging: TYPEORM_LOGGING === 'true',
logging: TYPEORM_LOGGING === 'true' ? ['error'] : false,
entities: [
PRODUCTION_ENV ? 'dist/src/entities/**/*.js' : 'src/entities/**/*.ts'
],
Expand All @@ -38,4 +44,13 @@ const config: ConnectionOptions = {
}
};

if (IS_DEPENDENT_SERVICE !== 'true') {
log.info('Importing entities from external components');
config.entities?.push(Secp256k1);
// eslint-disable-next-line max-len
typeof Secp256k1DbService; // validates this service exist as of the key-manager version being installed
} else {
log.info('Initializing with local entities');
}

export = config;
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "identity",
"version": "0.0.1",
"name": "lacpass-identity",
"version": "0.0.10",
"description": "Rest api for laccpass identity manager",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
"/dist"
],
"license": "MIT",
"scripts": {
"dev": "yarn && nodemon --watch 'src/**/*.ts' --exec 'ENV=dev ts-node -r tsconfig-paths/register' src/server.ts",
Expand Down Expand Up @@ -63,20 +68,24 @@
"typescript": "^4.9.5"
},
"dependencies": {
"@lacchain/gas-model-provider": "^1.0.1",
"aws-sdk": "^2.1116.0",
"base-x": "^4.0.0",
"bcrypt": "^5.1.0",
"body-parser": "^1.20.0",
"cbor": "^8.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.12.2",
"class-validator-jsonschema": "^2.2.0",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"ethers": "^6.3.0",
"ethers": "^5.6.5",
"express": "^4.17.3",
"express-formidable": "^1.2.0",
"express-rate-limit": "^6.3.0",
"helmet": "^5.0.2",
"jsonwebtoken": "^9.0.0",
"lacpass-key-manager": "^0.0.15",
"morgan": "^1.10.0",
"multer": "^1.4.4",
"nodemailer": "^6.7.3",
Expand All @@ -92,6 +101,8 @@
"tsconfig-paths": "^3.14.1",
"typedi": "^0.10.0",
"typeorm": "^0.2.41",
"typeorm-seeding": "^1.6.1"
"typeorm-seeding": "^1.6.1",
"typescript-logging": "^2.1.0",
"typescript-logging-log4ts-style": "^2.1.0"
}
}
5 changes: 5 additions & 0 deletions prod-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ for (const path in paths) {
paths[path][0] = paths[path][0]
.replace('src', 'dist/src')
.replace('.ts', '.js');
if (paths[path][0] === 'ormconfig') {
paths[path][0] = paths[path][0]
.replace('ormconfig', 'dist/ormconfig')
.replace('.ts', '.js');
}
}

tsConfigPaths.register({ baseUrl, paths });
Loading

0 comments on commit dd35c90

Please sign in to comment.