Skip to content

Commit a991333

Browse files
mguptahubPlane AI
andauthored
Add environment variable support for cache engine configuration (#2)
Extends config.loader.js to apply IFRAMELY_* env vars as a final override layer on top of file-based config, enabling container deployments to configure the cache engine and Redis connection without mounting a config.local.js file. Supported variables: IFRAMELY_CACHE_ENGINE redis | node-cache | memcached | no-cache IFRAMELY_CACHE_TTL cache TTL in seconds IFRAMELY_REDIS_HOST Redis hostname or IP IFRAMELY_REDIS_PORT Redis port IFRAMELY_REDIS_PASSWORD Redis auth password IFRAMELY_REDIS_TLS true to enable TLS socket IFRAMELY_REDIS_MODE standard | cluster Redis connection options are only applied when the effective cache engine resolves to redis (from env var or file config), preventing accidental REDIS_OPTIONS injection when a different engine is in use. Also updates docker-compose.yml with a Redis service for local testing, with a healthcheck and depends_on so iframely only starts once Redis is ready. Co-authored-by: Plane AI <noreply@plane.so>
1 parent 4d294b6 commit a991333

2 files changed

Lines changed: 111 additions & 3 deletions

File tree

config.loader.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,84 @@ import iframelyConfig from './config.js';
22
// Load global config from exec dir, because `iframely` can be used as library.
33
var globalConfig = await import(process.cwd() + '/config.js');
44
globalConfig = globalConfig && globalConfig.default;
5-
export default {...iframelyConfig, ...globalConfig};
5+
6+
// ---------------------------------------------------------------------------
7+
// Environment variable overrides (Plane fork extension).
8+
//
9+
// These are applied as a final layer on top of config.js + config.local.js so
10+
// that container deployments can configure iframely without baking secrets into
11+
// a mounted JS file.
12+
//
13+
// Supported variables (all prefixed IFRAMELY_):
14+
//
15+
// Cache engine
16+
// IFRAMELY_CACHE_ENGINE redis | node-cache | memcached | no-cache
17+
// IFRAMELY_CACHE_TTL seconds (integer)
18+
//
19+
// Redis (standard mode, used when IFRAMELY_CACHE_ENGINE=redis)
20+
// IFRAMELY_REDIS_HOST hostname or IP (default: 127.0.0.1)
21+
// IFRAMELY_REDIS_PORT port number (default: 6379)
22+
// IFRAMELY_REDIS_PASSWORD password (optional)
23+
// IFRAMELY_REDIS_TLS true | false (enables TLS socket)
24+
// IFRAMELY_REDIS_MODE standard | cluster (default: standard)
25+
// ---------------------------------------------------------------------------
26+
27+
var envOverrides = {};
28+
29+
// --- Cache engine ---
30+
if (process.env.IFRAMELY_CACHE_ENGINE) {
31+
envOverrides.CACHE_ENGINE = process.env.IFRAMELY_CACHE_ENGINE;
32+
}
33+
34+
if (process.env.IFRAMELY_CACHE_TTL) {
35+
var ttl = parseInt(process.env.IFRAMELY_CACHE_TTL, 10);
36+
if (!isNaN(ttl)) {
37+
envOverrides.CACHE_TTL = ttl;
38+
}
39+
}
40+
41+
// --- Redis mode ---
42+
if (process.env.IFRAMELY_REDIS_MODE) {
43+
envOverrides.REDIS_MODE = process.env.IFRAMELY_REDIS_MODE;
44+
}
45+
46+
// --- Redis connection options ---
47+
// Resolve the effective cache engine (env var wins over file-based config).
48+
var base = {...iframelyConfig, ...globalConfig};
49+
var effectiveEngine = process.env.IFRAMELY_CACHE_ENGINE || base.CACHE_ENGINE;
50+
51+
if (effectiveEngine === 'redis' && (
52+
process.env.IFRAMELY_REDIS_HOST ||
53+
process.env.IFRAMELY_REDIS_PORT ||
54+
process.env.IFRAMELY_REDIS_PASSWORD ||
55+
process.env.IFRAMELY_REDIS_TLS)) {
56+
var existingOptions = base.REDIS_OPTIONS || {};
57+
var existingSocket = existingOptions.socket || {};
58+
59+
var socketOverrides = {};
60+
if (process.env.IFRAMELY_REDIS_HOST) {
61+
socketOverrides.host = process.env.IFRAMELY_REDIS_HOST;
62+
}
63+
if (process.env.IFRAMELY_REDIS_PORT) {
64+
var port = parseInt(process.env.IFRAMELY_REDIS_PORT, 10);
65+
if (!isNaN(port)) {
66+
socketOverrides.port = port;
67+
}
68+
}
69+
if (process.env.IFRAMELY_REDIS_TLS === 'true') {
70+
socketOverrides.tls = true;
71+
}
72+
73+
var redisOptions = {
74+
...existingOptions,
75+
socket: { ...existingSocket, ...socketOverrides },
76+
};
77+
78+
if (process.env.IFRAMELY_REDIS_PASSWORD) {
79+
redisOptions.password = process.env.IFRAMELY_REDIS_PASSWORD;
80+
}
81+
82+
envOverrides.REDIS_OPTIONS = redisOptions;
83+
}
84+
85+
export default {...iframelyConfig, ...globalConfig, ...envOverrides};

docker-compose.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
version: "3"
22
services:
3-
api:
3+
iframely:
44
build:
55
context: .
66
dockerfile: Dockerfile
7-
container_name: iframely
7+
container_name: iframely
88
restart: always
99
ports:
1010
- "8061:8061"
11+
environment:
12+
IFRAMELY_CACHE_ENGINE: redis
13+
IFRAMELY_CACHE_TTL: "86400"
14+
IFRAMELY_REDIS_HOST: redis
15+
IFRAMELY_REDIS_PORT: "6379"
16+
# IFRAMELY_REDIS_PASSWORD: ""
17+
# IFRAMELY_REDIS_TLS: "false"
18+
# IFRAMELY_REDIS_MODE: standard
19+
depends_on:
20+
redis:
21+
condition: service_healthy
22+
23+
redis:
24+
image: redis:7-alpine
25+
container_name: iframely-redis
26+
restart: always
27+
# ports:
28+
# - "6379:6379"
29+
volumes:
30+
- redis-data:/data
31+
healthcheck:
32+
test: ["CMD", "redis-cli", "ping"]
33+
interval: 5s
34+
timeout: 3s
35+
retries: 5
36+
37+
volumes:
38+
redis-data:

0 commit comments

Comments
 (0)