Skip to content

Commit 16bad02

Browse files
clean: remove production details and unnecessary comments from env files
- Clean up .env.example and .env files - Remove production-specific configurations and examples - Remove unnecessary comments and explanations - Keep only essential development environment variables - Focus on contributor-friendly setup This aligns with the open-source project focus on contributors
1 parent 4db14c9 commit 16bad02

File tree

6 files changed

+61
-76
lines changed

6 files changed

+61
-76
lines changed

.env.example

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# SafeExec - Secure Code Execution Platform
2-
# Copy this file to .env and configure for your environment
2+
# Copy this file to .env and configure for your local development
33

44
# ================================
55
# ENVIRONMENT CONFIGURATION
66
# ================================
7-
# Environment: development, test, production
87
ENV=development
9-
10-
# Node.js Environment
118
NODE_ENV=development
129

1310
# ================================
@@ -25,7 +22,7 @@ MONGO_USERNAME=admin
2522
MONGO_PASSWORD=devpassword
2623
MONGO_DB=safeexec_dev
2724
MONGO_PORT=27017
28-
MONGO_URI=mongodb://localhost:27017/safeexec_dev
25+
MONGODB_URI=mongodb://admin:devpassword@localhost:27017/safeexec_dev?authSource=admin
2926

3027
# ================================
3128
# REDIS CONFIGURATION
@@ -37,7 +34,6 @@ REDIS_URI=redis://localhost:6379
3734
# ================================
3835
# SECURITY CONFIGURATION
3936
# ================================
40-
# JWT Configuration (CHANGE IN PRODUCTION!)
4137
JWT_SECRET=dev-jwt-secret-change-in-production
4238
JWT_EXPIRES_IN=24h
4339

@@ -70,58 +66,6 @@ SWAGGER_UI_ENABLED=true
7066
# DOCKER CONFIGURATION
7167
# ================================
7268
DOCKER_HOST=/var/run/docker.sock
73-
BUILD_TARGET=development
74-
SUBNET=172.20.0.0/16
75-
76-
# Nginx Configuration
7769
NGINX_HTTP_PORT=80
7870
NGINX_HTTPS_PORT=443
79-
80-
# Health Check Configuration
81-
HEALTH_CHECK_INTERVAL=30s
82-
HEALTH_CHECK_TIMEOUT=10s
83-
84-
# Development Volume Mounts (for hot reload)
85-
DEV_VOLUME_MOUNT=.
86-
DEV_NODE_MODULES_MOUNT=/tmp/node_modules
87-
88-
# ================================
89-
# ENVIRONMENT-SPECIFIC EXAMPLES
90-
# ================================
91-
92-
# Development Environment
93-
# ENV=development
94-
# LOG_LEVEL=debug
95-
# SWAGGER_UI_ENABLED=true
96-
# BUILD_TARGET=development
97-
# HEALTH_CHECK_INTERVAL=10s
98-
# API_PORT=5000
99-
# MONGO_PORT=27017
100-
# REDIS_PORT=6379
101-
102-
# Test Environment
103-
# ENV=test
104-
# LOG_LEVEL=error
105-
# SWAGGER_UI_ENABLED=false
106-
# BUILD_TARGET=test
107-
# HEALTH_CHECK_INTERVAL=5s
108-
# API_PORT=5001
109-
# MONGO_PORT=27018
110-
# REDIS_PORT=6380
111-
# JWT_EXPIRES_IN=1h
112-
113-
# Production Environment
114-
# ENV=production
115-
# LOG_LEVEL=warn
116-
# SWAGGER_UI_ENABLED=false
117-
# BUILD_TARGET=production
118-
# HEALTH_CHECK_INTERVAL=30s
119-
# API_PORT=5000
120-
# MONGO_PORT=27017
121-
# REDIS_PORT=6379
122-
# REDIS_PASSWORD=secure_redis_password_change_me
123-
# MONGO_PASSWORD=secure_mongo_password_change_me
124-
# JWT_SECRET=super-secure-jwt-secret-change-me
125-
# ALLOWED_ORIGINS=https://yourdomain.com,https://www.yourdomain.com
126-
# DEV_VOLUME_MOUNT=/dev/null
127-
# DEV_NODE_MODULES_MOUNT=/dev/null
71+
WORKER_REPLICAS=1

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,26 @@ nano .env # or use your preferred editor
5959
**Sample .env for local development:**
6060

