diff --git a/Dockerfile b/Dockerfile index e60534f9..314d6c36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,44 @@ -FROM node:18 +FROM node:18-alpine AS base +FROM base AS deps + +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +COPY package.json yarn.lock* package-lock.json* ./ + +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + else echo "Lockfile not found." && exit 1; \ + fi + +FROM base AS builder + +RUN apk update && apk add --no-cache git + +ENV OPENAI_API_KEY="" +ENV CODE="" +ARG DOCKER=true + +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +RUN yarn build + +FROM base AS runner WORKDIR /app ENV OPENAI_API_KEY="" ENV CODE="" -COPY . ./ - -RUN yarn && yarn build +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/.next/server ./.next/server EXPOSE 3000 -CMD ["yarn","start"] +CMD ["node","server.js"] diff --git a/next.config.js b/next.config.js index eea258d3..fc164db9 100644 --- a/next.config.js +++ b/next.config.js @@ -14,4 +14,8 @@ const nextConfig = { } }; +if (process.env.DOCKER) { + nextConfig.output = 'standalone' +} + module.exports = nextConfig;