Skip to content

Commit

Permalink
#74 - docker/api/ Dockerfile revision
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoluis-pdm committed Jun 1, 2022
1 parent 214423f commit 0dfeeed
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 31 deletions.
53 changes: 40 additions & 13 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
FROM node:14.16-buster
# Docker image build for Finished Goods Traceability (FGT)
#
FROM node:14.17.4-alpine

RUN npm install -g node-gyp
# The tag, branch or commit hash to clone.
ARG GIT_BRANCH
ENV GIT_BRANCH=${GIT_BRANCH:-master}

ENV TARGET_FOLDER_NAME="fgt-workspace"
RUN git clone https://github.com/PharmaLedger-IMI/fgt-workspace.git $TARGET_FOLDER_NAME
RUN apk --no-cache add git curl && apk add --no-cache --upgrade bash

RUN cd $TARGET_FOLDER_NAME && \
RUN npm install -g node-gyp

# create folder fgt-workspace and change its owner to pre-existing user 'node'
RUN mkdir -p /fgt-workspace

#checkov:skip=CKV_DOCKER_3: "Ensure that a user for the container has been created"
WORKDIR /fgt-workspace

# Build the software - Note: Clone by specific tag or branch
RUN git clone -b ${GIT_BRANCH} --single-branch --depth 1 https://github.com/PharmaLedger-IMI/fgt-workspace.git . && \
npm install --unsafe-perm

# Copy the API HUB Configs (BDNS, domains, etc)
COPY config/ $TARGET_FOLDER_NAME/apihub-root/external-volume/config/
# copy bdns+domain configuration files from local context
COPY config/ apihub-root/external-volume/config/

# Remove all Git related files and directories - see https://gist.github.com/facelordgists/80e868ff5e315878ecd6
RUN find . \( -name ".git" -o -name ".gitignore" -o -name ".gitmodules" -o -name ".gitattributes" \) -exec rm -rf -- {} +

# Save some space by removing directories not needed in production
RUN rm -rf docs workdocs

# git no longer needed for runtime
RUN apk del git

RUN chown -R node /fgt-workspace

USER node

# Start the server, run build-all, run the ROLE specific API and run the swagger instance<
RUN cd $TARGET_FOLDER_NAME && \
echo 'npm run server & \n sleep 5s \n npm run build-all \n cd fgt-api && npm run boot-api & \n tail -f /dev/null' >> startup-script.sh
RUN cd $TARGET_FOLDER_NAME && cat startup-script.sh
CMD ["npm", "run", "server"]
# The command above starts the apihub server, and never returns.
# tracebility must additionally execute "npm run build-all".
# participants must additionally execute "npm run build-all ; cd fgt-api && npm run boot-api " (or npm run boot-api-helm).
# That needs to be perfomed by external tool.

# APIHub & Dashboard - traceability only has apihub.
EXPOSE 8080/tcp
# FGT API - different for Wholesaler & Pharmacy
EXPOSE 8081/tcp
# Swagger
EXPOSE 3009/tcp

CMD cd $TARGET_FOLDER_NAME && \
bash startup-script.sh
2 changes: 1 addition & 1 deletion docker/api/docker-compose-eth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
ipv4_address: 172.16.63.51
qbn-net:
ipv4_address: 172.16.16.51
command: ["/bin/bash", "-c", "cd /fgt-workspace && bash startup-eth-script.sh"]
command: ["/bin/bash", "-c", "cd /fgt-workspace ; npm run switch-to-test-chain ; npm run server & ( sleep 5s ; npm run build-all ; tail -f /dev/null )"]

