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 https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
FROM node:22.17.0-alpine AS base
|
||||
|
||||
# Install dependencies only when needed
|
||||
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
|
||||
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
|
||||
WORKDIR /app
|
||||
RUN corepack enable && corepack prepare pnpm@9 --activate
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Next.js collects completely anonymous telemetry data about general usage.
|
||||
# Learn more here: https://nextjs.org/telemetry
|
||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV DATABASE_URI="mongodb://localhost:27017/build-placeholder"
|
||||
ENV PAYLOAD_SECRET="build-time-placeholder"
|
||||
ENV NEXT_PUBLIC_SERVER_URL="http://localhost:3000"
|
||||
ENV NODE_ENV=production
|
||||
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn run build; \
|
||||
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
|
||||
RUN pnpm payload generate:types || echo "Skipped"
|
||||
RUN pnpm next build --experimental-build-mode compile
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
ENV NODE_ENV production
|
||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
RUN apk add --no-cache libc6-compat curl
|
||||
RUN addgroup --system --gid 1001 nodejs && \
|
||||
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
|
||||
|
||||
# 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
|
||||
RUN mkdir .next && chown nextjs:nodejs .next
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 3001
|
||||
ENV PORT=3001
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
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
|
||||
CMD ["node", "server.js"]
|
||||
|
|
@ -3,29 +3,23 @@ version: '3'
|
|||
services:
|
||||
payload:
|
||||
image: node:18-alpine
|
||||
pull_policy: always
|
||||
ports:
|
||||
- '3000:3000'
|
||||
- '3001:3000'
|
||||
volumes:
|
||||
- .:/home/node/app
|
||||
- node_modules:/home/node/app/node_modules
|
||||
working_dir: /home/node/app/
|
||||
command: sh -c "yarn install && yarn dev"
|
||||
depends_on:
|
||||
- mongo
|
||||
env_file:
|
||||
- .env
|
||||
|
||||
mongo:
|
||||
image: mongo:latest
|
||||
ports:
|
||||
- '27017:27017'
|
||||
command:
|
||||
- --storageEngine=wiredTiger
|
||||
volumes:
|
||||
- data:/data/db
|
||||
logging:
|
||||
driver: none
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATABASE_URI=${DATABASE_URI}
|
||||
- PAYLOAD_SECRET=${PAYLOAD_SECRET}
|
||||
- NEXT_PUBLIC_SERVER_URL=${NEXT_PUBLIC_SERVER_URL}
|
||||
- CRON_SECRET=${CRON_SECRET}
|
||||
- PREVIEW_SECRET=${PREVIEW_SECRET}
|
||||
- PAYLOAD_DROP_DATABASE=false
|
||||
- PAYLOAD_SEED=false
|
||||
|
||||
volumes:
|
||||
data:
|
||||
node_modules:
|
||||
|
|
@ -7,13 +7,9 @@ const __filename = fileURLToPath(import.meta.url)
|
|||
const dirname = path.dirname(__filename)
|
||||
import { redirects } from './redirects'
|
||||
|
||||
const NEXT_PUBLIC_SERVER_URL = process.env.VERCEL_PROJECT_PRODUCTION_URL
|
||||
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
|
||||
: process.env.__NEXT_PRIVATE_ORIGIN || 'http://localhost:3000'
|
||||
const NEXT_PUBLIC_SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:3001'
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
// Temporarily required on Windows until Next.js fixes Turbopack Sass resolution.
|
||||
// See: https://github.com/vercel/next.js/issues/86431
|
||||
sassOptions: {
|
||||
loadPaths: ['./node_modules/@payloadcms/ui/dist/scss/'],
|
||||
},
|
||||
|
|
@ -25,7 +21,7 @@ const nextConfig: NextConfig = {
|
|||
],
|
||||
qualities: [100],
|
||||
remotePatterns: [
|
||||
...[NEXT_PUBLIC_SERVER_URL /* 'https://example.com' */].map((item) => {
|
||||
...[NEXT_PUBLIC_SERVER_URL].map((item) => {
|
||||
const url = new URL(item)
|
||||
|
||||
return {
|
||||
|
|
@ -42,8 +38,15 @@ const nextConfig: NextConfig = {
|
|||
'.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
|
||||
},
|
||||
|
||||
reactStrictMode: true,
|
||||
redirects,
|
||||
turbopack: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue