From 509316b60b0268001d0ffa1fe8e600cc3d47318f Mon Sep 17 00:00:00 2001 From: Vojtech Mares Date: Tue, 27 Jun 2023 14:02:24 +0200 Subject: [PATCH] chore(build): build docker image --- .dockerignore | 9 ++++++++ Dockerfile | 53 ++++++++++++++++++++++++++++++++++++++++++++ next.config.mjs | 2 ++ prisma/schema.prisma | 1 + 4 files changed, 65 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a0c5816 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.env +Dockerfile +.dockerignore +node_modules +npm-debug.log +README.md +.next +.git +README.create-t3-gg.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a9877a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +FROM --platform=linux/amd64 node:18-alpine3.17 as base + +##### DEPENDENCIES + +FROM base AS deps +RUN apk add --no-cache libc6-compat openssl1.1-compat +WORKDIR /app + +COPY prisma ./ + +# Install dependencies based on the preferred package manager + +COPY package.json package-lock.json ./ + +RUN npm ci --frozen-lockfile + +##### BUILDER + +FROM base AS builder +ARG DATABASE_URL +ARG NEXT_PUBLIC_CLIENTVAR +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN SKIP_ENV_VALIDATION=1 npm run build + +##### RUNNER + +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production + +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/next.config.mjs ./ +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json + +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 + +CMD ["node", "server.js"] diff --git a/next.config.mjs b/next.config.mjs index 654e725..00d515a 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -18,6 +18,8 @@ const config = { locales: ["en"], defaultLocale: "en", }, + swcMinify: true, + output: "standalone", }; export default config; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e98bc8b..e4b6c29 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -4,6 +4,7 @@ generator client { provider = "prisma-client-js" previewFeatures = ["jsonProtocol"] + binaryTargets = ["native", "linux-musl-openssl-3.0.x"] } datasource db {