6161
```env
62+
# Environment
63+
ENV=development
6264
NODE_ENV=development
6365
PORT=5000
64-
MONGO_URI=mongodb://localhost:27017/rce_dev
65-
REDIS_HOST=localhost
66-
REDIS_PORT=6379
66+
67+
# MongoDB (use localhost for local development & MongoDB Compass)
68+
MONGO_USERNAME=admin
69+
MONGO_PASSWORD=devpassword
70+
MONGO_DB=safeexec_dev
71+
MONGODB_URI=mongodb://admin:devpassword@localhost:27017/safeexec_dev?authSource=admin
72+
73+
# Redis (use localhost for local development & Redis clients)
74+
REDIS_URI=redis://localhost:6379
75+
76+
# Security
6777
JWT_SECRET=your-super-secret-jwt-key-for-development
6878
JWT_EXPIRES_IN=24h
79+
80+
# CORS
81+
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001
6982
```
7083

7184
### 3. Quick Setup (Recommended for Contributors)

docker-compose.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
environment:
1616
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME:-admin}
1717
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-devpassword}
18-
MONGO_INITDB_DATABASE: ${MONGO_DB:-rce_system}
18+
MONGO_INITDB_DATABASE: ${MONGO_DB:-safeexec_dev}
1919
ports:
2020
# Auto-allocate ports if default is busy
2121
- '${MONGO_PORT:-27017}:27017'
@@ -69,15 +69,24 @@ services:
6969
- '${DEBUG_PORT:-9229}:9229'
7070
environment:
7171
NODE_ENV: ${ENV:-development}
72-
PORT: 5000
73-
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-devpassword}@mongodb:27017/${MONGO_DB:-rce_system}?authSource=admin
72+
PORT: ${PORT:-5000}
73+
MONGO_USERNAME: ${MONGO_USERNAME:-admin}
74+
MONGO_PASSWORD: ${MONGO_PASSWORD:-devpassword}
75+
MONGO_DB: ${MONGO_DB:-safeexec_dev}
76+
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-devpassword}@mongodb:27017/${MONGO_DB:-safeexec_dev}?authSource=admin
7477
REDIS_URI: redis://${REDIS_PASSWORD:+:${REDIS_PASSWORD}@}redis:6379
7578
JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-change-in-production}
7679
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-24h}
7780
DOCKER_HOST: /var/run/docker.sock
7881
LOG_LEVEL: ${LOG_LEVEL:-info}
7982
ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-http://localhost:3000}
8083
SWAGGER_UI_ENABLED: ${SWAGGER_UI_ENABLED:-true}
84+
MAX_SUBMISSIONS_PER_MINUTE: ${MAX_SUBMISSIONS_PER_MINUTE:-10}
85+
MAX_SUBMISSIONS_PER_HOUR: ${MAX_SUBMISSIONS_PER_HOUR:-100}
86+
MAX_SUBMISSIONS_PER_DAY: ${MAX_SUBMISSIONS_PER_DAY:-500}
87+
EXECUTOR_TIMEOUT_MS: ${EXECUTOR_TIMEOUT_MS:-30000}
88+
EXECUTOR_MEMORY_LIMIT_MB: ${EXECUTOR_MEMORY_LIMIT_MB:-128}
89+
EXECUTOR_CPU_LIMIT: ${EXECUTOR_CPU_LIMIT:-0.5}
8190
volumes:
8291
- /var/run/docker.sock:/var/run/docker.sock
8392
- app_logs:/app/logs
@@ -116,11 +125,17 @@ services:
116125
restart: unless-stopped
117126
environment:
118127
NODE_ENV: ${ENV:-development}
119-
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-devpassword}@mongodb:27017/${MONGO_DB:-rce_system}?authSource=admin
128+
MONGO_USERNAME: ${MONGO_USERNAME:-admin}
129+
MONGO_PASSWORD: ${MONGO_PASSWORD:-devpassword}
130+
MONGO_DB: ${MONGO_DB:-safeexec_dev}
131+
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-devpassword}@mongodb:27017/${MONGO_DB:-safeexec_dev}?authSource=admin
120132
REDIS_URI: redis://${REDIS_PASSWORD:+:${REDIS_PASSWORD}@}redis:6379
121133
JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-change-in-production}
122134
DOCKER_HOST: /var/run/docker.sock
123135
LOG_LEVEL: ${LOG_LEVEL:-info}
136+
EXECUTOR_TIMEOUT_MS: ${EXECUTOR_TIMEOUT_MS:-30000}
137+
EXECUTOR_MEMORY_LIMIT_MB: ${EXECUTOR_MEMORY_LIMIT_MB:-128}
138+
EXECUTOR_CPU_LIMIT: ${EXECUTOR_CPU_LIMIT:-0.5}
124139
volumes:
125140
- /var/run/docker.sock:/var/run/docker.sock
126141
- app_logs:/app/logs

