Skip to content

Commit

Permalink
refs #123 - updates docker compose, server.js server-helm.js and dock…
Browse files Browse the repository at this point in the history
…er file to use environment variables instead of build args
  • Loading branch information
TiagoV-PDMFC committed Nov 9, 2022
1 parent 4b96306 commit 32e3bf7
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 26 deletions.
8 changes: 1 addition & 7 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Docker image build for Finished Goods Traceability (FGT)
#
# docker build --build-arg GIT_BRANCH=v0.10.0 --build-arg BUILD_ENV=dev -t fgt:v0.10.0 --rm=false --pull --network host -f=Dockerfile .
# docker build --build-arg GIT_BRANCH=v0.10.0 -t fgt:v0.10.0 --rm=false --pull --network host -f=Dockerfile .
#
FROM node:16.14.2-alpine

Expand All @@ -23,12 +23,6 @@ WORKDIR /fgt-workspace
RUN git clone -b ${GIT_BRANCH} --single-branch --depth 1 https://github.com/PharmaLedger-IMI/fgt-workspace.git . && \
npm ci && npm cache clean --force

# The environment we're meant to replicate (local/dev/tst)
ARG BUILD_ENV
ENV BUILD_ENV=${BUILD_ENV:-local}

RUN cp ./fgt-bdns/${BUILD_ENV}/apihub.jon ./apihub-root/external-volume/config/apihub.json

RUN npm run install-dsu-explorer

