From a10aa9c52f54fd22556fe1647293f6f79e226d4f Mon Sep 17 00:00:00 2001 From: Jeremy Chabernaud Date: Wed, 15 Nov 2023 21:33:05 +0100 Subject: [PATCH] feat: add docker (#6) * misc: improve match version of types/node * feat: improve stop with sigint signal * feat: add docker * feat: add docker in readme --- .dockerignore | 6 ++++++ Dockerfile | 29 +++++++++++++++++++++++++++++ README.md | 23 +++++++++++++++++++++-- package-lock.json | 2 +- package.json | 2 +- src/main.ts | 9 +++++++-- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..37a40c7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +README.md +LICENSE.txt +Dockerfile +.vscode +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0989b56 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +############################ +# Docker build environment # +############################ + +FROM node:18.16.1-bookworm AS build + +WORKDIR /build + +COPY . . + +RUN npm i +RUN npm run build + +############################ +# Docker final environment # +############################ + +FROM node:18.16.1-bookworm + +EXPOSE 3333 +EXPOSE 3334 +EXPOSE 8332 + +WORKDIR /public-pool + +COPY --from=build /build . +COPY .env.example .env + +CMD ["/usr/local/bin/node", "dist/main"] diff --git a/README.md b/README.md index 1479dc1..73c15c9 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,6 @@ $ npm run start:dev $ npm run build ``` - - ## Test ```bash @@ -36,12 +34,33 @@ $ npm run test:cov ``` ## Web interface + See [public-pool-ui](https://github.com/benjamin-wilson/public-pool-ui) ## Deployment + Install pm2 (https://pm2.keymetrics.io/) ```bash $ pm2 start dist/main.js ``` +## Docker + +Build container: + +```bash +$ docker build -t public-pool . +``` + +Run container (with default configuration): + +```bash +$ docker container run --name public-pool --rm -p 3333:3333 -p 3334:3334 -p 8332:8332 public-pool +``` + +Run container (with custom configuration): + +```bash +$ docker container run --name public-pool --rm -p 3333:3333 -p 3334:3334 -p 8332:8332 -v .env:.env public-pool +``` diff --git a/package-lock.json b/package-lock.json index 663e762..d048806 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,7 @@ "@types/cron": "^2.0.1", "@types/express": "^4.17.13", "@types/jest": "29.5.1", - "@types/node": "18.16.12", + "@types/node": "^18.16.12", "@types/node-telegram-bot-api": "^0.61.6", "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.0.0", diff --git a/package.json b/package.json index 61adb2b..0c528c7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@types/cron": "^2.0.1", "@types/express": "^4.17.13", "@types/jest": "29.5.1", - "@types/node": "18.16.12", + "@types/node": "^18.16.12", "@types/node-telegram-bot-api": "^0.61.6", "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.0.0", diff --git a/src/main.ts b/src/main.ts index 2540678..f785ac5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,7 +25,6 @@ async function bootstrap() { cert: readFileSync(`${currentDirectory}/secrets/cert.pem`), } }; - } const app = await NestFactory.create(AppModule, new FastifyAdapter(options)); @@ -38,10 +37,15 @@ async function bootstrap() { forbidUnknownValues: true }), ); + + process.on('SIGINT', () => { + console.log(`Stopping services`); + process.exit(0); + }); + app.enableCors(); useContainer(app.select(AppModule), { fallbackOnErrors: true }); - //Taproot bitcoinjs.initEccLib(ecc); @@ -50,4 +54,5 @@ async function bootstrap() { }); } + bootstrap();