Caleb Fahlgren commited on
Commit
cf661a0
·
1 Parent(s): d59a538

add dockerfile build

Browse files
Files changed (2) hide show
  1. Dockerfile +61 -0
  2. next.config.mjs +2 -0
Dockerfile ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1.4
2
+ # Adapted for Next.js App Router
3
+
4
+ FROM node:18 AS base
5
+
6
+ # Install dependencies only when needed
7
+ FROM base AS deps
8
+ WORKDIR /app
9
+
10
+ # Install dependencies based on the preferred package manager
11
+ COPY --link package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
12
+ RUN \
13
+ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
14
+ elif [ -f package-lock.json ]; then npm ci; \
15
+ elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
16
+ else echo "Lockfile not found." && exit 1; \
17
+ fi
18
+
19
+ # Rebuild the source code only when needed
20
+ FROM base AS builder
21
+ WORKDIR /app
22
+ COPY --from=deps --link /app/node_modules ./node_modules
23
+ COPY --link . .
24
+
25
+ # Next.js collects completely anonymous telemetry data about general usage.
26
+ # Learn more here: https://nextjs.org/telemetry
27
+ # Uncomment the following line in case you want to disable telemetry during the build.
28
+ # ENV NEXT_TELEMETRY_DISABLED 1
29
+
30
+ RUN npm run build
31
+
32
+ # Production image, copy all the files and run next
33
+ FROM base AS runner
34
+ WORKDIR /app
35
+
36
+ ENV NODE_ENV production
37
+
38
+ # Uncomment the following line in case you want to disable telemetry during runtime.
39
+ # ENV NEXT_TELEMETRY_DISABLED 1
40
+
41
+ RUN \
42
+ addgroup --system --gid 1001 nodejs; \
43
+ adduser --system --uid 1001 nextjs
44
+
45
+ # Set the correct permission for prerender cache
46
+ RUN mkdir .next
47
+ RUN chown nextjs:nodejs .next
48
+
49
+ # Automatically leverage output traces to reduce image size
50
+ # https://nextjs.org/docs/advanced-features/output-file-tracing
51
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
52
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
53
+
54
+ USER nextjs
55
+
56
+ EXPOSE 3000
57
+
58
+ ENV PORT 3000
59
+ ENV HOSTNAME 0.0.0.0
60
+
61
+ CMD ["node", "server.js"]
next.config.mjs CHANGED
@@ -1,5 +1,7 @@
1
  /** @type {import('next').NextConfig} */
2
  const nextConfig = {
 
 
3
  reactStrictMode: true,
4
  experimental: {
5
  appDir: true,
 
1
  /** @type {import('next').NextConfig} */
2
  const nextConfig = {
3
+ output: 'standalone',
4
+
5
  reactStrictMode: true,
6
  experimental: {
7
  appDir: true,