Skip to content

Commit 12b6da0

Browse files
committed
Create dockerfile for frontend app
1 parent b7ba663 commit 12b6da0

File tree

3 files changed

+1900
-2214
lines changed

3 files changed

+1900
-2214
lines changed

apps/frontend/Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
FROM node:18-alpine AS base
2+
3+
# For now we can specify it here, else we can use --build-arg in our docker build command
4+
ENV NEXT_PUBLIC_API_URL="http://localhost:8080/"
5+
6+
# Install dependencies only when needed
7+
FROM base AS deps
8+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
9+
RUN apk add --no-cache libc6-compat
10+
WORKDIR /app
11+
12+
# Install dependencies based on the preferred package manager
13+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
14+
RUN \
15+
if [ -f pnpm-lock.yaml ]; then corepack enable 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 /app/node_modules ./node_modules
23+
COPY . .
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 \
31+
if [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
32+
else echo "Lockfile not found." && exit 1; \
33+
fi
34+
35+
# Production image, copy all the files and run next
36+
FROM base AS runner
37+
WORKDIR /app
38+
39+
ENV NODE_ENV=production
40+
# Uncomment the following line in case you want to disable telemetry during runtime.
41+
# ENV NEXT_TELEMETRY_DISABLED=1
42+
43+
RUN addgroup --system --gid 1001 nodejs
44+
RUN adduser --system --uid 1001 nextjs
45+
46+
# Include this when we want to include images in the future
47+
# COPY --from=builder /app/public ./public
48+
49+
# Set the correct permission for prerender cache
50+
RUN mkdir .next
51+
RUN chown nextjs:nodejs .next
52+
53+
# Automatically leverage output traces to reduce image size
54+
# https://nextjs.org/docs/advanced-features/output-file-tracing
55+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
56+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
57+
58+
USER nextjs
59+
60+
EXPOSE 3000
61+
62+
ENV PORT=3000
63+
64+
# server.js is created by next build from the standalone output
65+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
66+
ENV HOSTNAME="0.0.0.0"
67+
CMD ["node", "server.js"]

apps/frontend/next.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
const nextConfig = {
3+
output: "standalone",
4+
};
35

46
export default nextConfig;

0 commit comments

Comments
 (0)