Skip to content

Commit

Permalink
resolve hashgraph#1923,resolve hashgraph#1693
Browse files Browse the repository at this point in the history
Integrate multi env feature
Service Env can Override

Signed-off-by: otherNet <[email protected]>
  • Loading branch information
otherNet committed Apr 6, 2023
1 parent a00aff3 commit 87801bf
Show file tree
Hide file tree
Showing 50 changed files with 15,154 additions and 18,366 deletions.
95 changes: 95 additions & 0 deletions .env.develop.guardian.system
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# ECOSYSTEM ENVIRONMENT VARIABLES AND FEATURES


# HEDERA_NET - MANDATORY
# ---------------------------------------------
HEDERA_NET="testnet"

# PRE USED HEDERA_NET
# ---------------------
# Configure this value just once and keep the same setting for all subsequent configurations.
# If it is first Guardian installation or don't care about your previous data (demo) use default
# or remove from the configuration.
# Otherwise read carfully:
# Definition: as PRE USED hedera network is intended the Hedera network that you already started to use actively
# and where your important data is stored currently when you installed this release.
# for example if you are used to work on Hedera mainnet configure it as
# PREUSED_HEDERA_NET="mainnet"
# Configure this value just once and keep the same setting for all subsequent configurations.
# if not specified default Value is NULL
# better description in intallation document
PREUSED_HEDERA_NET="testnet"
# OVERRIDE="false"

# TESTNET
OPERATOR_ID="0.0.3422318"
OPERATOR_KEY="302e020100300506032b6570042204207a032dab9919a648142572069e8a4ccf34c805215e7099b30abd63fd1c58bd3c"
INITIALIZATION_TOPIC_ID="0.0.2030"

# # LOCALNODE
# LOCALNODE_ADDRESS="..."
# LOCALNODE_PROTOCOL="http"
# OPERATOR_ID="0.0.2"
# OPERATOR_KEY="302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"


# # PREVIEWNET
# OPERATOR_ID="..."
# OPERATOR_KEY="..."
# INITIALIZATION_TOPIC_ID="0.0.155110"

SEND_KEYS_TO_VAULT="TRUE"
CONTRACT_FILE_ID="0.0.6276"

# HEDERA_CUSTOM_NODES={"0.testnet.hedera.com:50211":"0.0.3"}
# HEDERA_CUSTOM_MIRROR_NODES=["testnet.mirrornode.hedera.com:443"]

# MAX_TRANSACTION_FEE="10"

# ADDRESSING / SERVICES
# ----------------------
MQ_ADDRESS="message-broker"

MRV_ADDRESS="http://message-broker:3003/mrv"

DB_HOST="mongo"

ACCESS_TOKEN_SECRET="youraccesstokensecret"

VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS="http://vault:8200"
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
#HASHICORP_UNSEAL_KEY=""

MIN_PRIORITY="0"
MAX_PRIORITY="19"
TASK_TIMEOUT="300"
REFRESH_INTERVAL="60"

IPFS_TIMEOUT="720"
IPFS_PROVIDER="web3storage" # 'web3storage' or 'local'
IPFS_PUBLIC_GATEWAY='https://ipfs.io/ipfs/${cid}'
IPFS_STORAGE_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDUyMTQ1ZTY2OWUwMDdCNDQ2ZDZEZGUxYTlhMGJFZjAyZTM5RjU0ZTEiLCJpc3MiOiJ3ZWIzLXN0b3JhZ2UiLCJpYXQiOjE2NzI2NjEyNzEyMzksIm5hbWUiOiJ3ZWIzU3RvcmFnZUFwaVRrbiJ9.fu12X3XVFRFUSf9eszGid6AHHdGPriqPk4lHfCMEuX4"
IPFS_NODE_ADDRESS="http://ipfs-node:5002"

# FE/DEMO
# --------------
INITIAL_BALANCE="100"
INITIAL_STANDARD_REGISTRY_BALANCE="100"

# COMMONS
# ----------
MESSAGE_LANG="en-US"
LOG_LEVEL="1"
MULTI_POLICY_SCHEDULER="0 0 * * *"

# FEATURES
# --------------
BBS_SIGNATURES_MODE="WASM"
# IMPORT_KEYS_FROM_DB=1
# MQ_MESSAGE_CHUNK=5000000
# RAW_REQUEST_LIMIT="1gb"
# JSON_REQUEST_LIMIT="1mb"

14 changes: 0 additions & 14 deletions .env.example

