it should work
This commit is contained in:
parent
5811eaaf06
commit
8e0f5cdaa5
3 changed files with 44 additions and 74 deletions
71
Dockerfile
71
Dockerfile
|
|
@ -1,71 +1,44 @@
|
||||||
# To use this Dockerfile, you have to set `output: 'standalone'` in your next.config.js file.
|
FROM node:20-alpine AS base
|
||||||
# From https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
|
|
||||||
|
|
||||||
FROM node:22.17.0-alpine AS base
|
|
||||||
|
|
||||||
# Install dependencies only when needed
|
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
RUN corepack enable && corepack prepare pnpm@9 --activate
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
# Install dependencies based on the preferred package manager
|
|
||||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
|
||||||
RUN \
|
|
||||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
|
||||||
elif [ -f package-lock.json ]; then npm ci; \
|
|
||||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
|
||||||
else echo "Lockfile not found." && exit 1; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Rebuild the source code only when needed
|
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
RUN corepack enable && corepack prepare pnpm@9 --activate
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Next.js collects completely anonymous telemetry data about general usage.
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
# Learn more here: https://nextjs.org/telemetry
|
ENV DATABASE_URI="mongodb://localhost:27017/build-placeholder"
|
||||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
ENV PAYLOAD_SECRET="build-time-placeholder"
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
ENV NEXT_PUBLIC_SERVER_URL="http://localhost:3000"
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
RUN \
|
RUN pnpm payload generate:types || echo "Skipped"
|
||||||
if [ -f yarn.lock ]; then yarn run build; \
|
RUN pnpm next build --experimental-build-mode compile
|
||||||
elif [ -f package-lock.json ]; then npm run build; \
|
|
||||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
|
||||||
else echo "Lockfile not found." && exit 1; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
ENV NODE_ENV production
|
RUN apk add --no-cache libc6-compat curl
|
||||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
RUN addgroup --system --gid 1001 nodejs && \
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
|
||||||
RUN adduser --system --uid 1001 nextjs
|
|
||||||
|
|
||||||
# Remove this line if you do not have this folder
|
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
|
RUN mkdir .next && chown nextjs:nodejs .next
|
||||||
# Set the correct permission for prerender cache
|
|
||||||
RUN mkdir .next
|
|
||||||
RUN chown nextjs:nodejs .next
|
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
|
||||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
EXPOSE 3001
|
||||||
|
ENV PORT=3001
|
||||||
|
ENV HOSTNAME=0.0.0.0
|
||||||
|
|
||||||
EXPOSE 3000
|
CMD ["node", "server.js"]
|
||||||
|
|
||||||
ENV PORT 3000
|
|
||||||
|
|
||||||
# server.js is created by next build from the standalone output
|
|
||||||
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
|
||||||
CMD HOSTNAME="0.0.0.0" node server.js
|
|
||||||
|
|
@ -3,29 +3,23 @@ version: '3'
|
||||||
services:
|
services:
|
||||||
payload:
|
payload:
|
||||||
image: node:18-alpine
|
image: node:18-alpine
|
||||||
|
pull_policy: always
|
||||||
ports:
|
ports:
|
||||||
- '3000:3000'
|
- '3001:3000'
|
||||||
volumes:
|
volumes:
|
||||||
- .:/home/node/app
|
- .:/home/node/app
|
||||||
- node_modules:/home/node/app/node_modules
|
- node_modules:/home/node/app/node_modules
|
||||||
working_dir: /home/node/app/
|
working_dir: /home/node/app/
|
||||||
command: sh -c "yarn install && yarn dev"
|
command: sh -c "yarn install && yarn dev"
|
||||||
depends_on:
|
environment:
|
||||||
- mongo
|
- NODE_ENV=production
|
||||||
env_file:
|
- DATABASE_URI=${DATABASE_URI}
|
||||||
- .env
|
- PAYLOAD_SECRET=${PAYLOAD_SECRET}
|
||||||
|
- NEXT_PUBLIC_SERVER_URL=${NEXT_PUBLIC_SERVER_URL}
|
||||||
mongo:
|
- CRON_SECRET=${CRON_SECRET}
|
||||||
image: mongo:latest
|
- PREVIEW_SECRET=${PREVIEW_SECRET}
|
||||||
ports:
|
- PAYLOAD_DROP_DATABASE=false
|
||||||
- '27017:27017'
|
- PAYLOAD_SEED=false
|
||||||
command:
|
|
||||||
- --storageEngine=wiredTiger
|
|
||||||
volumes:
|
|
||||||
- data:/data/db
|
|
||||||
logging:
|
|
||||||
driver: none
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
data:
|
|
||||||
node_modules:
|
node_modules:
|
||||||
|
|
@ -7,13 +7,9 @@ const __filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(__filename)
|
const dirname = path.dirname(__filename)
|
||||||
import { redirects } from './redirects'
|
import { redirects } from './redirects'
|
||||||
|
|
||||||
const NEXT_PUBLIC_SERVER_URL = process.env.VERCEL_PROJECT_PRODUCTION_URL
|
const NEXT_PUBLIC_SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:3001'
|
||||||
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
|
|
||||||
: process.env.__NEXT_PRIVATE_ORIGIN || 'http://localhost:3000'
|
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
// Temporarily required on Windows until Next.js fixes Turbopack Sass resolution.
|
|
||||||
// See: https://github.com/vercel/next.js/issues/86431
|
|
||||||
sassOptions: {
|
sassOptions: {
|
||||||
loadPaths: ['./node_modules/@payloadcms/ui/dist/scss/'],
|
loadPaths: ['./node_modules/@payloadcms/ui/dist/scss/'],
|
||||||
},
|
},
|
||||||
|
|
@ -25,7 +21,7 @@ const nextConfig: NextConfig = {
|
||||||
],
|
],
|
||||||
qualities: [100],
|
qualities: [100],
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
...[NEXT_PUBLIC_SERVER_URL /* 'https://example.com' */].map((item) => {
|
...[NEXT_PUBLIC_SERVER_URL].map((item) => {
|
||||||
const url = new URL(item)
|
const url = new URL(item)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -42,8 +38,15 @@ const nextConfig: NextConfig = {
|
||||||
'.mjs': ['.mts', '.mjs'],
|
'.mjs': ['.mts', '.mjs'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const replaceHash = (val: unknown) =>
|
||||||
|
typeof val === 'string' ? val.replace('[chunkhash]', '[contenthash]') : val
|
||||||
|
|
||||||
|
webpackConfig.output.filename = replaceHash(webpackConfig.output.filename)
|
||||||
|
webpackConfig.output.chunkFilename = replaceHash(webpackConfig.output.chunkFilename)
|
||||||
|
|
||||||
return webpackConfig
|
return webpackConfig
|
||||||
},
|
},
|
||||||
|
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
redirects,
|
redirects,
|
||||||
turbopack: {
|
turbopack: {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue