From 39a2420edbe6df711ebf3f085283c918344c7a65 Mon Sep 17 00:00:00 2001 From: Jacob Burrell Date: Mon, 5 Jul 2021 12:36:32 +0100 Subject: [PATCH 1/2] Simplify with PM2.json file and add README This adds a basic README and simplifies two commands in package.json by using a pm2.json file for the price-script and server scripts. --- README.md | 25 +++++++++++++++++++- package.json | 64 ++++++++++++++++++++++++++-------------------------- pm2.json | 15 ++++++++++++ 3 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 pm2.json diff --git a/README.md b/README.md index 162e128..d634997 100644 --- a/README.md +++ b/README.md @@ -1 +1,24 @@ -edge-notifications +# Edge Notifications Server + +## Usage + +### Install + +``` +yarn +``` + +### Configuration + +Configure `serverConfig.json.sample` and rename to `serverConfig.json` + +#### Running for Development + +``` +yarn start +``` + +#### Running Build for Production +``` +pm2 start pm2.json +``` \ No newline at end of file diff --git a/package.json b/package.json index 6efcfb5..537b8cb 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,33 @@ { - "name": "edge-push-notifications", - "version": "1.0.0", - "description": "", - "main": "build/index.js", - "scripts": { - "price:script": "node build/index.js", - "server": "node build/server.js", - "price:script:pm2": "pm2 start build/price-script/index.js --name price-script --log logs/price-script.log --time", - "server:pm2": "pm2 start build/server/index.js --name server --log logs/server.log --time", - "compile": "tsc" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@pm2/io": "^4.3.5", - "axios": "^0.19.2", - "body-parser": "^1.19.0", - "cleaners": "^0.2.0", - "cors": "^2.8.5", - "express": "^4.17.1", - "firebase-admin": "^8.12.1", - "nano": "^8.2.2", - "node-schedule": "^1.3.2" - }, - "devDependencies": { - "@types/express": "^4.17.6", - "@types/node": "^14.0.5", - "ts-node": "^8.10.2", - "typescript": "^3.9.3" - } -} + "name": "edge-push-notifications", + "version": "1.0.0", + "description": "", + "main": "build/index.js", + "scripts": { + "price:script": "node build/index.js", + "server": "node build/server/index.js", + "compile": "tsc", + "pm2": "yarn compile && pm2 start pm2.json && pm2 save", + "start": "yarn compile && yarn server" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@pm2/io": "^4.3.5", + "axios": "^0.19.2", + "body-parser": "^1.19.0", + "cleaners": "^0.2.0", + "cors": "^2.8.5", + "express": "^4.17.1", + "firebase-admin": "^8.12.1", + "nano": "^8.2.2", + "node-schedule": "^1.3.2" + }, + "devDependencies": { + "@types/express": "^4.17.6", + "@types/node": "^14.0.5", + "ts-node": "^8.10.2", + "typescript": "^3.9.3" + } +} \ No newline at end of file diff --git a/pm2.json b/pm2.json new file mode 100644 index 0000000..c546d17 --- /dev/null +++ b/pm2.json @@ -0,0 +1,15 @@ +{ + "apps": [{ + "name": "price-script", + "script": "build/price-script/index.js", + "error_file": "logs/price-script/error.log", + "out_file": "logs/price-script/price-script.log" + }, + { + "name": "server", + "script": "build/server/index.js", + "error_file": "logs/server/error.log", + "out_file": "logs/server/out.log" + } + ] +} \ No newline at end of file From 2b8de1085c53ed473621a4dd79e4af6dc3fc1523 Mon Sep 17 00:00:00 2001 From: Jacob Burrell Date: Mon, 5 Jul 2021 12:51:14 +0100 Subject: [PATCH 2/2] Dockerize --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 7 +++++++ 2 files changed, 41 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d13ac5e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM node:14.16.0-alpine3.13 + +EXPOSE 8008 + +# Install PM2 +RUN npm install -g pm2 + +# PM2 log rotation +RUN pm2 install pm2-logrotate + +# Set working directory to /usr/app +WORKDIR /usr/app + +# Set logs directory +VOLUME [ "./logs" ] + +# Copy dependency files +COPY package.json . +COPY yarn.lock . + +# Install deps +RUN yarn install --ignore-scripts + +# Copy project files +COPY pm2.json . +COPY src src/ +COPY tsconfig.json . +COPY serverConfig.json . + +# Compile +RUN yarn compile + +# Run app +CMD [ "pm2-runtime", "pm2.json" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..789ffd2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + infoserver: + image: edge-notifications:latest + network_mode: "host" + volumes: + - ./logs:/usr/server/logs + container_name: edge-notifications \ No newline at end of file