Add Dockerfile for cloud run

This commit is contained in:
Hongbo Wu
2022-10-04 09:51:42 +08:00
parent 726df26c15
commit 78bce2d1e7
6 changed files with 152 additions and 19 deletions

View File

@ -0,0 +1,28 @@
FROM node:14.18-alpine
# Run everything after as non-privileged user.
WORKDIR /app
COPY package.json .
COPY yarn.lock .
COPY tsconfig.json .
COPY .prettierrc .
COPY .eslintrc .
COPY /packages/content-handler/package.json ./packages/content-handler/package.json
RUN yarn install --pure-lockfile
ADD /packages/inbound-email-handler ./packages/inbound-email-handler
ADD /packages/content-handler ./packages/content-handler
RUN yarn workspace @omnivore/content-handler build
# After building, fetch the production dependencies
RUN rm -rf /app/packages/inbound-email-handler/node_modules
RUN rm -rf /app/node_modules
RUN yarn install --pure-lockfile --production
EXPOSE 8080
CMD ["yarn", "workspace", "@omnivore/inbound-email-handler", "start"]

View File

@ -29,7 +29,7 @@
"dependencies": {
"@google-cloud/functions-framework": "3.1.2",
"@google-cloud/pubsub": "^2.18.4",
"@omnivore/content-handler": "file:./content-handler",
"@omnivore/content-handler": "file:./../content-handler",
"@sendgrid/client": "^7.6.0",
"@sentry/serverless": "^6.16.1",
"addressparser": "^1.0.1",

View File

@ -92,13 +92,20 @@ COPY tsconfig.json .
COPY .prettierrc .
COPY .eslintrc .
COPY /packages/puppeteer-parse/package.json ./packages/puppeteer-parse/package.json
COPY /packages/content-handler/package.json ./packages/content-handler/package.json
RUN yarn install --pure-lockfile
ADD /packages/puppeteer-parse ./packages/puppeteer-parse
ADD /packages/content-handler ./packages/content-handler
RUN yarn workspace @omnivore/content-handler build
EXPOSE 8080
# After building, fetch the production dependencies
RUN rm -rf /app/packages/puppeteer-parse/node_modules
RUN rm -rf /app/node_modules
RUN yarn install --pure-lockfile --production
EXPOSE 9090
# USER pptruser
ENTRYPOINT ["yarn", "workspace", "@omnivore/puppeteer-parse", "start"]

View File

@ -0,0 +1,111 @@
# FROM node:14-slim
# # Taken from pu
# # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# # 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-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
# --no-install-recommends \
# && rm -rf /var/lib/apt/lists/*
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
# ENV CHROMIUM_PATH "/usr/bin/google-chrome-stable"
# ------------------------
# FROM --platform=linux/arm64 node:14.18
# RUN apt-get update \
# && apt-get install -y chromium \
# && apt-get install -y ca-certificates \
# fonts-liberation \
# libappindicator3-1 \
# libasound2 \
# libatk-bridge2.0-0 \
# libatk1.0-0 \
# libc6 \
# libcairo2 \
# libcups2 \
# libdbus-1-3 \
# libexpat1 \
# libfontconfig1 \
# libgbm1 \
# libgcc1 \
# libglib2.0-0 \
# libgtk-3-0 \
# libnspr4 \
# libnss3 \
# libpango-1.0-0 \
# libpangocairo-1.0-0 \
# libstdc++6 \
# libx11-6 \
# libx11-xcb1 \
# libxcb1 \
# libxcomposite1 \
# libxcursor1 \
# libxdamage1 \
# libxext6 \
# libxfixes3 \
# libxi6 \
# libxrandr2 \
# libxrender1 \
# libxss1 \
# libxtst6 \
# lsb-release \
# wget \
# xdg-utils
FROM node:14.18-alpine
# Installs latest Chromium (92) package.
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont \
nodejs \
yarn
# Add user so we don't need --no-sandbox.
RUN addgroup -S pptruser && adduser -S -g pptruser pptruser \
&& mkdir -p /home/pptruser/Downloads /app \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /app
# Run everything after as non-privileged user.
WORKDIR /app
ENV CHROMIUM_PATH /usr/bin/chromium-browser
ENV LAUNCH_HEADLESS=true
COPY package.json .
COPY yarn.lock .
COPY tsconfig.json .
COPY .prettierrc .
COPY .eslintrc .
COPY /packages/content-handler/package.json ./packages/content-handler/package.json
RUN yarn install --pure-lockfile
ADD /packages/puppeteer-parse ./packages/puppeteer-parse
ADD /packages/content-handler ./packages/content-handler
RUN yarn workspace @omnivore/content-handler build
# After building, fetch the production dependencies
RUN rm -rf /app/packages/puppeteer-parse/node_modules
RUN rm -rf /app/node_modules
RUN yarn install --pure-lockfile --production
EXPOSE 8080
# USER pptruser
ENTRYPOINT ["yarn", "workspace", "@omnivore/puppeteer-parse", "start_preview"]

View File

@ -4,9 +4,10 @@
"description": "Google Cloud Function that accepts URL of the article and parses its content",
"main": "index.js",
"dependencies": {
"@google-cloud/functions-framework": "^3.1.2",
"@google-cloud/logging-winston": "^5.1.1",
"@google-cloud/storage": "^5.18.1",
"@omnivore/content-handler": "file:./content-handler",
"@omnivore/content-handler": "file:./../content-handler",
"@sentry/serverless": "^6.13.3",
"axios": "^0.27.2",
"chrome-aws-lambda": "^10.1.0",
@ -18,9 +19,6 @@
"underscore": "^1.13.4",
"winston": "^3.3.3"
},
"devDependencies": {
"@google-cloud/functions-framework": "^3.0.0"
},
"scripts": {
"start": "npx functions-framework --port=9090 --target=puppeteer",
"start_preview": "npx functions-framework --target=preview",

View File

@ -2390,7 +2390,7 @@
google-gax "^2.24.1"
protobufjs "^6.8.6"
"@google-cloud/functions-framework@3.1.2", "@google-cloud/functions-framework@^3.0.0":
"@google-cloud/functions-framework@3.1.2", "@google-cloud/functions-framework@^3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@google-cloud/functions-framework/-/functions-framework-3.1.2.tgz#2cd92ce4307bf7f32555d028dca22e398473b410"
integrity sha512-pYvEH65/Rqh1JNPdcBmorcV7Xoom2/iOSmbtYza8msro7Inl+qOYxbyMiQfySD2gwAyn38WyWPRqsDRcf/BFLg==
@ -4323,17 +4323,6 @@
underscore "^1.13.6"
uuid "^9.0.0"
"@omnivore/content-handler@file:./packages/inbound-email-handler/content-handler":
version "1.0.0"
dependencies:
addressparser "^1.0.1"
axios "^0.27.2"
linkedom "^0.14.16"
luxon "^3.0.4"
rfc2047 "^4.0.1"
underscore "^1.13.6"
uuid "^9.0.0"
"@opentelemetry/api-metrics@0.27.0":
version "0.27.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/api-metrics/-/api-metrics-0.27.0.tgz#d8eca344ed1155f3ea8a8133ade827b4bb90efbf"