This file was deleted.

101 changes: 101 additions & 0 deletions .env.template.guardian.system
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# ECOSYSTEM ENVIRONMENT VARIABLES AND FEATURES

# HEDERA NETWORK
# HEDERA_NET - MANDATORY
# ------------------------
HEDERA_NET="testnet"

# PRE USED HEDERA_NET
# ---------------------
# Configure this value just once and keep the same setting for all subsequent configurations.
# If it is first Guardian installation or don't care about your previous data (demo) use default
# or remove from the configuration.
# Otherwise read carfully:
# Definition: as PRE USED hedera network is intended the Hedera network that you already started to use actively
# and where your important data is stored currently when you installed this release.
# for example if you are used to work on Hedera mainnet configure it as
# PREUSED_HEDERA_NET="mainnet"
# Configure this value just once and keep the same setting for all subsequent configurations.
# if not specified default Value is NULL
# PREUSED_HEDERA_NET=""

# OVERRIDE
# ---------
# this paramenter allows to override the environment variables at service level
# with the service-specific environment also if already defined at root level.
# Setting the parameter to "true" is not recommended.
# if not specified default Value "false"
# OVERRIDE="false"

# HEDERA - NETWORKS

# TESTNET
OPERATOR_ID="..."
OPERATOR_KEY="..."
INITIALIZATION_TOPIC_ID="0.0.2030"

# LOCALNODE
# LOCALNODE_ADDRESS="..."
# LOCALNODE_PROTOCOL="http"
# OPERATOR_ID="0.0.2"
# OPERATOR_KEY="302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"

# PREVIEWNET
# OPERATOR_ID="..."
# OPERATOR_KEY="302e020100300506032b657004220420f6cec1af811fe09394d635352e583ac3ce84fc180bf328b9cc21e8f58f67e323"
# INITIALIZATION_TOPIC_ID="0.0.155110"

# HEDERA_CUSTOM_NODES={"0.testnet.hedera.com:50211":"0.0.3"}
# HEDERA_CUSTOM_MIRROR_NODES=["testnet.mirrornode.hedera.com:443"]

CONTRACT_FILE_ID="0.0.6276"

# MAX_TRANSACTION_FEE="10"

# ADDRESSING / SERVICES
# ----------------------
MQ_ADDRESS="message-broker"

MRV_ADDRESS="http://message-broker:3003/mrv"

DB_HOST="mongo"

ACCESS_TOKEN_SECRET="youraccesstokensecret"

SEND_KEYS_TO_VAULT="TRUE"
VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS="http://vault:8200"
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
#HASHICORP_UNSEAL_KEY=""

MIN_PRIORITY="0"
MAX_PRIORITY="19"
TASK_TIMEOUT="300"
REFRESH_INTERVAL="60"
IPFS_TIMEOUT="720"
IPFS_PROVIDER="web3storage" # 'web3storage' or 'local'
IPFS_PUBLIC_GATEWAY='https://ipfs.io/ipfs/${cid}'
IPFS_STORAGE_API_KEY="..."
IPFS_NODE_ADDRESS="http://ipfs-node:5002"

# FE/DEMO
# --------------
INITIAL_BALANCE="100"
INITIAL_STANDARD_REGISTRY_BALANCE="100"

# COMMONS
# ----------
MESSAGE_LANG="en-US"
LOG_LEVEL="1"
MULTI_POLICY_SCHEDULER="0 0 * * *"

# FEATURES
# --------------
BBS_SIGNATURES_MODE="WASM"
# IMPORT_KEYS_FROM_DB=1
# MQ_MESSAGE_CHUNK=5000000
# RAW_REQUEST_LIMIT="1gb"
# JSON_REQUEST_LIMIT="1mb"

44 changes: 44 additions & 0 deletions .env_SSV
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## GUARDIAN ECOSYSTEM ENVIRONMENT NAME
# if you already started to use actively Guardian leave GUARDIAN_ENV empty
GUARDIAN_ENV="develop"

## VARIABLES DEDICATED TO SPECIFIC SERVICES

#Api-service
API_SERVICE_CHANNEL="api-gateway"

# Auth-service
AUTH_SERVICE_CHANNEL="auth-service"
AUTH_ACCESS_TOKEN_SECRET="youraccesstokensecret"
AUTH_DB_DATABASE="auth_db"