# Remove all Git related files and directories - see https://gist.github.com/facelordgists/80e868ff5e315878ecd6
Expand Down
30 changes: 30 additions & 0 deletions docker/api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ services:
# The config files are handled by distincat startup-script.sh.
#image: joaoluispdm/pharmaledger-imi-fgt:v0.9.6
hostname: fgt-workspace
environment:
ENVIRONMENT: ${ENVIRONMENT:-local}
restart: "unless-stopped"
labels:
- "traefik.enable=true"
Expand Down Expand Up @@ -146,6 +148,8 @@ services:
FGT_API_CREDENTIALS: "{\"name\":{\"secret\":\"Roche AG\",\"public\":true},\"id\":{\"secret\":\"MAH116267986\",\"public\":true},\"email\":{\"secret\":\"[email protected]\",\"public\":true},\"address\":{\"public\":true,\"secret\":\" k Switzerland\"},\"pass\":{\"secret\":\"This1sSuchAS3curePassw0rd\"},\"passrepeat\":{\"secret\":\"This1sSuchAS3curePassw0rd\"}}"
CREDENTIALS_FILE: mah-roche.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-roche${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-roche
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-roche.rule=Host(`mah-roche${DOMAIN}`)"
Expand Down Expand Up @@ -181,6 +185,8 @@ services:
ROLE: mah
CREDENTIALS_FILE: mah-bayer.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-bayer${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-bayer
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-bayer.rule=Host(`mah-bayer${DOMAIN}`)"
Expand Down Expand Up @@ -216,6 +222,8 @@ services:
ROLE: mah
CREDENTIALS_FILE: mah-gsk.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-gsk${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-gsk
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-gsk.rule=Host(`mah-gsk${DOMAIN}`)"
Expand Down Expand Up @@ -253,6 +261,8 @@ services:
# FGT_API_CREDENTIALS: "{\"name\":{\"secret\":\"Merck & Co., Inc.\",\"public\":true},\"id\":{\"secret\":\"MAH0000000\",\"public\":true},\"email\":{\"secret\":\"[email protected]\",\"public\":true},\"address\":{\"public\":true,\"secret\":\"Kenilworth, New Jersey, USA\"},\"pass\":{\"secret\":\"This1sSuchAS3curePassw0rd\"},\"passrepeat\":{\"secret\":\"This1sSuchAS3curePassw0rd\"}}"
CREDENTIALS_FILE: mah-msd.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-msd${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-msd
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-msd.rule=Host(`mah-msd${DOMAIN}`)"
Expand Down Expand Up @@ -288,6 +298,8 @@ services:
ROLE: mah
CREDENTIALS_FILE: mah-novo-nordisk.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-novo-nordisk${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-novo-nordisk
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-novo-nordisk.rule=Host(`mah-novo-nordisk${DOMAIN}`)"
Expand Down Expand Up @@ -323,6 +335,8 @@ services:
ROLE: mah
CREDENTIALS_FILE: mah-pfizer.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-pfizer${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-pfizer
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-pfizer.rule=Host(`mah-pfizer${DOMAIN}`)"
Expand Down Expand Up @@ -358,6 +372,8 @@ services:
ROLE: mah
CREDENTIALS_FILE: mah-takeda.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-takeda${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-takeda
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-takeda.rule=Host(`mah-takeda${DOMAIN}`)"
Expand Down Expand Up @@ -393,6 +409,8 @@ services:
ROLE: mah
CREDENTIALS_FILE: mah-sanofi.json
SWAGGER_SERVER: ${PROTOCOL}://api-mah-sanofi${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.mah-sanofi
labels:
- "traefik.enable=true"
- "traefik.http.routers.mah-sanofi.rule=Host(`mah-sanofi${DOMAIN}`)"
Expand Down Expand Up @@ -429,6 +447,8 @@ services:
ROLE: whs
CREDENTIALS_FILE: whs-1.json
SWAGGER_SERVER: ${PROTOCOL}://api-whs1${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.whs-1
labels:
- "traefik.enable=true"

Expand Down Expand Up @@ -466,6 +486,8 @@ services:
ROLE: whs
CREDENTIALS_FILE: whs-2.json
SWAGGER_SERVER: ${PROTOCOL}://api-whs2${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.whs-2
labels:
- "traefik.enable=true"

Expand Down Expand Up @@ -502,6 +524,8 @@ services:
ROLE: whs
CREDENTIALS_FILE: whs-takeda.json
SWAGGER_SERVER: ${PROTOCOL}://api-whs-takeda${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.whs-takeda
labels:
- "traefik.enable=true"

Expand Down Expand Up @@ -538,6 +562,8 @@ services:
ROLE: whs
CREDENTIALS_FILE: whs-zuellig.json
SWAGGER_SERVER: ${PROTOCOL}://api-whs-zuellig${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.whs-zuellig
labels:
- "traefik.enable=true"

Expand Down Expand Up @@ -575,6 +601,8 @@ services:
ROLE: pha
CREDENTIALS_FILE: pha-1.json
SWAGGER_SERVER: ${PROTOCOL}://api-pha1${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.pha-1
labels:
- "traefik.enable=true"

Expand Down Expand Up @@ -611,6 +639,8 @@ services:
ROLE: pha
CREDENTIALS_FILE: pha-2.json
SWAGGER_SERVER: ${PROTOCOL}://api-pha2${SWAGGER}/traceability
ENVIRONMENT: ${ENVIRONMENT:-local}
BRICKS_DOMAIN: traceability.pha-2
labels:
- "traefik.enable=true"

Expand Down
6 changes: 0 additions & 6 deletions docker/api/traceability/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ WORKDIR /fgt-workspace
RUN git clone -b ${GIT_BRANCH} --single-branch --depth 1 https://github.com/PharmaLedger-IMI/fgt-workspace.git . && \
npm install --unsafe-perm

# The environment we're meant to replicate (local/dev/tst)
ARG BUILD_ENV
ENV BUILD_ENV=${BUILD_ENV:-local}

RUN cp ./fgt-bdns/${BUILD_ENV}/apihub.jon ./apihub-root/external-volume/config/apihub.json

RUN npm run install-dsu-explorer

# Remove all Git related files and directories - see https://gist.github.com/facelordgists/80e868ff5e315878ecd6
Expand Down
29 changes: 22 additions & 7 deletions fgt-api/server-helm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {ROLE, SWAGGER_SERVER} = process.env;
const {ROLE, SWAGGER_SERVER, ENVIRONMENT} = process.env;
const fs = require('fs');
const path = require('path');
const {spawn} = require("child_process");

const currentPath = process.cwd();

Expand Down Expand Up @@ -124,12 +123,28 @@ const setDashboard = async function(){
})
}

const updateConfigsToMatchEnvironment = async function(){
return new Promise((resolve, reject) => {
const environment = ENVIRONMENT || "local";
console.log(`Updating environment configurations for the ${environment} environment`)
try {
fs.copyFileSync(path.join(process.cwd(), `./fgt-bdns/${environment}/apihub.json`),
path.join(process.cwd(), `./apihub-root/external-volume/config/apihub.json`))
} catch (e) {
return reject(e);
}
resolve();
})
}

try {
setDashboard().then(_ => {
Promise.all([bootAPIServer(), bootSwagger()])
.then(_ => console.log(`Completed Boot`))
.catch(e => failServerBoot(e.message));
}).catch(e => failServerBoot(e.message));
updateConfigsToMatchEnvironment().then(_ =>
setDashboard().then(_ => {
Promise.all([bootAPIServer(), bootSwagger()])
.then(_ => console.log(`Completed Boot`))
.catch(e => failServerBoot(e.message));
}).catch(e => failServerBoot(e.message))
).catch(e => failServerBoot(e.message));
} catch (e){
failServerBoot(e.message);
}
Expand Down
27 changes: 21 additions & 6 deletions fgt-api/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let {ROLE, CREDENTIALS_FILE, SWAGGER_SERVER, FGT_API_CREDENTIALS} = process.env;
let {ROLE, CREDENTIALS_FILE, SWAGGER_SERVER, FGT_API_CREDENTIALS, ENVIRONMENT} = process.env;
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -140,15 +140,30 @@ const setDashboard = async function(){
})
}

const updateConfigsToMatchEnvironment = async function(){
return new Promise((resolve, reject) => {
const environment = ENVIRONMENT || "local";
console.log(`Updating environment configurations for the ${environment} environment`)
try {
fs.copyFileSync(path.join(process.cwd(), `./fgt-bdns/${environment}/apihub.json`),
path.join(process.cwd(), `./apihub-root/external-volume/config/apihub.json`))
} catch (e) {
return reject(e);
}
resolve();
})
}


try {
overWriteCredentialsByRole();
setDashboard().then(_ => {
Promise.all([bootAPIServer(), bootSwagger()])
.then(_ => console.log(`Completed Boot`))
.catch(e => failServerBoot(e.message));
}).catch(e => failServerBoot(e.message));
updateConfigsToMatchEnvironment().then(_ =>
setDashboard().then(_ => {
Promise.all([bootAPIServer(), bootSwagger()])
.then(_ => console.log(`Completed Boot`))
.catch(e => failServerBoot(e.message));
}).catch(e => failServerBoot(e.message))
).catch(e => failServerBoot(e.message));
} catch (e){
failServerBoot(e.message);
}
Expand Down

0 comments on commit 32e3bf7

Please sign in to comment.