networks:
qbn-net:
Expand Down
4 changes: 3 additions & 1 deletion docker/api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ x-participant-def:
timeout: 3s
retries: 100
start_period: 40s
command: ["/bin/bash", "-c", "cd /fgt-workspace ; npm run server & ( sleep 5s ; npm run build-all ; cd fgt-api ; npm run boot-api )"]
# the command above is not for the tracebility apihub, so it must be overridden on fgt-workspace.
x-mah-def:
&mah-def
<< : *participant-def
Expand Down Expand Up @@ -121,7 +123,7 @@ services:
timeout: 3s
retries: 100
start_period: 20s
command: ["/bin/bash", "-c", "cd /fgt-workspace && bash startup-noeth-script.sh"]
command: ["/bin/bash", "-c", "cd /fgt-workspace ; npm run switch-to-simul-chain ; npm run server & ( sleep 5s ; npm run build-all ; tail -f /dev/null )"]

mah-roche:
<< : *mah-def
Expand Down
56 changes: 40 additions & 16 deletions docker/api/traceability/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,52 @@
FROM node:14.16-buster
# Docker image build for Finished Goods Traceability (FGT)
#
FROM node:14.17.4-alpine

# The tag, branch or commit hash to clone.
ARG GIT_BRANCH
ENV GIT_BRANCH=${GIT_BRANCH:-master}

RUN apk --no-cache add git curl && apk add --no-cache --upgrade bash

RUN npm install -g node-gyp

ENV TARGET_FOLDER_NAME="fgt-workspace"
RUN git clone https://github.com/PharmaLedger-IMI/fgt-workspace.git $TARGET_FOLDER_NAME
# create folder fgt-workspace and change its owner to pre-existing user 'node'
RUN mkdir -p /fgt-workspace

#checkov:skip=CKV_DOCKER_3: "Ensure that a user for the container has been created"
WORKDIR /fgt-workspace

RUN cd $TARGET_FOLDER_NAME && \
# Build the software - Note: Clone by specific tag or branch
RUN git clone -b ${GIT_BRANCH} --single-branch --depth 1 https://github.com/PharmaLedger-IMI/fgt-workspace.git . && \
npm install --unsafe-perm

COPY config/ $TARGET_FOLDER_NAME/apihub-root/external-volume/config/
# copy bdns+domain configuration files from local context
COPY config/ apihub-root/external-volume/config/

# Remove all Git related files and directories - see https://gist.github.com/facelordgists/80e868ff5e315878ecd6
RUN find . \( -name ".git" -o -name ".gitignore" -o -name ".gitmodules" -o -name ".gitattributes" \) -exec rm -rf -- {} +

# Save some space by removing directories not needed in production
RUN rm -rf docs workdocs

# git no longer needed for runtime
RUN apk del git

RUN cd $TARGET_FOLDER_NAME && \
echo 'npm run server & \n sleep 5s \n npm run build-all \n tail -f /dev/null' >> startup-script.sh
RUN cd $TARGET_FOLDER_NAME && cat startup-script.sh
# this is very slow, specially on the node_modules folder
RUN chown -R node /fgt-workspace

# #30 alternative startup script with ethAdapter
RUN cd $TARGET_FOLDER_NAME && \
echo 'npm run switch-to-test-chain ; source startup-script.sh' >> startup-eth-script.sh
USER node

# #30 alternative startup script without ethAdapter
RUN cd $TARGET_FOLDER_NAME && \
echo 'npm run switch-to-simul-chain ; source startup-script.sh' >> startup-noeth-script.sh
CMD ["npm", "run", "server"]
# The command above starts the apihub server, and never returns.
# tracebility must additionally execute "npm run build-all".
# participants must additionally execute "npm run build-all ; cd fgt-api && npm run boot-api " (or npm run boot-api-helm).
# That needs to be perfomed by external tool.

# APIHub & Dashboard - traceability only has apihub.
EXPOSE 8080/tcp
# FGT API - different for Wholesaler & Pharmacy
# EXPOSE 8081/tcp
# Swagger
# EXPOSE 3009/tcp

CMD cd $TARGET_FOLDER_NAME && \
bash startup-script.sh

0 comments on commit 0dfeeed

Please sign in to comment.