# guardian-service
GUARDIAN_SERVICE_CHANNEL="guardian.1"
GUARDIAN_DB_DATABASE="guardian_db"
GUARDIAN_LOG_LEVEL="1"
GUARDIAN_MULTI_POLICY_SCHEDULER="0 0 * * *"

# logger-service
LOGGER_SERVICE_CHANNEL="logger-service"
LOGGER_DB_DATABASE="logger_db"

# policy-service
POLICY_SERVICE_CHANNEL="policy-service"
POLICY_DB_DATABASE="guardian_db"
POLICY_LOG_LEVEL="1"
POLICY_MULTI_POLICY_SCHEDULER="0 0 * * *"

# worker-service
WORKER_1_SERVICE_CHANNEL="worker.1"
WORKER_2_SERVICE_CHANNEL="worker.2"











1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tsconfig.tsbuildinfo
.pnp.*
node_modules
runtime-data/
000_*

# OSX related metadata removal and IDE nonsense
.DS_store
Expand Down
8 changes: 2 additions & 6 deletions api-gateway/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
MQ_ADDRESS="localhost"
SERVICE_CHANNEL="api-gateway"
MRV_ADDRESS="http://localhost:3003/mrv"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
GUARDIAN_ENV="develop"
OVERRIDE="false"
8 changes: 8 additions & 0 deletions api-gateway/.env.develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HEDERA_NET="testnet"
PREUSED_HEDERA_NET="testnet"
MQ_ADDRESS="localhost"
SERVICE_CHANNEL="api-gateway"
MRV_ADDRESS="http://localhost:3003/mrv"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
6 changes: 4 additions & 2 deletions api-gateway/.env.docker → api-gateway/.env.template.gateway
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
MQ_ADDRESS="message-broker"
HEDERA_NET=""
PREUSED_HEDERA_NET=""
MQ_ADDRESS=""
SERVICE_CHANNEL="api-gateway"
MRV_ADDRESS="http://message-broker:3003/mrv"
MRV_ADDRESS="http://localhost:3003/mrv"
#MQ_MESSAGE_CHUNK=5000000
#RAW_REQUEST_LIMIT="1gb"
#JSON_REQUEST_LIMIT="1mb"
2 changes: 1 addition & 1 deletion api-gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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
# COPY ./api-gateway/.env.docker ./.env
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
23 changes: 23 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 @@ -10,3 +11,25 @@ moduleAlias.addAliases({
});

dotenv.config();

if (!process.env.OVERRIDE || process.env.OVERRIDE === 'false'){
dotenv.config({
path: `.env.${process.env.GUARDIAN_ENV}`,
});
}else{
try {
const envConfig = dotenv.parse(fs.readFileSync(`.env.${process.env.GUARDIAN_ENV}`));
for (const k of Object.keys(envConfig)) {
process.env[k] = envConfig[k]
}
} catch (err) {
if (err.code === 'ENOENT') {
console.log(`WARN: Environment Not Overrided from file .env.${process.env.GUARDIAN_ENV}` );
} else {
throw err;
}
}
}

console.log('Charged Environment',process.env,'\r\n___ . ___');

16 changes: 3 additions & 13 deletions auth-service/.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
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"
#HASHICORP_USEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
GUARDIAN_ENV="develop"
OVERRIDE="false"

15 changes: 15 additions & 0 deletions auth-service/.env.develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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"
#HASHICORP_USEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
10 changes: 6 additions & 4 deletions auth-service/.env.docker → auth-service/.env.template.auth
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
MQ_ADDRESS="message-broker"
HEDERA_NET=""
PREUSED_HEDERA_NET=""
MQ_ADDRESS=""
SERVICE_CHANNEL="auth-service"
ACCESS_TOKEN_SECRET="youraccesstokensecret"
DB_HOST="mongo"
DB_HOST=""
DB_DATABASE="auth_db"
VAULT_PROVIDER="database"
HASHICORP_TOKEN="1234"
HASHICORP_ADDRESS="http://vault:8200"
HASHICORP_ADDRESS="http://localhost:8200"
HASHICORP_NAMESPACE="admin"
HASHICORP_ENCRIPTION_ALG="sha512"
#HASHICORP_UNSEAL_KEY=""
#HASHICORP_USEAL_KEY=""
#IMPORT_KEYS_FROM_DB=1
#MQ_MESSAGE_CHUNK=5000000
2 changes: 1 addition & 1 deletion auth-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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
# COPY ./auth-service/.env.docker ./.env
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
Loading

0 comments on commit 87801bf

Please sign in to comment.