Merge pull request #7 from m1xxos/self-host-updates

Api Dockerfile optimizations
This commit is contained in:
Tom Rogers 2024-12-13 15:43:36 +01:00 committed by GitHub
commit bc41ca22b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,51 +1,36 @@
FROM node:18.16 as builder
FROM node:18.16 AS builder
WORKDIR /app
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
RUN apt-get update && apt-get install -y g++ make python3
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
COPY package.json .
COPY yarn.lock .
COPY tsconfig.json .
COPY .prettierrc .
COPY .eslintrc .
RUN apt-get update && apt-get install -y g++ make python3 && apt-get clean && rm -rf /var/lib/apt/lists/*
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/liqe/package.json ./packages/liqe/package.json
COPY /packages/utils/package.json ./packages/utils/package.json
COPY package.json yarn.lock tsconfig.json .prettierrc .eslintrc ./
COPY packages ./packages
RUN yarn install --pure-lockfile
# Remove all except needed packages
RUN find packages -mindepth 1 -type d \
! -regex '^packages/\(api\|readabilityjs\|text-to-speech\|content-handler\|liqe\|utils\)\(/.*\)?' \
-exec rm -rf {} +
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/liqe ./packages/liqe
ADD /packages/utils ./packages/utils
RUN yarn install --pure-lockfile && \
yarn workspace @omnivore/utils build && \
yarn workspace @omnivore/text-to-speech-handler build && \
yarn workspace @omnivore/content-handler build && \
yarn workspace @omnivore/liqe build && \
yarn workspace @omnivore/api build && \
rm -rf /app/packages/api/node_modules /app/node_modules && \
yarn install --pure-lockfile --production
RUN yarn workspace @omnivore/utils build
RUN yarn workspace @omnivore/text-to-speech-handler build
RUN yarn workspace @omnivore/content-handler build
RUN yarn workspace @omnivore/liqe build
RUN yarn workspace @omnivore/api build
# After building, fetch the production dependencies
RUN rm -rf /app/packages/api/node_modules
RUN rm -rf /app/node_modules
RUN yarn install --pure-lockfile --production
FROM node:18.16 as runner
FROM node:18.16-alpine AS runner
LABEL org.opencontainers.image.source="https://github.com/omnivore-app/omnivore"
RUN apt-get update && apt-get install -y netcat-openbsd
RUN apk update && apk add netcat-openbsd && rm -rf /var/cache/apk/*
WORKDIR /app
ENV NODE_ENV production
ENV NODE_ENV=production
ENV NODE_OPTIONS=--max-old-space-size=4096
ENV PORT=8080
@ -59,6 +44,7 @@ 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/liqe/ /app/packages/liqe/
COPY --from=builder /app/packages/utils/ /app/packages/utils/
EXPOSE 8080
CMD ["yarn", "workspace", "@omnivore/api", "start"]