From d34c50c8f16bce05c6b3ff084b156a705a9ce992 Mon Sep 17 00:00:00 2001 From: Wolvan Date: Thu, 3 Feb 2022 21:12:07 +0100 Subject: [PATCH] Dockerize Application Now poll.horse is available as a docker image! To persist data, mount `/data` to a host directory. A config file can be specified via binding `/usr/src/app/config.json` to a config file on the host. --- .dockerignore | 33 +++++++++++++++++++++++++++++++++ .vscode/launch.json | 7 +++++++ .vscode/tasks.json | 39 +++++++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 .dockerignore create mode 100644 .vscode/tasks.json create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fcbedbd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,33 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +README.md +CHANGELOG.md +API.md +LICENSE + +data/ +dist/ +node_modules/ +.editorconfig +config*.js* +Procfile \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 6597265..1d1d393 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,6 +13,13 @@ ], "restart": true, "type": "pwa-node" + }, + { + "name": "Docker Node.js Launch", + "type": "docker", + "request": "launch", + "preLaunchTask": "docker-run: debug", + "platform": "node" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d416da5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,39 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "docker-build", + "label": "docker-build", + "platform": "node", + "dockerBuild": { + "dockerfile": "${workspaceFolder}/Dockerfile", + "context": "${workspaceFolder}", + "pull": true + } + }, + { + "type": "docker-run", + "label": "docker-run: release", + "dependsOn": [ + "docker-build" + ], + "platform": "node" + }, + { + "type": "docker-run", + "label": "docker-run: debug", + "dependsOn": [ + "docker-build" + ], + "dockerRun": { + "env": { + "DEBUG": "*", + "NODE_ENV": "development" + } + }, + "node": { + "enableDebugging": true + } + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8e06a87 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:lts-alpine +WORKDIR /usr/src/app + +# Add Tini +RUN apk add --update tini + +# Install and build application +COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"] +RUN npm set-script prepublish "" +RUN npm install --silent && npm cache clean --silent --force +COPY . . +RUN npm test +RUN npm run build +RUN rm -rf src utils .eslintignore .eslintrc.json .mocharc.json test tsconfig.json +RUN npm prune --production --silent +RUN chown -R node /usr/src/app +RUN mv node_modules ../ +ENV PORT=6969 +RUN mkdir -p /data && chown -R node /data +USER node +ENTRYPOINT ["/sbin/tini", "--", "node", "dist/main", "--port", "env:PORT", "--data-directory", "/data"]