Skip to content

Commit 65e9f20

Browse files
committed
fix: enhance Docker and application configuration with health check, improved ignore files, and updated package details
1 parent bdfa469 commit 65e9f20

File tree

6 files changed

+94
-104
lines changed

6 files changed

+94
-104
lines changed

.dockerignore

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
1+
# Dependencies
12
node_modules
2-
npm-debug.log
3+
4+
# Git
35
.git
46
.gitignore
7+
8+
# Environment
59
.env
610
.env.*
7-
*.md
11+
!.env.example
12+
13+
# IDE
814
.vscode
915
.idea
10-
.DS_Store
16+
*.swp
17+
*.swo
18+
19+
# Logs
1120
*.log
21+
npm-debug.log*
22+
23+
# Testing & Coverage
1224
coverage
1325
.nyc_output
26+
27+
# Documentation
28+
*.md
29+
!README.md
30+
31+
# OS
32+
.DS_Store
33+
Thumbs.db
34+
35+
# Build artifacts
36+
build
37+
dist
38+
39+
# Docker (don't copy docker files into image)
40+
Dockerfile
41+
docker-compose*.yml
42+
.dockerignore
43+
44+
# Dev tools
45+
.eslintrc*
46+
.editorconfig
47+
.github

.gitignore

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,41 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Environment
5+
.env
6+
.env.local
7+
.env.*.local
8+
19
# Logs
2-
logs
10+
logs/
311
*.log
412
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
713

8-
# Runtime data
9-
pids
14+
# Runtime
15+
pids/
1016
*.pid
11-
*.seed
1217
*.pid.lock
1318

14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
16-
17-
# Coverage directory used by tools like istanbul
18-
coverage
19+
# Coverage
20+
coverage/
21+
.nyc_output/
1922

20-
# nyc test coverage
21-
.nyc_output
23+
# Build
24+
build/
25+
dist/
2226

23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
29-
# node-waf configuration
30-
.lock-wscript
31-
32-
# Compiled binary addons (https://nodejs.org/api/addons.html)
33-
build/Release
34-
35-
# Dependency directories
36-
node_modules/
37-
jspm_packages/
27+
# IDE
28+
.idea/
29+
.vscode/
30+
*.swp
31+
*.swo
32+
*~
3833

39-
# TypeScript v1 declaration files
40-
typings/
41-
42-
# Optional npm cache directory
43-
.npm
44-
45-
# Optional eslint cache
46-
.eslintcache
47-
48-
# Optional REPL history
49-
.node_repl_history
50-
51-
# Output of 'npm pack'
52-
*.tgz
53-
54-
# Yarn Integrity file
55-
.yarn-integrity
56-
57-
# dotenv environment variables file
58-
.env
59-
60-
# next.js build output
61-
.next
34+
# OS
35+
.DS_Store
36+
Thumbs.db
6237

38+
# Project specific
6339
assets/fonts/*
6440
assets/emojis/*
65-
6641
!.gitkeep

Dockerfile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1818
pkg-config \
1919
&& rm -rf /var/lib/apt/lists/*
2020

21-
# Copy package files
2221
COPY package*.json ./
2322

24-
# Install all dependencies (including dev for native compilation)
25-
RUN npm ci
23+
RUN npm ci --omit=dev
2624

2725
# Production stage
2826
FROM node:22-bookworm-slim
2927

3028
WORKDIR /app
3129

32-
# Install runtime dependencies only
30+
ENV NODE_ENV=production
31+
32+
# Install runtime dependencies and fonts
3333
RUN apt-get update && apt-get install -y --no-install-recommends \
3434
fonts-noto \
3535
fonts-noto-cjk \
@@ -43,21 +43,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
4343
librsvg2-2 \
4444
libpixman-1-0 \
4545
libvips42 \
46+
curl \
4647
&& rm -rf /var/lib/apt/lists/* \
4748
&& fc-cache -f -v
4849

50+
# Create non-root user first
51+
RUN groupadd -r nodejs && useradd -r -g nodejs nodejs
52+
4953
# Copy node_modules from builder
5054
COPY --from=builder /app/node_modules ./node_modules
5155

5256
# Copy application code
53-
COPY . .
54-
55-
# Create non-root user
56-
RUN groupadd -r nodejs && useradd -r -g nodejs nodejs \
57-
&& chown -R nodejs:nodejs /app
57+
COPY --chown=nodejs:nodejs . .
5858

5959
USER nodejs
6060

6161
EXPOSE 3000
6262

63+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
64+
CMD curl -f http://localhost:3000/health || exit 1
65+
6366
CMD ["node", "index.js"]

app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const route = new Router()
4545

4646
const routes = require('./routes')
4747

48+
// Health check endpoint for Docker/Coolify
49+
route.get('/health', (ctx) => {
50+
ctx.status = 200
51+
ctx.body = { status: 'ok', timestamp: Date.now() }
52+
})
53+
4854
route.use('/*', routes.routeApi.routes())
4955

5056
app.use(route.routes())

docker-compose.yml

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,13 @@
1+
# Local development only - Coolify ignores this file
12
services:
23
quote-api:
3-
build:
4-
context: .
4+
build: .
5+
ports:
6+
- "3000:3000"
57
env_file: .env
6-
deploy:
7-
replicas: 3
8-
resources:
9-
limits:
10-
memory: 512M
11-
reservations:
12-
memory: 256M
13-
environment:
14-
- NODE_ENV=production
8+
restart: unless-stopped
159
healthcheck:
16-
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
10+
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
1711
interval: 30s
1812
timeout: 10s
1913
retries: 3
20-
start_period: 10s
21-
restart: unless-stopped
22-
logging:
23-
driver: "json-file"
24-
options:
25-
max-size: "10m"
26-
max-file: "3"
27-
networks:
28-
- quotly
29-
30-
nginx:
31-
image: nginx:alpine
32-
ports:
33-
- "127.0.0.1:4888:80"
34-
volumes:
35-
- ./nginx.conf:/etc/nginx/nginx.conf:ro
36-
depends_on:
37-
- quote-api
38-
restart: unless-stopped
39-
networks:
40-
- quotly
41-
42-
networks:
43-
quotly:
44-
external: true

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
22
"name": "quote-api",
33
"version": "0.14.0",
4-
"description": "",
4+
"description": "Quote image generation API",
55
"main": "index.js",
6+
"engines": {
7+
"node": ">=22.0.0"
8+
},
69
"scripts": {
710
"start": "node index.js",
8-
"lint": "node_modules/.bin/eslint --ext js .",
9-
"lint:fix": "node_modules/.bin/eslint --fix --ext js ."
11+
"lint": "eslint --ext js .",
12+
"lint:fix": "eslint --fix --ext js ."
1013
},
1114
"repository": {
1215
"type": "git",

0 commit comments

Comments
 (0)