Optimize docker image size
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
tobias 2024-06-14 22:35:28 +02:00
parent 954b950d18
commit 82300f54eb
5 changed files with 4537 additions and 4956 deletions

9
.dockerignore Normal file
View File

@ -0,0 +1,9 @@
node_modules
.next
.gitignore
README.md
.dockerignore
.git
.vscode
.idea
.github

View File

@ -1,42 +1,37 @@
FROM node:lts as base # Build stage
FROM node:20-slim as builder
# Set environment variables for pnpm
ENV PNPM_HOME="/pnpm" ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH" ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable RUN corepack enable
WORKDIR /base
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
# Build stage: build the Next.js application WORKDIR /builder
FROM base as build COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
ENV NODE_ENV=production ENV NODE_ENV=production
WORKDIR /base COPY . .
RUN pnpm build RUN pnpm build
# Production stage: serve the application # Production stage: serve the application
FROM node:lts as prod FROM node:20-slim as runner
ENV NODE_ENV=production WORKDIR /runner
WORKDIR /app ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable RUN corepack enable
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --production
# Copy build artifacts from the build stage ## Copy build artifacts from the build stage
COPY --from=build /base/.next ./.next COPY --from=builder /builder/package.json ./
COPY --from=build /base/public ./public #COPY --from=builder /builder/node_modules ./node_modules
COPY --from=build /base/next.config.mjs ./ COPY --from=builder /builder/.next/standalone ./.next/standalone/
COPY --from=builder /builder/.next/static ./.next/static
COPY --from=builder /builder/public ./public
COPY --from=builder /builder/next.config.mjs ./
# Expose the port for the application #FROM runner as server
EXPOSE 3000 EXPOSE 3000
CMD ["pnpm", "start:standalone"]
# Copy and configure the entrypoint script
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["pnpm", "start"]

View File

@ -4,8 +4,9 @@ import { withPayload } from '@payloadcms/next/withPayload'
const nextConfig = { const nextConfig = {
// Your Next.js config here // Your Next.js config here
experimental: { experimental: {
reactCompiler: false reactCompiler: false,
} },
output: 'standalone',
} }
export default withPayload(nextConfig) export default withPayload(nextConfig)

View File

@ -13,17 +13,16 @@
"lint": "cross-env NODE_OPTIONS=--no-deprecation next lint", "lint": "cross-env NODE_OPTIONS=--no-deprecation next lint",
"ci": "payload migrate && pnpm build", "ci": "payload migrate && pnpm build",
"generate:types": "payload generate:types", "generate:types": "payload generate:types",
"standalone-script": "node ./src/scripts/standalone-script.js" "standalone-script": "node ./standalone-script.js",
"start:standalone": "node .next/standalone/server.js"
}, },
"engines": { "engines": {
"node": "^18.20.2 || >=20.6.0" "node": "^18.20.2 || >=20.6.0"
}, },
"dependencies": { "dependencies": {
"@payloadcms/db-mongodb": "3.0.0-beta.40", "@payloadcms/db-mongodb": "3.0.0-beta.40",
"@payloadcms/db-postgres": "3.0.0-beta.40",
"@payloadcms/next": "3.0.0-beta.40", "@payloadcms/next": "3.0.0-beta.40",
"@payloadcms/richtext-lexical": "3.0.0-beta.40", "@payloadcms/richtext-lexical": "3.0.0-beta.40",
"@payloadcms/richtext-slate": "3.0.0-beta.40",
"@payloadcms/ui": "3.0.0-beta.40", "@payloadcms/ui": "3.0.0-beta.40",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"graphql": "^16.8.1", "graphql": "^16.8.1",

File diff suppressed because it is too large Load Diff