src/config/env.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ configDotenv();
44

55
export const config = {
66
port: process.env.PORT || 5000,
7-
mongoUri: process.env.MONGO_URI || 'mongodb://localhost:27017/rce',
8-
redisHost: process.env.REDIS_HOST || 'localhost',
9-
redisPort: Number(process.env.REDIS_PORT) || 6379,
7+
mongoUri: process.env.MONGODB_URI || 'mongodb://localhost:27017/rce',
8+
redisUri: process.env.REDIS_URI || 'redis://localhost:6379',
109
};

src/queue/queue.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
// src/queue/queue.ts
22
import { Queue } from 'bullmq';
3-
import { config } from '../config/env';
3+
import { environmentConfig } from '../config/environment';
4+
5+
const config = environmentConfig.getConfig();
46

57
export const submissionQueue = new Queue('submission', {
68
connection: {
7-
host: config.redisHost,
8-
port: config.redisPort,
9+
host: config.redis.uri.includes('://')
10+
? new URL(config.redis.uri).hostname
11+
: config.redis.uri.split(':')[0],
12+
port: config.redis.uri.includes('://')
13+
? parseInt(new URL(config.redis.uri).port) || 6379
14+
: parseInt(config.redis.uri.split(':')[1]) || 6379,
15+
...(config.redis.password && { password: config.redis.password }),
916
},
1017
});

src/queue/worker.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// src/queue/worker.ts
22
import { Worker } from 'bullmq';
3-
import { config } from '../config/env';
3+
import { environmentConfig } from '../config/environment';
44
import { SubmissionModel } from '../models/submission.model';
55
import { executeInDocker } from '../executors/dockerExecutor';
66

7+
const config = environmentConfig.getConfig();
8+
79
// eslint-disable-next-line @typescript-eslint/no-unused-vars
810
const worker = new Worker(
911
'submission',
@@ -17,7 +19,7 @@ const worker = new Worker(
1719
_id: submission._id.toString(),
1820
code: submission.code,
1921
language: submission.language,
20-
timeLimitMs: 10000,
22+
timeLimitMs: config.executor.timeoutMs,
2123
save: async () => {
2224
await submission.save();
2325
},
@@ -27,8 +29,13 @@ const worker = new Worker(
2729
},
2830
{
2931
connection: {
30-
host: config.redisHost,
31-
port: config.redisPort,
32+
host: config.redis.uri.includes('://')
33+
? new URL(config.redis.uri).hostname
34+
: config.redis.uri.split(':')[0],
35+
port: config.redis.uri.includes('://')
36+
? parseInt(new URL(config.redis.uri).port) || 6379
37+
: parseInt(config.redis.uri.split(':')[1]) || 6379,
38+
...(config.redis.password && { password: config.redis.password }),
3239
},
3340
}
3441
);

0 commit comments

Comments
 (0)