Skip to content

Commit 058626d

Browse files
committed
Refactor Dockerfile to use multi-stage builds for Hugo site and Nginx
1 parent 299d433 commit 058626d

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

Dockerfile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
# Use the official Nginx image from the Docker Hub
2-
FROM nginx:latest
1+
# Stage 1: Build the Hugo site
2+
FROM node:20 AS builder
33

4-
# Copy custom configuration file from the current directory
5-
# to the Nginx configuration directory
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy package files
8+
COPY package*.json ./
9+
10+
# Install dependencies
11+
RUN npm install
12+
13+
# Copy all project files
14+
COPY . .
15+
16+
# Clean and build the Hugo site
17+
RUN npm run clean && npm run build
18+
19+
# Stage 2: Serve with Nginx
20+
FROM nginx:alpine
21+
22+
# Copy custom Nginx configuration
623
COPY nginx.conf /etc/nginx/nginx.conf
724

8-
# Copy website files to the default Nginx public directory
9-
COPY public /usr/share/nginx/html
25+
# Copy built site from builder stage
26+
COPY --from=builder /app/public /usr/share/nginx/html
1027

11-
# Expose port 80 to the outside world
28+
# Expose port 80
1229
EXPOSE 80
1330

14-
# Start Nginx when the container has provisioned
31+
# Start Nginx
1532
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)