Fix backend dockerfile
Opened this issue · 0 comments
zetos commented
The build script is no longer working.
Some needed changes:
- Update node version on the Dockerfile.
- The command
RUN npm install puppeteer
will install the puppeteer 3.x.x with can have breaking changes.
This is a suggestion for a Dockerfile that worked for me. I changes the node image to use Alpine, and added the "puppeteer": "^2.0.0"
dependency on the package.json
.
I also changed the following lines on the server.js
from:
code = code.replace(/\.launch\([\w\W]*?\)/g,
".launch({args: ['--no-sandbox', '--disable-dev-shm-usage']})");
to:
code = code.replace(/\.launch\([\w\W]*?\)/g,
".launch({executablePath: '/usr/bin/chromium-browser', args: ['--disable-dev-shm-usage']})");
Dockerfile:
FROM node:alpine
# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
# Installs latest Chromium (79) package.
RUN apk add --no-cache \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
WORKDIR /usr/src/app
COPY . .
COPY package*.json ./
# Install deps for server.
RUN npm install --only=production
# building the image.
ARG CACHEBUST=1
# Add pptr user.
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 user as non privileged.
USER pptruser
EXPOSE 8080
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "server.js"]