2 Commits

Author SHA1 Message Date
ramvignesh-b d28903c611 refactor: move healthcheck configuration from docker-compose to Dockerfile
CI / build (pull_request) Successful in 1m19s
2026-05-12 01:21:27 +05:30
ramvignesh-b a4f3ea7837 refactor: replace REDIS_URL with individual host and port configuration variables 2026-05-12 01:05:27 +05:30
7 changed files with 22 additions and 18 deletions
+3 -4
View File
@@ -1,6 +1,5 @@
# Core Server Configuration
PORT=3000
APP_PORT=3000
API_KEY=your_secret_api_key_here
# Redis Configuration (Use redis://redis:6379 for Docker)
REDIS_URL=redis://localhost:6379
REDIS_HOST=redis
REDIS_PORT=6379
+3
View File
@@ -11,4 +11,7 @@ ENV NODE_ENV=production
USER bun
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD bun -e "fetch('http://localhost:3000/health').then(res => res.ok ? process.exit(0) : process.exit(1)).catch(e => process.exit(1))"
CMD ["bun", "run", "start"]
+5 -8
View File
@@ -3,22 +3,19 @@ services:
build: .
restart: always
ports:
- "${PORT:-3000}:3000"
- "${APP_PORT:-3000}:3000"
environment:
- REDIS_URL=redis://redis:6379
- REDIS_HOST=redis
- REDIS_PORT=6379
- API_KEY=${API_KEY}
depends_on:
- redis
healthcheck:
test: [ "CMD", "bun", "-e", "fetch('http://localhost:3000/health').then(res => res.ok ? process.exit(0) : process.exit(1)).catch(e => process.exit(1))" ]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
redis:
image: redis:alpine
restart: always
ports:
- "${REDIS_PORT:-6379}:6379"
volumes:
- redis-data:/data
+3 -2
View File
@@ -1,8 +1,9 @@
import { z } from "zod";
const configSchema = z.object({
PORT: z.string().default("3000"),
REDIS_URL: z.string(),
APP_PORT: z.string().default("3000"),
REDIS_HOST: z.string().default("redis"),
REDIS_PORT: z.coerce.number().default(6379),
API_KEY: z.string(),
});
+4 -1
View File
@@ -1,4 +1,7 @@
import { Redis } from "ioredis";
import { config } from "../config";
export const redis = new Redis(config.REDIS_URL);
export const redis = new Redis({
host: config.REDIS_HOST,
port: config.REDIS_PORT,
});
+1 -1
View File
@@ -74,6 +74,6 @@ app.get("/health", async (c) => {
export { app };
export default {
port: Number.parseInt(config.PORT, 10),
port: Number.parseInt(config.APP_PORT, 10),
fetch: app.fetch,
};
+3 -2
View File
@@ -2,8 +2,9 @@ import { mock } from "bun:test";
// Global test setup to stub environment variables
process.env.API_KEY = "test-api-key";
process.env.REDIS_URL = "redis://localhost:6379";
process.env.PORT = "3000";
process.env.REDIS_HOST = "localhost";
process.env.REDIS_PORT = "6379";
process.env.APP_PORT = "3000";
// Global Redis mock
mock.module("../src/core/RedisClient", () => ({