build(app): optimize app docker image by use Next.js standalone output

This commit is contained in:
WanQuanXie 2024-05-09 02:16:45 +08:00
parent 4f5f6be85f
commit 838b779f3d
2 changed files with 19 additions and 7 deletions

View file

@ -1,9 +1,4 @@
FROM node:alpine FROM node:alpine as builder
ARG NEXT_PUBLIC_WS_URL
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
WORKDIR /home/perplexica WORKDIR /home/perplexica
@ -12,4 +7,20 @@ COPY ui /home/perplexica/
RUN yarn install RUN yarn install
RUN yarn build RUN yarn build
CMD ["yarn", "start"] FROM node:alpine as runner
ARG NEXT_PUBLIC_WS_URL
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
WORKDIR /home/perplexica
COPY --from=builder /home/perplexica/package.json .
COPY --from=builder /home/perplexica/yarn.lock .
COPY --from=builder /home/perplexica/next.config.mjs .
COPY --from=builder /home/perplexica/.next/standalone .
COPY --from=builder /home/perplexica/public ./public
COPY --from=builder /home/perplexica/.next/static ./.next/static
ENTRYPOINT ["node", "server.js"]

View file

@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
output: 'standalone',
images: { images: {
remotePatterns: [ remotePatterns: [
{ {