diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-14 19:38:26 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-14 19:38:26 +0300 |
commit | 33e640f1e8654fcfc8102b43449c79bcb4d5ddff (patch) | |
tree | 3936700d729067c998569adcb566ef5b47a1dffc | |
parent | fb8cdd4bce1c549135b435473b5ca30e77efa969 (diff) | |
download | bsu-fantom-33e640f1e8654fcfc8102b43449c79bcb4d5ddff.tar.gz |
build: setup docker correctly
-rw-r--r-- | Dockerfile | 25 | ||||
-rw-r--r-- | docker-compose.yml | 7 | ||||
-rw-r--r-- | src/handlers/index.js | 2 | ||||
-rw-r--r-- | src/handlers/launchUserSession.js | 6 |
4 files changed, 33 insertions, 7 deletions
@@ -1,12 +1,33 @@ # Dockerfile to build bsu-fantom image -FROM node:12 +FROM node:12-slim + +# Install latest chrome dev package +# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer +# installs, work. +RUN apt-get update \ + && apt-get install -y wget gnupg \ + && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ + && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ + && apt-get update \ + && apt-get install -y google-chrome-stable fonts-freefont-ttf libxss1 \ + --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY package*.json ./ -RUN npm install +RUN npm install \ + # Add user so we don't need --no-sandbox. + # same layer as npm install to keep re-chowned files from using up several hundred MBs more space + && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \ + && mkdir -p /home/pptruser/Downloads \ + && chown -R pptruser:pptruser /home/pptruser \ + && chown -R pptruser:pptruser /app/node_modules + +# Run everything after as non-privileged user. +USER pptruser COPY . . diff --git a/docker-compose.yml b/docker-compose.yml index 0986cac..bb59b43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,16 +8,19 @@ services: app: container_name: bsu-fantom restart: always + init: true build: . environment: - MONGODB_URI=mongodb://db:27017/bsu-fantom + env_file: + - .env ports: - '3030:3030' links: - db db: - container_name: mongo + container_name: bsu-fantom-db image: mongo ports: - - '27017:27017' + - '27018:27017' diff --git a/src/handlers/index.js b/src/handlers/index.js index e6f84df..18946fc 100644 --- a/src/handlers/index.js +++ b/src/handlers/index.js @@ -8,7 +8,7 @@ const { clickElementBySelector } = require('./utils.js'); const { EDUFPMI_URL, NODE_ENV, HEADLESS } = process.env; // Always run headless in production, but allow configuring for development -const headless = NODE_ENV === 'production' || HEADLESS || false; +const headless = NODE_ENV === 'production' || HEADLESS; const handleJobAsUser = async (job, user) => { diff --git a/src/handlers/launchUserSession.js b/src/handlers/launchUserSession.js index 58dde62..44f2193 100644 --- a/src/handlers/launchUserSession.js +++ b/src/handlers/launchUserSession.js @@ -3,8 +3,10 @@ const { clickElementBySelector } = require('./utils.js'); const { EDUFPMI_URL } = process.env; -const launchUserSession = (user, headless = true) => puppeteer.launch({ headless }) - .then(async browser => { +const launchUserSession = (user, headless = true) => puppeteer.launch({ + headless, + args: ['--no-sandbox'] +}).then(async browser => { const { username, password } = user; const page = await browser.newPage(); |