Skip to content

Commit 1c0a8fe

Browse files
committed
update docker file to get smallest images and multi-staged build with non root
1 parent 7d74f97 commit 1c0a8fe

5 files changed

Lines changed: 104 additions & 28 deletions

File tree

.dockerignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Dependencies
2+
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Git and IDE
8+
.git
9+
.gitignore
10+
.github
11+
.husky
12+
.cursor
13+
.vscode
14+
.idea
15+
*.swp
16+
*.swo
17+
18+
# Tests and dev tooling
19+
tests
20+
coverage
21+
.nyc_output
22+
*.test.js
23+
*.spec.js
24+
jest.config.js
25+
.eslintrc
26+
.prettierrc
27+
.lintstagedrc.json
28+
29+
# Docs and local env (keep .env.example if app needs it at runtime; exclude if not)
30+
docs
31+
.env
32+
.env.local
33+
.env.*.local
34+
*.md
35+
!README.md
36+
37+
# Docker
38+
Dockerfile*
39+
docker-compose*
40+
.dockerignore
41+
42+
# Misc
43+
.DS_Store
44+
*.log

Dockerfile

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
# Use official Node.js LTS image
2-
FROM node:18-alpine
3-
4-
# Set working directory
5-
WORKDIR /usr/src/app
6-
7-
# Copy package.json and yarn.lock
1+
# syntax=docker/dockerfile:1
2+
# ---- Dependencies stage ----
3+
FROM node:22-alpine AS deps
4+
WORKDIR /app
85
COPY package.json yarn.lock ./
6+
RUN yarn install --frozen-lockfile --production
97

10-
# Install dependencies
11-
RUN yarn install --production
8+
# ---- Production image ----
9+
FROM node:22-alpine AS runner
10+
WORKDIR /app
1211

13-
# Copy the rest of the application code
12+
# Create non-root user with fixed UID for consistency
13+
RUN addgroup -g 1001 -S appgroup && \
14+
adduser -S appuser -u 1001 -G appgroup
15+
16+
# Copy production dependencies from deps stage
17+
COPY --from=deps /app/node_modules ./node_modules
18+
COPY --from=deps /app/package.json ./package.json
1419
COPY . .
1520

16-
# Expose the port the app runs on
17-
EXPOSE 5000
21+
# Ensure app files are readable by appuser (write not required at runtime)
22+
RUN chown -R appuser:appgroup /app
1823

19-
# Set environment variables
2024
ENV NODE_ENV=production
25+
EXPOSE 5000
26+
27+
USER appuser
28+
29+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
30+
CMD node -e "require('http').get('http://localhost:5000/', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
2131

22-
# Start the app
23-
CMD ["yarn", "start"]
32+
CMD ["node", "index.js"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@
5757
"**/tests/**/*.test.js"
5858
]
5959
}
60-
}
60+
}

public/css/style.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ body {
8585
border-radius: 12px;
8686
padding: 1.5rem;
8787
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
88-
transition: border-color 0.2s, box-shadow 0.2s;
88+
transition:
89+
border-color 0.2s,
90+
box-shadow 0.2s;
8991
}
9092

9193
.home__card:hover {
@@ -148,7 +150,10 @@ body {
148150
padding: 0.75rem 1.5rem;
149151
border-radius: 10px;
150152
text-decoration: none;
151-
transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
153+
transition:
154+
opacity 0.2s,
155+
transform 0.1s,
156+
box-shadow 0.2s;
152157
box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
153158
}
154159

@@ -241,4 +246,4 @@ body {
241246
.diverrormessage p {
242247
color: #475569;
243248
font-size: 0.95rem;
244-
}
249+
}

public/views/index.html

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
@@ -17,16 +17,26 @@
1717
<header class="home__header">
1818
<div class="home__logo">
1919
<span class="home__logo-icon"></span>
20-
<span class="home__logo-text">Clean Code Architecture backend - based on Uncle Bob's Clean Architecture concepts</span>
20+
<span class="home__logo-text"
21+
>Clean Code Architecture backend - based on Uncle Bob's Clean Architecture
22+
concepts</span
23+
>
2124
</div>
22-
<a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html" target="_blank" rel="noopener noreferrer" style="color:rgb(133, 133, 238); text-decoration:underline;">Uncle Bob's Clean Architecture</a>
23-
25+
<a
26+
href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html"
27+
target="_blank"
28+
rel="noopener noreferrer"
29+
style="color: rgb(133, 133, 238); text-decoration: underline"
30+
>Uncle Bob's Clean Architecture</a
31+
>
2432
</header>
2533

2634
<main class="home__main">
2735
<section class="home__hero">
28-
<h1 class="home__title"> RESTFul API</h1>
29-
<p class="home__tagline">Sell products with a Node.js backend built on Clean Architecture</p>
36+
<h1 class="home__title">RESTFul API</h1>
37+
<p class="home__tagline">
38+
Sell products with a Node.js backend built on Clean Architecture
39+
</p>
3040
</section>
3141

3242
<section class="home__cards">
@@ -44,8 +54,14 @@ <h2>Objective</h2>
4454
<section class="home__card home__features">
4555
<h2>What this API provides</h2>
4656
<ul class="home__feature-list">
47-
<li><strong>Auth</strong> — Register, login, logout, refresh token, forgot/reset password</li>
48-
<li><strong>Users</strong> — Profile, list users (admin), get/update/delete user, block/unblock</li>
57+
<li>
58+
<strong>Auth</strong> — Register, login, logout, refresh token, forgot/reset
59+
password
60+
</li>
61+
<li>
62+
<strong>Users</strong> — Profile, list users (admin), get/update/delete user,
63+
block/unblock
64+
</li>
4965
<li><strong>Products</strong> — Full CRUD, list, get by ID, rate products</li>
5066
<li><strong>Blogs</strong> — Full CRUD, list, get by ID</li>
5167
</ul>
@@ -71,7 +87,9 @@ <h3>Developer</h3>
7187
<p class="home__developer-contact">
7288
<a href="mailto:bricefrkc@gmail.com">bricefrkc@gmail.com</a>
7389
<span class="home__developer-sep">·</span>
74-
<a href="https://maebrieporfolio.vercel.app" target="_blank" rel="noopener noreferrer">Portfolio</a>
90+
<a href="https://maebrieporfolio.vercel.app" target="_blank" rel="noopener noreferrer"
91+
>Portfolio</a
92+
>
7593
</p>
7694
<p class="home__developer-meta">Created Jun 12, 2024 · Updated Feb 9, 2026</p>
7795
</section>

0 commit comments

Comments
 (0)