Skip to content

Commit d2b0c61

Browse files
committed
feat (deployment): containerizing frontend
1 parent 03250a6 commit d2b0c61

6 files changed

Lines changed: 81 additions & 8 deletions

File tree

.github/workflows/deploy-dev.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,4 @@ jobs:
3737
docker compose down
3838
3939
# Build new images if the Dockerfile has changed, and start the new containers in the background.
40-
docker compose up --build -d
41-
42-
# Optional: This cleans up any old, unused Docker images to save disk space.
43-
docker image prune -af
40+
docker compose up --build -d

.github/workflows/deploy-stag.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,4 @@ jobs:
3737
docker-compose down
3838
3939
# Build new images if the Dockerfile has changed, and start the new containers in the background.
40-
docker-compose up --build -d
41-
42-
# Optional: This cleans up any old, unused Docker images to save disk space.
43-
docker image prune -af
40+
docker-compose up --build -d

src/client/.dockerignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# src/client/.dockerignore
2+
3+
# Git
4+
.git
5+
.gitignore
6+
7+
# Docker
8+
Dockerfile
9+
.dockerignore
10+
docker-compose.yml
11+
12+
# Node
13+
node_modules
14+
npm-debug.log
15+
16+
# Next.js build artifacts
17+
.next
18+
out
19+
20+
# Environment files (these should be passed in at runtime)
21+
.env
22+
.env.local
23+
.env.template

src/client/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# src/client/Dockerfile
2+
3+
# 1. Builder Stage: Installs dependencies and builds the app
4+
FROM node:20-slim AS builder
5+
WORKDIR /app
6+
7+
# Copy package.json and lock file to leverage Docker cache
8+
COPY package.json ./
9+
RUN npm install
10+
11+
# Copy the rest of the application source code
12+
COPY . .
13+
14+
# Build the Next.js application for production
15+
# This creates the .next/standalone folder
16+
RUN npm run build
17+
18+
19+
# 2. Runner Stage: Creates the final, lightweight image
20+
FROM node:20-alpine AS runner
21+
WORKDIR /app
22+
23+
# Set the environment to production
24+
ENV NODE_ENV=production
25+
ENV PORT=3000
26+
27+
# Copy the standalone Next.js server from the builder stage
28+
COPY --from=builder /app/.next/standalone ./
29+
# Copy public assets and static build artifacts
30+
COPY --from=builder /app/public ./public
31+
COPY --from=builder /app/.next/static ./.next/static
32+
33+
# Expose the port the app will run on
34+
EXPOSE 3000
35+
36+
# The command to start the optimized Next.js server
37+
CMD ["node", "server.js"]

src/client/docker-compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# src/client/docker-compose.yml
2+
3+
services:
4+
sentient-client:
5+
# Build the image from the Dockerfile in the current directory
6+
build: .
7+
container_name: sentient-client
8+
# Always restart the container unless it is explicitly stopped
9+
restart: unless-stopped
10+
# Map port 80 on the VM to port 3000 inside the container
11+
ports:
12+
- "80:3000"
13+
# Load environment variables from a .env file in the same directory
14+
env_file:
15+
- .env

src/client/next.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ const nextConfig = {
55
}
66
}
77

8+
if (process.env.NODE_ENV === "production") {
9+
nextConfig.output = "standalone"
10+
}
11+
812
export default nextConfig

0 commit comments

Comments
 (0)