Skip to content

Commit 736e5cf

Browse files
authored
Merge pull request #51 from refactor-group/add-dockerfile
Add Dockerfile
2 parents 27039cb + d3630c2 commit 736e5cf

14 files changed

+922
-1267
lines changed

.env

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL="http"
2+
NEXT_PUBLIC_BACKEND_SERVICE_PORT=4000
3+
NEXT_PUBLIC_BACKEND_SERVICE_HOST="localhost"
4+
NEXT_PUBLIC_BACKEND_API_VERSION="0.0.1"
5+
6+
FRONTEND_SERVICE_PORT=3000
7+
FRONTEND_SERVICE_INTERFACE=0.0.0.0

Dockerfile

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM node:18-alpine AS base
2+
3+
# 1. Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
8+
# Set the working directory
9+
WORKDIR /app
10+
11+
# Copy package.json and package-lock.json
12+
COPY package.json ./
13+
COPY package-lock.json ./
14+
15+
RUN npm install
16+
17+
# 2. Rebuild the source code only when needed
18+
FROM base AS builder
19+
WORKDIR /app
20+
COPY --from=deps /app/node_modules ./node_modules
21+
COPY . .
22+
# This will do the trick, use the corresponding env file for each environment.
23+
COPY .env .env
24+
RUN npm run build
25+
26+
# 3. Production image, copy all the files and run next
27+
FROM base AS runner
28+
WORKDIR /app
29+
30+
ENV NODE_ENV=production
31+
32+
RUN addgroup -g 1001 -S nodejs
33+
RUN adduser -S nextjs -u 1001
34+
35+
COPY --from=builder /app/public ./public
36+
37+
# Automatically leverage output traces to reduce image size
38+
# https://nextjs.org/docs/advanced-features/output-file-tracing
39+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
40+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
41+
42+
COPY --from=builder /app/package.json ./
43+
44+
USER nextjs
45+
46+
# Expose the port Next.js runs on
47+
EXPOSE 3000
48+
49+
ENV PORT=3000
50+
ENV HOSTNAME=0.0.0.0
51+
52+
# Run the app using JSON array notation
53+
CMD ["node", "server.js"]
54+
#CMD HOSTNAME="0.0.0.0" node server.js

next.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
output: 'standalone',
34
webpack: (config) => {
45
config.externals.push("@node-rs/argon2", "@node-rs/bcrypt");
56
return config;

0 commit comments

Comments
 (0)