From 5635e1800e3dd3f70ee2a0561396b614fd58689c Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Sun, 31 Jul 2022 20:31:33 +0200 Subject: [PATCH] Disable double caching of dependencies in dockerfile Signed-off-by: Tilman Vatteroth Use node-slim for building Signed-off-by: Tilman Vatteroth Use standalone mode Signed-off-by: Tilman Vatteroth Use alpine Signed-off-by: Tilman Vatteroth --- Dockerfile | 28 ++++++++++++---------------- next.config.js | 3 ++- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 744c645c5..08fb87256 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,32 +3,28 @@ # SPDX-License-Identifier: CC-BY-SA-4.0 # BUILD - -FROM node:18 AS builder +FROM node:18-alpine AS builder ENV NEXT_TELEMETRY_DISABLED=1 -WORKDIR /usr/src/app -RUN chown -R node:node . /usr/src/app -USER node -COPY --chown=node . ./ +WORKDIR /app +COPY . ./ RUN yarn install --immutable && \ - yarn build:for-real-backend && \ - rm -rf .next/cache + yarn build:for-real-backend # RUNNER - -FROM node:18-slim +FROM node:18-alpine ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 WORKDIR /app RUN chown node:node -R /app -COPY --chown=node package.json yarn.lock .yarnrc.yml ./ -COPY --chown=node .yarn/ .yarn/ -COPY --chown=node public/ public/ -COPY --chown=node --from=builder /usr/src/app/.next/ .next/ + +COPY --from=builder --chown=node:node /app/.next/standalone ./ +COPY --from=builder --chown=node:node /app/.next/static ./.next/static +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json + USER node -RUN yarn workspaces focus --all --production EXPOSE 3001/tcp -CMD ["/usr/local/bin/yarn", "start:for-real-backend"] +CMD ["node", "server.js"] diff --git a/next.config.js b/next.config.js index 30e11a98c..da0e74815 100644 --- a/next.config.js +++ b/next.config.js @@ -110,7 +110,8 @@ const rawNextConfig = { permanent: true } ]) - } + }, + output: 'standalone', } const completeNextConfig = withBundleAnalyzer(rawNextConfig)