Disable double caching of dependencies in dockerfile

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

Use node-slim for building

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

Use standalone mode

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

Use alpine

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-07-31 20:31:33 +02:00
parent 4bd0c4708b
commit 5635e1800e
2 changed files with 14 additions and 17 deletions

View file

@ -3,32 +3,28 @@
# SPDX-License-Identifier: CC-BY-SA-4.0 # SPDX-License-Identifier: CC-BY-SA-4.0
# BUILD # BUILD
FROM node:18-alpine AS builder
FROM node:18 AS builder
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /usr/src/app WORKDIR /app
RUN chown -R node:node . /usr/src/app COPY . ./
USER node
COPY --chown=node . ./
RUN yarn install --immutable && \ RUN yarn install --immutable && \
yarn build:for-real-backend && \ yarn build:for-real-backend
rm -rf .next/cache
# RUNNER # RUNNER
FROM node:18-alpine
FROM node:18-slim
ENV NODE_ENV=production ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app WORKDIR /app
RUN chown node:node -R /app RUN chown node:node -R /app
COPY --chown=node package.json yarn.lock .yarnrc.yml ./
COPY --chown=node .yarn/ .yarn/ COPY --from=builder --chown=node:node /app/.next/standalone ./
COPY --chown=node public/ public/ COPY --from=builder --chown=node:node /app/.next/static ./.next/static
COPY --chown=node --from=builder /usr/src/app/.next/ .next/ COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
USER node USER node
RUN yarn workspaces focus --all --production
EXPOSE 3001/tcp EXPOSE 3001/tcp
CMD ["/usr/local/bin/yarn", "start:for-real-backend"] CMD ["node", "server.js"]

View file

@ -110,7 +110,8 @@ const rawNextConfig = {
permanent: true permanent: true
} }
]) ])
} },
output: 'standalone',
} }
const completeNextConfig = withBundleAnalyzer(rawNextConfig) const completeNextConfig = withBundleAnalyzer(rawNextConfig)