From a55661164b84cb60e52e0125bc980affb42e662d Mon Sep 17 00:00:00 2001 From: Chris Grimmett Date: Fri, 29 Mar 2024 19:27:03 -0800 Subject: [PATCH] make next.dockerfile more lightweight --- .nvmrc | 1 + next.dockerfile | 35 ++++++++++++++++++++------------- packages/bot/.gitignore | 1 + packages/link2cid/.dockerignore | 3 +++ packages/link2cid/package.json | 2 +- packages/next/package.json | 2 +- packages/strapi/package.json | 2 +- 7 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 .nvmrc create mode 100644 packages/bot/.gitignore create mode 100644 packages/link2cid/.dockerignore diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..9de2256 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/iron diff --git a/next.dockerfile b/next.dockerfile index fc6e788..3eb61ce 100644 --- a/next.dockerfile +++ b/next.dockerfile @@ -1,3 +1,6 @@ +## Important! Build context is the ROOT of the project. +## this keeps the door open for future possibility of shared code between pnpm workspace packages + FROM node:20-slim AS base FROM base AS deps @@ -15,24 +18,27 @@ ENV NEXT_PUBLIC_SITE_URL ${NEXT_PUBLIC_SITE_URL} ENV NEXT_PUBLIC_STRAPI_URL ${NEXT_PUBLIC_STRAPI_URL} ENV NEXT_PUBLIC_UPPY_COMPANION_URL ${NEXT_PUBLIC_UPPY_COMPANION_URL} ENV NEXT_TELEMETRY_DISABLED 1 -COPY package.json pnpm-lock.yaml ./ -RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store pnpm install -COPY ./packages/next . +COPY pnpm-lock.yaml package.json ./ +RUN pnpm fetch +RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store pnpm install --offline +COPY ./packages/next /app -FROM deps AS dev -COPY --from=install /app /app -ENV NEXT_TELEMETRY_DISABLED 1 +FROM install AS dev CMD ["pnpm", "run", "dev"] -FROM install AS build -COPY --chown=node:node --from=install /app/package.json /app/pnpm-lock.yaml ./ -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile -COPY --from=install /app /app -RUN echo "hello gitea" -RUN pnpm run build +FROM install AS build +RUN pnpm run build +# COPY --chown=node:node --from=install /app/package.json /app/pnpm-lock.yaml ./ +# RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile +# COPY --from=install /app /app # i think this is duplicate +# can't get these to work because errors like "/prod/next/.next/standalone": not found +# as if pnpm is not copying the build artifacts. +# also this makes the build REALLY slow (adds ~10mins to build time) +# RUN pnpm deploy --filter=@futureporn/next --prod /prod/next +# RUN pnpm deploy --filter=@futureporn/link2cid --prod /prod/link2cid # FROM deps as release # # ENV NEXT_SHARP_PATH=/app/node_modules/sharp @@ -45,7 +51,7 @@ RUN pnpm run build -FROM install AS release +FROM deps AS next RUN apt-get update && apt-get install -y -qq --no-install-recommends dumb-init COPY --chown=node:node --from=build /app/package.json /app/pnpm-lock.yaml ./ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile @@ -55,4 +61,5 @@ COPY --chown=node:node --from=build /app/.next/static ./.next/static ENV TZ=UTC ENV NODE_ENV=production ENV HOSTNAME="0.0.0.0" -CMD [ "dumb-init", "node", "server.js" ] \ No newline at end of file +CMD [ "dumb-init", "node", "server.js" ] + diff --git a/packages/bot/.gitignore b/packages/bot/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/packages/bot/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/packages/link2cid/.dockerignore b/packages/link2cid/.dockerignore new file mode 100644 index 0000000..3176bcb --- /dev/null +++ b/packages/link2cid/.dockerignore @@ -0,0 +1,3 @@ +node_modules +.env +*~ \ No newline at end of file diff --git a/packages/link2cid/package.json b/packages/link2cid/package.json index 9f0599b..de17ac5 100644 --- a/packages/link2cid/package.json +++ b/packages/link2cid/package.json @@ -1,5 +1,5 @@ { - "name": "link2cid", + "name": "@futureporn/link2cid", "version": "3.2.0", "description": "REST API for adding files to IPFS", "main": "index.js", diff --git a/packages/next/package.json b/packages/next/package.json index 11818f8..a22d4d5 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -1,5 +1,5 @@ { - "name": "fp-next", + "name": "@futureporn/next", "version": "2.0.0", "private": true, "scripts": { diff --git a/packages/strapi/package.json b/packages/strapi/package.json index de81be2..d20c735 100644 --- a/packages/strapi/package.json +++ b/packages/strapi/package.json @@ -1,5 +1,5 @@ { - "name": "futureporn-strapi", + "name": "@futureporn/strapi", "private": true, "version": "0.1.0", "description": "A Strapi application",