fp/next.dockerfile

66 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-03-30 03:27:03 +00:00
## Important! Build context is the ROOT of the project.
## this keeps the door open for future possibility of shared code between pnpm workspace packages
2024-03-28 11:48:46 +00:00
FROM node:20-slim AS base
FROM base AS deps
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
WORKDIR /app
FROM deps AS install
ARG NEXT_PUBLIC_SITE_URL=https://futureporn.net
ARG NEXT_PUBLIC_STRAPI_URL=https://portal.futureporn.net
ARG NEXT_PUBLIC_UPPY_COMPANION_URL=https://uppy.futureporn.net
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
2024-03-30 05:01:24 +00:00
COPY pnpm-lock.yaml ./
2024-03-30 03:27:03 +00:00
RUN pnpm fetch
COPY ./packages/next /app
2024-03-30 05:01:24 +00:00
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store pnpm install --offline
2024-03-28 11:48:46 +00:00
2024-03-30 03:27:03 +00:00
FROM install AS dev
2024-03-28 11:48:46 +00:00
CMD ["pnpm", "run", "dev"]
2024-03-30 03:27:03 +00:00
2024-03-28 11:48:46 +00:00
FROM install AS build
RUN pnpm run build
2024-03-30 03:27:03 +00:00
# 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
2024-03-28 11:48:46 +00:00
# FROM deps as release
# # ENV NEXT_SHARP_PATH=/app/node_modules/sharp
# ENV NODE_ENV=production
# WORKDIR /app
# COPY --from=build /app/public ./public
# COPY --from=build /app/.next/standalone ./
# COPY --from=build /app/.next/static ./.next/static
# CMD [ "dumb-init", "node", "server.js" ]
2024-03-30 03:27:03 +00:00
FROM deps AS next
2024-03-28 11:48:46 +00:00
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
COPY --chown=node:node --from=build /app/public ./public
COPY --chown=node:node --from=build /app/.next/standalone ./
COPY --chown=node:node --from=build /app/.next/static ./.next/static
ENV TZ=UTC
ENV NODE_ENV=production
ENV HOSTNAME="0.0.0.0"
2024-03-30 03:27:03 +00:00
CMD [ "dumb-init", "node", "server.js" ]