diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0d82803 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +docker +.git diff --git a/hosting/docker/development/Dockerfile b/hosting/docker/development/Dockerfile index a2b8008..0d23b69 100644 --- a/hosting/docker/development/Dockerfile +++ b/hosting/docker/development/Dockerfile @@ -1,9 +1,37 @@ FROM oven/bun:alpine AS base - # 1. Install dependencies only when needed +#1. Install dependencies FROM base AS deps - # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. - WORKDIR /app COPY package.json bun.lockb ./ RUN bun install --frozen-lockfile + +#2. Build the sources +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +COPY .env .env.production +RUN bun run build + +#3. Create the production image +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 + +COPY --from=builder /app/public ./public + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs +EXPOSE 3000 + +ENV PORT 3000 +ENV HOSTNAME localhost + +CMD ["node", "server.js"]