Skip to content

Commit

Permalink
rebase on env_EcoSys
Browse files Browse the repository at this point in the history
Signed-off-by: otherNet <[email protected]>
  • Loading branch information
otherNet committed May 3, 2023
1 parent f7bbeb8 commit f27e874
Show file tree
Hide file tree
Showing 53 changed files with 1,449 additions and 173 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## GUARDIAN ECOSYSTEM ENVIRONMENT NAME
# if you already started to use actively Guardian leave GUARDIAN_ENV empty when you want to use it as usual
# if you want to use a new environment configure GUARDIAN_ENV with a significative environment name
GUARDIAN_ENV="develop"
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ guardian_build:
cd policy-service && yarn install && yarn build:prod
cd topic-viewer && yarn install && yarn build:prod
cd mrv-sender && yarn install && yarn build:prod
cd frontend && yarn install && yarn build:prod
cd frontend && yarn install && export NODE_OPTIONS=--openssl-legacy-provider && yarn build:prod

guardian_make_env:
cd logger-service && cp .env.example .env && cp .env.docker.example .env.docker
Expand All @@ -51,11 +51,11 @@ guardian_make_env:
cd policy-service && cp .env.example .env && cp .env.docker.example .env.docker

guardian_up_pm2:
docker-compose -f docker-compose-dev.yml up -d mongo message-broker ipfs-node
docker compose -f docker-compose-dev.yml up -d mongo message-broker ipfs-node
pm2 start ecosystem.config.js

guardian_down_pm2:
docker-compose stop mongo
docker-compose rm -s -v mongo
docker compose stop mongo
docker compose rm -s -v mongo
pm2 delete all


