From 4e142c8e5ebb141922c84f89d24425ffd35d3c83 Mon Sep 17 00:00:00 2001 From: briandennis Date: Mon, 12 Mar 2018 23:06:12 -0700 Subject: [PATCH] add back Dockerfile --- Dockerfile | 33 +++++++++++++++++++++++++++++++++ server.js | 8 ++++---- 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8b9392a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:9-alpine + +# Installs latest Chromium (63) package. +RUN apk update && apk upgrade && \ + echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \ + echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \ + apk add --no-cache \ + chromium@edge \ + nss@edge + +WORKDIR /app + +COPY package.json ./ +COPY yarn.lock ./ + +RUN yarn + +COPY . . + +RUN yarn build + +# Add user so we don't need --no-sandbox. +RUN addgroup -S pptruser && adduser -S -g pptruser pptruser \ + && mkdir -p /home/pptruser/Downloads \ + && chown -R pptruser:pptruser /home/pptruser \ + && chown -R pptruser:pptruser /app + +# Run everything after as non-privileged user. +USER pptruser + +ENV NODE_ENV production +EXPOSE 3000 +CMD [ "yarn", "start" ] \ No newline at end of file diff --git a/server.js b/server.js index 28cc343..2e4bfd8 100644 --- a/server.js +++ b/server.js @@ -5,7 +5,7 @@ const next = require('next') const puppeteer = require('puppeteer') const port = parseInt(process.env.PORT, 10) || 3000 -const dev = process.env.NODE_ENV !== 'production' && !process.env.NOW +const dev = process.env.NODE_ENV !== 'production' const app = next({ dev }) const handle = app.getRequestHandler() @@ -21,12 +21,12 @@ function wrap(handler) { }) } -const puppeteerParams = process.env.DOCKER - ? { +const puppeteerParams = dev + ? {} + : { executablePath: '/usr/bin/chromium-browser', args: ['--no-sandbox', '--disable-setuid-sandbox'] } - : {} app .prepare()