Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ backend/dist
.env.development.local
.env.test.local
.env.production.local
.env
env.json

dist
npm-debug.log*
Expand All @@ -30,4 +32,6 @@ frontend/server.key
frontend/server.cert

backend/server.key
backend/server.cert
backend/server.cert

logs
46 changes: 7 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,17 @@
# OVERVIEW: This is the Dockerfile for a multi-stage build of the CDS Authoring
# Tool. A multi-stage approach was used to keep the overall image size low by
# including only the layers needed at runtime in the final image. For more
# info see: https://docs.docker.com/develop/develop-images/multistage-build/

###############################################################################
# STAGE 0: base
# - Setup base image from which most others derive. This allows for a single
# place to declare the versioned node image we use and any other commands
# common to all (or most?) environments.
###############################################################################

FROM node:18-alpine as base
FROM node:14-alpine
ENV NODE_ENV production
# ADD https://gitlab.mitre.org/mitre-scripts/mitre-pki/raw/master/os_scripts/install_certs.sh /tmp/install_certs.sh
# RUN chmod a+x /tmp/install_certs.sh && /tmp/install_certs.sh && rm /tmp/install_certs.sh

# RUN apk update
# RUN apk upgrade openssl
# First copy just the package.json, package-lock.json, and local dependencies so that
# if they have not changed, we can use cached node_modules instead of
# redownloading them all.
COPY ./ /usr/src/app/
WORKDIR /usr/src/app/backend



WORKDIR /home/node/app
COPY --chown=node:node . .
WORKDIR /home/node/app/backend
RUN npm install

RUN ls -la



WORKDIR /usr/src/app/frontend
WORKDIR /home/node/app/frontend
RUN npm install
WORKDIR /home/node/app


RUN npm install -g pm2@4.4.1
WORKDIR /usr/src/app
RUN chown -R node:node .
ENV PORT 5050
RUN npm install pm2 -g

EXPOSE 5050
EXPOSE 5051

USER node


CMD [ "pm2-docker", "pm2.config.js" ]
39 changes: 7 additions & 32 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
# OVERVIEW: This is the Dockerfile for a multi-stage build of the CDS Authoring
# Tool. A multi-stage approach was used to keep the overall image size low by
# including only the layers needed at runtime in the final image. For more
# info see: https://docs.docker.com/develop/develop-images/multistage-build/

###############################################################################
# STAGE 0: base
# - Setup base image from which most others derive. This allows for a single
# place to declare the versioned node image we use and any other commands
# common to all (or most?) environments.
###############################################################################

FROM node:14-alpine as base


# First copy just the package.json, package-lock.json, and local dependencies so that
# if they have not changed, we can use cached node_modules instead of
# redownloading them all.
COPY ./ /usr/src/app/
WORKDIR /usr/src/app/backend

FROM node:14-alpine

WORKDIR /home/node/app
COPY --chown=node:node . .
WORKDIR /home/node/app/backend
RUN npm install
RUN npm run build

WORKDIR /usr/src/app/frontend
WORKDIR /home/node/app/frontend
RUN npm install
WORKDIR /home/node/app



RUN npm install -g pm2@4.4.1
WORKDIR /usr/src/app
RUN chown -R node:node .
ENV PORT 5050
RUN npm install pm2 -g

EXPOSE 5050
EXPOSE 5051

USER node

CMD ./dockerRunnerDev.sh
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"typescript": "^4.9.3"
},
"scripts": {
"start": "tsc && nodemon ./dist/server.js",
"start": "ts-node-dev src/server.ts",
"test": "mocha",
"build": "tsc",
"lint": "tsc && eslint \"**/*.{js,ts}\"",
Expand Down
38 changes: 23 additions & 15 deletions dockerRunnerDev.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#!/bin/sh

# Handle closing application on signal interrupt (ctrl + c)
trap 'kill $CONTINUOUS_INSTALL_PID $SERVER_PID; gradle --stop; exit' INT
trap 'kill $CONTINUOUS_INSTALL_PID $SERVER_PID $BACKEND_SERVER_PID; exit' INT

mkdir logs

# Reset log file content for new application boot
echo "*** Logs for continuous installer ***" > ./frontend/logs/installer.log
echo "*** Logs for 'npm run start' ***" > ./frontent/logs/runner.log
echo "*** Logs for continuous frontend installer ***" > ./logs/frontend_installer.log
echo "*** Logs for frontend 'npm run start' ***" > ./logs/frontend_runner.log

echo "*** Logs for continuous installer ***" > ./backend/logs/installer.log
echo "*** Logs for 'npm run start' ***" > ./backend/logs/runner.log
echo "*** Logs for continuous backend installer ***" > ./logs/backend_installer.log
echo "*** Logs for backend 'npm run start' ***" > ./logs/backend_runner.log

# Print that the application is starting in watch mode
echo "starting application in watch mode..."

# Start the continious build listener process
echo "starting continuous installer..."
echo "starting continuous installers..."

cd frontend
npm install | tee ./logs/installer.log
npm install | tee ./logs/frontend_installer.log
cd ../backend
npm install | tee ./logs/installer.log
npm install | tee ./logs/backend_installer.log
cd ..

( package_modify_time=$(stat -c %Y frontend/package.json)
Expand All @@ -36,13 +37,16 @@ do

if [[ "$package_modify_time" != "$new_package_modify_time" ]] || [[ "$package_lock_modify_time" != "$new_package_lock_modify_time" ]] || [[ "$backend_lock_modify_time" != "$new_backend_lock_modify_time" ]]|| [[ "$backend_modify_time" != "$new_backend_modify_time" ]]
then
echo "running npm install..."
echo "running frontent npm install..."
cd frontend
npm install | tee ./logs/installer.log
cd ../backend
npm install | tee ./logs/installer.log
npm install | tee ./logs/frontend_installer.log
cd ..
elif [[ "$backend_lock_modify_time" != "$new_backend_lock_modify_time" ]]|| [[ "$backend_modify_time" != "$new_backend_modify_time" ]]
then
echo "running backend npm install..."
cd backend
npm install | tee ./logs/backend_installer.log
cd ..
pm2-docker pm2.config.dev.js
fi

package_modify_time=$new_package_modify_time
Expand All @@ -53,10 +57,14 @@ do
done ) & CONTINUOUS_INSTALL_PID=$!

# Start server process once initial build finishes
( pm2-docker pm2.config.js ) & SERVER_PID=$!
cd frontend
( npm run start | tee ./logs/frontend_runner.log ) & SERVER_PID=$!

cd ../backend
( npm run start | tee ./logs/backend_runner.log ) & BACKEND_SERVER_PID=$!

# Handle application background process exiting
wait $CONTINUOUS_INSTALL_PID $SERVER_PID
wait $CONTINUOUS_INSTALL_PID $SERVER_PID $BACKEND_SERVER_PID
EXIT_CODE=$?
echo "application exited with exit code $EXIT_CODE..."

2 changes: 2 additions & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=5050
REACT_APP_PIMS_BACKEND_PORT=5051
51 changes: 0 additions & 51 deletions frontend/env.json

This file was deleted.