From 9a3cd629fdf93682c39f5555de94f23d63f14c63 Mon Sep 17 00:00:00 2001 From: andrzej Date: Tue, 1 Oct 2024 14:56:25 +0200 Subject: [PATCH] begin docker setup --- .dockerignore | 4 +++ Dockerfile | 73 +++++++++++++++++++++++++++++++++++++++++++++ ecosystem.config.js | 8 +++++ next.config.mjs | 1 + package-lock.json | 12 ++------ package.json | 2 +- 6 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 ecosystem.config.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c779817 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.log +node_modules +.git +.next diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4db8a25 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,73 @@ +FROM node:20-alpine AS base + + + +### Dependencies ### +FROM base AS deps +RUN apk add --no-cache libc6-compat git + + + +# Setup pnpm environment +ENV NPM_HOME="/npm" +ENV PATH="$NPM_HOME:$PATH" +RUN corepack enable +RUN corepack prepare npm@latest --activate + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm install --production + +# Builder +FROM base AS builder + +RUN corepack enable +RUN corepack prepare npm@latest --activate + + +COPY prisma prisma + +WORKDIR /app + +COPY --from=deps /app/node_modules ./node_modules +COPY . . + + +RUN [ "npx", "prisma", generate ] +RUN npm run build + + +### Production image runner ### +FROM base AS runner + +# Set NODE_ENV to production +ENV NODE_ENV production + +# Disable Next.js telemetry +# Learn more here: https://nextjs.org/telemetry +ENV NEXT_TELEMETRY_DISABLED 1 + +# Set correct permissions for nextjs user and don't run as root +RUN addgroup nodejs +RUN adduser -SDH nextjs +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/public ./public + +USER nextjs + +# Exposed port (for orchestrators and dynamic reverse proxies) +EXPOSE 3000 +ENV PORT 3000 +ENV HOSTNAME "0.0.0.0" +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "wget", "-q0", "http://localhost:3000/health" ] + +# Run the nextjs app +CMD ["node", "server.js"] + diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..fd9f27e --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,8 @@ +module.exports = { + apps: [ + { + name: "subman", + script: "npm run next start", + }, + ], +}; diff --git a/next.config.mjs b/next.config.mjs index 9f5042c..98fd83d 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -4,6 +4,7 @@ const nextConfig = { config.externals = [...config.externals, "bcrypt"]; return config; }, + output: "standalone", }; export default nextConfig; diff --git a/package-lock.json b/package-lock.json index 95983ef..b778bb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "lucide-react": "^0.394.0", "next": "^14.2.13", "next-themes": "^0.3.0", + "prisma": "^5.15.0", "react": "^18", "react-day-picker": "^8.10.1", "react-dom": "^18", @@ -49,7 +50,6 @@ "autoprefixer": "^10.4.19", "eslint-config-next": "14.2.3", "postcss": "^8.4.38", - "prisma": "^5.15.0", "tailwindcss": "^3.4.4", "typescript": "^5" } @@ -429,7 +429,6 @@ "version": "5.16.0", "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.16.0.tgz", "integrity": "sha512-OGvi/GvLX3XwTWQ+k/57kLyHGidQ8rC8zB+Zq9nEE7gegjazyzgLYN9qzfdcCfyI8ilc6IMxOyX4sspwkv98hg==", - "devOptional": true, "hasInstallScript": true, "dependencies": { "@prisma/debug": "5.16.0", @@ -441,20 +440,17 @@ "node_modules/@prisma/engines-version": { "version": "5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303", "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303.tgz", - "integrity": "sha512-HkT2WbfmFZ9WUPyuJHhkiADxazHg8Y4gByrTSVeb3OikP6tjQ7txtSUGu9OBOBH0C13dPKN2qqH12xKtHu/Hiw==", - "devOptional": true + "integrity": "sha512-HkT2WbfmFZ9WUPyuJHhkiADxazHg8Y4gByrTSVeb3OikP6tjQ7txtSUGu9OBOBH0C13dPKN2qqH12xKtHu/Hiw==" }, "node_modules/@prisma/engines/node_modules/@prisma/debug": { "version": "5.16.0", "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.16.0.tgz", - "integrity": "sha512-pfdOGxMShqZKkNNskYB0yXICsqL6rOkQUKNktouUZ9Y9ASd5736+ae2fpzif7onwJiIyEpu/yvOO3rFUbliKTA==", - "devOptional": true + "integrity": "sha512-pfdOGxMShqZKkNNskYB0yXICsqL6rOkQUKNktouUZ9Y9ASd5736+ae2fpzif7onwJiIyEpu/yvOO3rFUbliKTA==" }, "node_modules/@prisma/engines/node_modules/@prisma/fetch-engine": { "version": "5.16.0", "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.16.0.tgz", "integrity": "sha512-8C8y6J9eWRl+R/aO3vQ2HlmM9IbjAmrZaaEAdC0OJfG3CHvbTOcL7VRY6CEUKo8RwZ8bdATOePaSMS634fHWgw==", - "devOptional": true, "dependencies": { "@prisma/debug": "5.16.0", "@prisma/engines-version": "5.16.0-24.34ace0eb2704183d2c05b60b52fba5c43c13f303", @@ -465,7 +461,6 @@ "version": "5.16.0", "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.16.0.tgz", "integrity": "sha512-ynp2jAYfYdd7OObX+uWaFRpvhPVmpF0nsRMhbrWdVVUj39q3Zr8dGz5WDj2g+BTUE++u1T1Am3RyM3PBQdDZXA==", - "devOptional": true, "dependencies": { "@prisma/debug": "5.16.0" } @@ -7660,7 +7655,6 @@ "version": "5.16.0", "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.16.0.tgz", "integrity": "sha512-T1ZWJT/vgzp3rtRmd1iCSnPPsgOItXnnny+/cfpHraowiBEvUMD2pEI6yEOL6CP2EelTmq4wKDbXbYucy4Fd+A==", - "devOptional": true, "hasInstallScript": true, "dependencies": { "@prisma/engines": "5.16.0" diff --git a/package.json b/package.json index 644d84d..cc4bac4 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "react-day-picker": "^8.10.1", "react-dom": "^18", "react-hook-form": "^7.51.5", + "prisma": "^5.15.0", "recharts": "^2.12.7", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7", @@ -52,7 +53,6 @@ "autoprefixer": "^10.4.19", "eslint-config-next": "14.2.3", "postcss": "^8.4.38", - "prisma": "^5.15.0", "tailwindcss": "^3.4.4", "typescript": "^5" },