From c753e50e55acc0f0df25d707c6e4e2f94541de29 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 9 May 2023 15:40:40 +0800 Subject: [PATCH] Add Dockerfile and script for self hosting --- self-hosting/Dockerfile | 63 ++++++++++++++++++++++++++++++++++++++++ self-hosting/selfhost.sh | 16 ++++++++++ 2 files changed, 79 insertions(+) create mode 100644 self-hosting/Dockerfile create mode 100644 self-hosting/selfhost.sh diff --git a/self-hosting/Dockerfile b/self-hosting/Dockerfile new file mode 100644 index 000000000..f3166336d --- /dev/null +++ b/self-hosting/Dockerfile @@ -0,0 +1,63 @@ +FROM node:14.18-alpine as builder + +WORKDIR /app + +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true +RUN apk add g++ make python3 + +COPY package.json . +COPY yarn.lock . +COPY tsconfig.json . +COPY .prettierrc . +COPY .eslintrc . + +COPY selfhost.sh /app/selfhost.sh +COPY /packages/readabilityjs/package.json ./packages/readabilityjs/package.json +COPY /packages/api/package.json ./packages/api/package.json +COPY /packages/text-to-speech/package.json ./packages/text-to-speech/package.json +COPY /packages/content-handler/package.json ./packages/content-handler/package.json +COPY /packages/db/package.json ./packages/db/package.json + +RUN yarn install --pure-lockfile + +ADD /packages/readabilityjs ./packages/readabilityjs +ADD /packages/api ./packages/api +ADD /packages/text-to-speech ./packages/text-to-speech +ADD /packages/content-handler ./packages/content-handler +ADD /packages/db ./packages/db + +RUN yarn workspace @omnivore/text-to-speech-handler build +RUN yarn workspace @omnivore/content-handler build +RUN yarn workspace @omnivore/api build + +RUN rm -rf /app/packages/api/node_modules +RUN rm -rf /app/node_modules +RUN yarn install --pure-lockfile --production + +FROM node:14.18-alpine as runner + +WORKDIR /app + +ENV NODE_ENV production +ENV NODE_OPTIONS=--max-old-space-size=4096 +ENV PORT=8080 + +COPY --from=builder /app/packages/api/dist /app/packages/api/dist +COPY --from=builder /app/packages/readabilityjs/ /app/packages/readabilityjs/ +COPY --from=builder /app/packages/api/package.json /app/packages/api/package.json +COPY --from=builder /app/packages/api/node_modules /app/packages/api/node_modules +COPY --from=builder /app/node_modules /app/node_modules +COPY --from=builder /app/package.json /app/package.json +COPY --from=builder /app/packages/text-to-speech/ /app/packages/text-to-speech/ +COPY --from=builder /app/packages/content-handler/ /app/packages/content-handler/ +COPY --from=builder /app/packages/db/ /app/packages/db/ +COPY --from=builder /app/selfhost.sh /app/selfhost.sh + +RUN apk add postgresql-client +RUN chmod 0755 /app/selfhost.sh + +EXPOSE 8080 + +# Using a custom script to customize imageproxy startup and to pass +# signatureKey through env variable +ENTRYPOINT ["/app/selfhost.sh"] diff --git a/self-hosting/selfhost.sh b/self-hosting/selfhost.sh new file mode 100644 index 000000000..a950dd163 --- /dev/null +++ b/self-hosting/selfhost.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +echo "creating omnivore database with $(which psql)" +psql --host $PG_HOST -U $PG_USER -c "CREATE DATABASE omnivore;" + +echo "creating app_user" +psql --host $PG_HOST -U $PG_USER -d $PG_DB -c "CREATE USER app_user WITH PASSWORD 'app_pass';" +echo "created app_user" + +echo "running migrations" +yarn workspace @omnivore/db migrate + +psql --host $PG_HOST -U $PG_USER -d $PG_DB -c "GRANT omnivore_user TO app_user;" +echo "granted omnivore_user to app_user" + +yarn workspace @omnivore/api start