From d79de35603f396ce5ec7988649e970ca5492b49c Mon Sep 17 00:00:00 2001 From: Koyu Berteon Date: Fri, 25 May 2018 04:59:48 +0200 Subject: [PATCH] Added Dockerfile (#313) * Added Dockerfile * Better comments in Dockerfile * Added SIGINT handler * Keeping code-check happy * Keeping code-check happy v2 * Keeping code-check happy v2 --- Dockerfile | 23 +++++++++++++++++++++++ README.md | 7 +++++++ server.js | 5 +++++ 3 files changed, 35 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8e8868f7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Using Alpine to keep the images smaller +FROM alpine:latest + +# Pushing all files into image +WORKDIR /app +ADD . /app + +# Install updates and NodeJS+Dependencies +RUN apk update && apk upgrade +RUN apk add nodejs git python build-base clang + +# Upgrading NPM +RUN npm i npm@latest -g + +# Install Pinafore +RUN npm install +RUN npm run build + +# Expose port 4002 +EXPOSE 4002 + +# Setting run-command +CMD PORT=4002 npm start \ No newline at end of file diff --git a/README.md b/README.md index f1cdc42c..2f9a9234 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,13 @@ To build Pinafore for production: npm run build PORT=4002 npm start +### Docker + +To build a docker image for production: + + docker build . + docker run -d -p 4002:4002 [your-image] + Now Pinafore is running at `localhost:4002`. Pinafore requires [Node.js](https://nodejs.org/en/) v8+. diff --git a/server.js b/server.js index e69e6fff..e072ce1b 100644 --- a/server.js +++ b/server.js @@ -63,3 +63,8 @@ app.use(sapper()) app.listen(PORT, () => { console.log(`listening on port ${PORT}`) }) + +// Handle SIGINT (source: https://git.io/vhJgF) +process.on('SIGINT', function () { + process.exit(0) +})