diff --git a/.gitignore b/.gitignore index 91b4877..ffa6af6 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ backend/dist .env.development.local .env.test.local .env.production.local +.env +env.json dist npm-debug.log* @@ -30,4 +32,6 @@ frontend/server.key frontend/server.cert backend/server.key -backend/server.cert \ No newline at end of file +backend/server.cert + +logs diff --git a/Dockerfile b/Dockerfile index 6378271..67c0f04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev index 93659e8..436f2df 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -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 \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index 9ae70f5..fe8e3ab 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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}\"", diff --git a/dockerRunnerDev.sh b/dockerRunnerDev.sh index 59cd204..02a0cfd 100755 --- a/dockerRunnerDev.sh +++ b/dockerRunnerDev.sh @@ -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) @@ -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 @@ -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..." diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 0000000..7e845eb --- /dev/null +++ b/frontend/.env @@ -0,0 +1,2 @@ +PORT=5050 +REACT_APP_PIMS_BACKEND_PORT=5051 \ No newline at end of file diff --git a/frontend/env.json b/frontend/env.json deleted file mode 100644 index 172333d..0000000 --- a/frontend/env.json +++ /dev/null @@ -1,51 +0,0 @@ -{ -"BACKEND_PORT" : { - "type" :"number", - "default" : 5051 -}, -"ALLOWED_ORIGIN" : { - "type" : "object", - "default" : ["http://localhost:3000", "https://localhost:3000/", "http://localhost:3005", "https://localhost:3005/", "http://localhost:5050", "https://localhost:5050/", "http://localhost:4040", "https://localhost:4040/"] -}, -"MONGO_USERNAME": { - "type" : "string", - "default" : "rems-admin-pims-root" -}, - -"MONGO_PASSWORD" :{ - "type" : "string", - "default" : "rems-admin-pims-password" -}, - -"MONGO_URL" : { - "type" : "string", - "default" : "mongodb://localhost:27017/pims" -}, - -"AUTH_SOURCE" :{ - "type" : "string", - "default" : "admin" -}, - -"REMS_ADMIN_BASE" : { - "type" : "string", - "default" : "http://localhost:8090" -}, - -"PORT" : { - "type" :"number", - "default" : 5050 -}, -"SSL_KEY_FILE": { - "type": "string", - "default": "server.key" -}, -"SSL_CRT_FILE": { - "type": "string", - "default": "server.cert" -}, -"USE_HTTPS": { - "type": "boolean", - "default": false -} -}