53 changes: 36 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,20 @@ If you build with docker [MongoDB V6](https://www.mongodb.com), [NodeJS V16](htt
git clone https://github.com/hashgraph/guardian.git
```

2. Update the following files with your Hedera Testnet account info (see prerequisites) as indicated. Please check complete steps to generate Operation ID and Operator Key by looking at link : [How to Create Operator ID and Operator Key](https://docs.hedera.com/guardian/getting-started/getting-started/how-to-create-operator-id-and-operator-key). There will be other steps in the Demo Usage Guide that will require the generation of Operator IDs and Operator Keys. It is important to mention that the Operator IDs and Operator Keys in the .env will be used to generate demo accounts.
2. Update the following files with your Hedera Testnet account info (see prerequisites) as indicated. Please check complete steps to generate Operation ID and Operator Key by looking at link : [How to Create Operator ID and Operator Key](https://docs.hedera.com/guardian/getting-started/getting-started/how-to-create-operator-id-and-operator-key). There will be other steps in the Demo Usage Guide that will require the generation of Operator IDs and Operator Keys. It is important to mention that the Operator IDs and Operator Keys in the ./guardian/configs/.env.\<GUARDIAN_ENV\>.guardian.system will be used to generate demo accounts.

For example:

in `guardian-service/.env`:

in ./guardian/.env you may choose name of the Guardian platform. Leave the field empty or unspecified if you update a production environment to keep previous data (for more details read at https://github.com/IntellectEU/guardian/blob/feature/environment/docs/environments/Ecosystem-Envitonment.md)
```plaintext
OPERATOR_ID=""
OPERATOR_KEY=""
GUARDIAN_ENV="develop"
```

in `guardian-service/.env.docker`:
in ./guardian/configs/.env.develop.guardian.system

```plaintext
OPERATOR_ID=""
OPERATOR_KEY=""
OPERATOR_ID="..."
OPERATOR_KEY="..."
```

**Note**. You can use the Schema Topic ID (`INITIALIZATION_TOPIC_ID`) already present in the configuration files, or you can specify your own.
Expand All @@ -71,24 +69,24 @@ If you build with docker [MongoDB V6](https://www.mongodb.com), [NodeJS V16](htt

**3.1 Setting up IPFS Local node:**

3.1.1 We need to install and configure any IPFS node.
- 3.1.1 We need to install and configure any IPFS node.

For example: https://github.com/yeasy/docker-ipfs

3.1.2 For setup IPFS local node you need to set variables in `worker-service` folder
- 3.1.2 For setup IPFS local node you need to set variables in the same file ./guardian/configs/.env.develop.guardian.system

```
IPFS_NODE_ADDRESS="..." # Default IPFS_NODE_ADDRESS="http://localhost:5002"
IPFS_PUBLIC_GATEWAY="..." # Default IPFS_PUBLIC_GATEWAY="https://localhost:8080/ipfs/${cid}"
IPFS_PUBLIC_GATEWAY='...' # Default IPFS_PUBLIC_GATEWAY='https://localhost:8080/ipfs/${cid}'
IPFS_PROVIDER="local"
```
**Note**
1. Default IPFS_NODE_ADDRESS="http://localhost:5002"
2. Default IPFS_PUBLIC_GATEWAY="https://localhost:8080/ipfs/${cid}"
2. Default IPFS_PUBLIC_GATEWAY='https://localhost:8080/ipfs/${cid}'

**3.2 Setting up IPFS Web3Storage node:**

3.2.1 For setup IPFS web3storage node you need to set variables in `worker-service` folder:
3.2.1 For setup IPFS web3storage node you need to set variables in the same file ./guardian/configs/.env.develop.guardian.system

```
IPFS_STORAGE_API_KEY="..."
Expand All @@ -100,8 +98,10 @@ If you build with docker [MongoDB V6](https://www.mongodb.com), [NodeJS V16](htt
4. Build and launch with Docker. Please note that this build is meant to be used in production and will not contain any debug information. From the project's root folder:

```shell
docker-compose up -d --build
docker compose up -d --build
```
**Note**. about docker-compose: from the end of June 2023 Compose V1 won’t be supported anymore and will be removed from all Docker Desktop versions. Make sure you use Docker Compose V2 (comes with Docker Desktop > 3.6.0) as at https://docs.docker.com/compose/install/


5. Browse to <http://localhost:3000> and complete the setup.

Expand All @@ -118,6 +118,25 @@ If you want to manually build every component with debug information, then build
### Build and start each component

Install, configure and start all the prerequisites, then build and start each component.
Configure .env file in each service

For example:

in `guardian-service/.env`:
```plaintext
GUARDIAN_ENV="develop"
```

If need to configure OVERRIDE variables add it in .env file.
```plaintext
OVERRIDE="false"
```

in `guardian-service/configs/.env.guardian.develop`:
```plaintext
OPERATOR_ID="..."
OPERATOR_KEY="..."
```

**Note: Once you start each service, please wait for the initialization process to be completed.**

Expand Down Expand Up @@ -329,7 +348,7 @@ Install, configure and start all the prerequisites, then build and start each co
2. Start local development using docker compose
```shell
docker-compose -f docker-compose-dev.yml up --build
docker compose -f docker-compose-dev.yml up --build
```
3. Access local development using <http://localhost:3000> or <http://localhost:4200>
Expand All @@ -345,7 +364,7 @@ Install, configure and start all the prerequisites, then build and start each co
**To run by cleaning Docker cache**:
```shell
docker-compose build --no-cache
docker compose build --no-cache
```
([back to top](readme))
Expand Down
12 changes: 1 addition & 11 deletions api-gateway/.env
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
ENV="develop"
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
SERVICE_CHANNEL="api-gateway"
MRV_ADDRESS="http://localhost:3003/mrv"
MQ_MAX_PAYLOAD="1048576"
#LOG_LEVEL="2"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
GUARDIAN_ENV=""
3 changes: 2 additions & 1 deletion api-gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ COPY --from=interfacesModuleBuilder /usr/local/interfaces/guardian-interfaces-*.
COPY --from=commonModuleBuilder /usr/local/common/guardian-common-*.tgz /tmp/common.tgz
COPY --from=apiGatewayBuilder /usr/local/api-gateway/yarn.lock ./
COPY ./api-gateway/package.json ./
# COPY ./api-gateway/.env.docker ./.env
RUN mkdir -p ./configs
COPY ./api-gateway/configs/* ./configs
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@guardian/interfaces']='file:/tmp/interfaces.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@guardian/common']='file:/tmp/common.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN yarn install --frozen-lockfile
Expand Down
13 changes: 13 additions & 0 deletions api-gateway/configs/.env.gateway
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gateway Service Specialized Variables
SERVICE_CHANNEL="api-gateway"

# Ecosystem Defined Variables
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
MRV_ADDRESS="http://localhost:3003/mrv"
MQ_MAX_PAYLOAD="1048576"
#LOG_LEVEL="2"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
13 changes: 13 additions & 0 deletions api-gateway/configs/.env.gateway.develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gateway Service Specialized Variables
SERVICE_CHANNEL="api-gateway"

# Ecosystem Defined Variables
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
MRV_ADDRESS="http://localhost:3003/mrv"
MQ_MAX_PAYLOAD="1048576"
#LOG_LEVEL="2"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
13 changes: 13 additions & 0 deletions api-gateway/configs/.env.gateway.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Gateway Service Specialized Variables
SERVICE_CHANNEL="api-gateway"

# Ecosystem Defined Variables
HEDERA_NET=""
PREUSED_HEDERA_NET=""
MQ_ADDRESS=""
MRV_ADDRESS=""
MQ_MAX_PAYLOAD=""
#LOG_LEVEL="2"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
22 changes: 22 additions & 0 deletions api-gateway/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moduleAlias from 'module-alias';
import dotenv from 'dotenv';
import 'reflect-metadata'
import fs from 'fs';

moduleAlias.addAliases({
'@api': __dirname + '/api',
Expand All @@ -11,3 +12,24 @@ moduleAlias.addAliases({
});

dotenv.config();

const envPath = process.env.GUARDIAN_ENV ? `./configs/.env.gateway.${process.env.GUARDIAN_ENV}` : './configs/.env.gateway';

if (!process.env.OVERRIDE || process.env.OVERRIDE === 'false'){
console.log('reading from', envPath, 'not overriding');
dotenv.config({ path: envPath});
}else{
try {
const envConfig = dotenv.parse(fs.readFileSync(envPath));
for (const k of Object.keys(envConfig)) {
process.env[k] = envConfig[k]
}
} catch (err) {
if (err.code === 'ENOENT') {
console.log('WARN: Specific environment not loaded');
} else {
throw err;
}
}
}
console.log('Charged Environment',process.env,'\r\n___ . ___');
19 changes: 1 addition & 18 deletions auth-service/.env
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
ENV="develop"
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
SERVICE_CHANNEL="auth-service"
ACCESS_TOKEN_SECRET="youraccesstokensecret"
DB_HOST="localhost"
DB_DATABASE="auth_db"
VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS="http://localhost:8200"
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
MQ_MAX_PAYLOAD="1048576"
#LOG_LEVEL="2"
#HASHICORP_USEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
GUARDIAN_ENV=""
3 changes: 2 additions & 1 deletion auth-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ COPY --from=interfacesModuleBuilder /usr/local/interfaces/guardian-interfaces-*.
COPY --from=commonModuleBuilder /usr/local/common/guardian-common-*.tgz /tmp/common.tgz
COPY --from=authServiceBuilder /usr/local/auth-service/yarn.lock ./
COPY ./auth-service/package.json ./
# COPY ./auth-service/.env.docker ./.env
RUN mkdir -p ./configs
COPY ./auth-service/configs/* ./configs
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@guardian/interfaces']='file:/tmp/interfaces.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN node -e "const fs=require('fs'); const input=JSON.parse(fs.readFileSync('package.json')); input.dependencies['@guardian/common']='file:/tmp/common.tgz'; fs.writeFileSync('package.json', JSON.stringify(input));"
RUN yarn install --frozen-lockfile
Expand Down
20 changes: 20 additions & 0 deletions auth-service/configs/.env.auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Auth Service Specialized Variables
SERVICE_CHANNEL="auth-service"
DB_DATABASE="auth_db"

# Ecosystem Defined Variables
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
ACCESS_TOKEN_SECRET="youraccesstokensecret"
DB_HOST="localhost"
VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS="http://localhost:8200"
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
MQ_MAX_PAYLOAD="1048576"
#LOG_LEVEL="2"
#HASHICORP_UNSEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
20 changes: 20 additions & 0 deletions auth-service/configs/.env.auth.develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Auth Service Specialized Variables
SERVICE_CHANNEL="auth-service"
DB_DATABASE="auth_db"

# Ecosystem Defined Variables
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
ACCESS_TOKEN_SECRET="youraccesstokensecret"
DB_HOST="localhost"
VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS="http://localhost:8200"
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
MQ_MAX_PAYLOAD="1048576"
#LOG_LEVEL="2"
#HASHICORP_UNSEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
20 changes: 20 additions & 0 deletions auth-service/configs/.env.auth.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Auth Service Specialized Variables
SERVICE_CHANNEL="auth-service"
DB_DATABASE="auth_db"

# Ecosystem Defined Variables
HEDERA_NET=""
PREUSED_HEDERA_NET=""
MQ_ADDRESS=""
ACCESS_TOKEN_SECRET="youraccesstokensecret"
DB_HOST=""
VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS=""
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
MQ_MAX_PAYLOAD=""
#LOG_LEVEL="2"
#HASHICORP_UNSEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
22 changes: 22 additions & 0 deletions auth-service/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import moduleAlias from 'module-alias';
import dotenv from 'dotenv';
import fs from 'fs';

moduleAlias.addAliases({
'@api': __dirname + '/api',
Expand All @@ -8,3 +9,24 @@ moduleAlias.addAliases({
});

dotenv.config();

const envPath = process.env.GUARDIAN_ENV ? `./configs/.env.auth.${process.env.GUARDIAN_ENV}` : './configs/.env.auth';

if (!process.env.OVERRIDE || process.env.OVERRIDE === 'false'){
console.log('reading from', envPath, 'not overriding');
dotenv.config({ path: envPath});
}else{
try {
const envConfig = dotenv.parse(fs.readFileSync(envPath));
for (const k of Object.keys(envConfig)) {
process.env[k] = envConfig[k]
}
} catch (err) {
if (err.code === 'ENOENT') {
console.log('WARN: Specific environment not loaded');
} else {
throw err;
}
}
}
console.log('Charged Environment',process.env,'\r\n___ . ___');
6 changes: 3 additions & 3 deletions common/src/helpers/db-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { GridFSBucket } from 'mongodb';
export const COMMON_CONNECTION_CONFIG: any = {
type: 'mongo',
namingStrategy: DataBaseNamingStrategy,
dbName: (process.env.ENV||(process.env.HEDERA_NET!==process.env.PREUSED_HEDERA_NET))?
`${process.env.ENV}_${process.env.HEDERA_NET}_${process.env.DB_DATABASE}`:
process.env.DB_DATABASE,
dbName: (process.env.GUARDIAN_ENV||(process.env.HEDERA_NET!==process.env.PREUSED_HEDERA_NET))?
`${process.env.GUARDIAN_ENV}_${process.env.HEDERA_NET}_${process.env.DB_DATABASE}`:
process.env.DB_DATABASE,
clientUrl:`mongodb://${process.env.DB_HOST}`,
entities: [
'dist/entity/*.js'
Expand Down
Loading

0 comments on commit f27e874

Please sign in to comment.