Skip to content

Commit 640d588

Browse files
Merge pull request #236 from profullstack/feat/dev2-site-email-queue
dev2-site: render the shared email-queue Redis + external networks
2 parents e899cdb + 1d286ed commit 640d588

3 files changed

Lines changed: 58 additions & 8 deletions

File tree

‎dev2/dev2-site‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,10 @@ def render_compose(s, st, app_port_inside, build_args=(), node_preset=()):
661661
y.append(" environment:")
662662
if heap and name not in node_preset: y.append(heap_line(heap, list_style=False))
663663
y.append(f" PORT: \"{port_inside}\"\n HOST: \"0.0.0.0\"\n NODE_ENV: production")
664+
if s.get("email_queue_redis"):
665+
# The shared @profullstack/email-queue Redis this stack hosts (quotas,
666+
# suppressions and the provider breaker for every sending app).
667+
y.append(" EMAIL_QUEUE_REDIS_URL: redis://email-queue-redis:6379")
664668
if command:
665669
# A nixpacks image's entrypoint is `/bin/bash -l -c`, and bash -c takes ONE script
666670
# argument: an argv list would run only the first word (Bun's help text, exit 0,
@@ -670,27 +674,58 @@ def render_compose(s, st, app_port_inside, build_args=(), node_preset=()):
670674
if vols:
671675
y.append(" volumes:")
672676
for v in vols: y.append(f" - ./volumes/{v['name']}:{v['mountPath']}")
673-
if s["redis"]:
674-
y.append(" depends_on:\n redis:\n condition: service_started")
677+
eq = s.get("email_queue_redis")
678+
deps = []
679+
if s["redis"]: deps.append(" redis:\n condition: service_started")
680+
if eq: deps.append(" email-queue-redis:\n condition: service_healthy")
681+
if deps: y.append(" depends_on:\n" + "\n".join(deps))
682+
nets = s.get("external_networks") or []
683+
if nets:
684+
y.append(" networks:\n - default")
685+
y.extend(f" - {n['name']}" for n in nets)
675686
y.append(" logging:\n driver: json-file\n options: { max-size: \"50m\", max-file: \"3\" }")
676687
service("app", "app.env", command=s.get("start_command"), vols=s["volumes"])
677688
for c in s["companions"]:
678689
# companion_ports {"name": {"host": 3301, "inside": 3000}} publishes a companion on
679690
# loopback so a `proxies` entry can give it its own hostname (an API the web app calls).
680691
cp = (s.get("companion_ports") or {}).get(c["name"])
681692
service(c["name"], f"{c['name']}.env", command=(s.get("companion_commands") or {}).get(c["name"]), ports=False, vols=c.get("volumes", []), port_inside=(cp or {}).get("inside"))
682-
if cp: y.insert(len(y) - (2 if s["redis"] else 1), f" ports:\n - \"127.0.0.1:{cp['host']}:{cp['inside']}\"")
693+
if cp:
694+
# Insert before what service() appends after ports: depends_on (own redis or
695+
# the email-queue redis), the networks list (header + one line each), logging.
696+
tail = 1 + (1 if (s["redis"] or s.get("email_queue_redis")) else 0)
697+
nets = s.get("external_networks") or []
698+
if nets: tail += 1 + len(nets)
699+
y.insert(len(y) - tail, f" ports:\n - \"127.0.0.1:{cp['host']}:{cp['inside']}\"")
683700
if s["redis"]:
684701
y.append(" redis:\n image: redis:8-alpine\n restart: unless-stopped\n" + mem_lines(mem_plan(s, "redis", is_redis=True, maxmemory="1gb")[0]) + "\n command: [\"redis-server\", \"--appendonly\", \"yes\", \"--maxmemory\", \"1gb\", \"--maxmemory-policy\", \"noeviction\"]\n volumes:\n - redisdata:/data\n logging:\n driver: json-file\n options: { max-size: \"20m\", max-file: \"2\" }")
685-
y.append("volumes:\n redisdata:")
702+
eq = s.get("email_queue_redis")
703+
if eq:
704+
# sites.d "email_queue_redis": {"host_port": 6395, "volume": "mynaposter-email-queue-data"}
705+
# The fleet's one @profullstack/email-queue Redis. Other sending apps reach it by
706+
# joining this stack's default network (their sites.d "external_networks").
707+
# AOF + RDB: suppressions and receipts must survive a restart.
708+
y.append(" email-queue-redis:\n image: redis:8-alpine\n restart: unless-stopped\n mem_limit: 256m\n"
709+
" command: [\"redis-server\", \"--appendonly\", \"yes\", \"--save\", \"60\", \"1\"]")
710+
if eq.get("host_port"): y.append(f" ports:\n - \"127.0.0.1:{int(eq['host_port'])}:6379\"")
711+
y.append(" volumes:\n - email-queue-data:/data\n healthcheck:\n test: [\"CMD\", \"redis-cli\", \"ping\"]\n"
712+
" interval: 5s\n timeout: 3s\n retries: 20")
713+
vols = []
714+
if s["redis"]: vols.append(" redisdata:")
715+
if eq: vols.append(f" email-queue-data:\n name: {eq.get('volume') or s['site'].replace('.', '-') + '-email-queue-data'}")
716+
if vols: y.append("volumes:\n" + "\n".join(vols))
686717
# An explicit subnet per site: Docker's default address pools (15 x /16 + 16 x /20)
687718
# ran out at 34 networks on dev2, and widening them means restarting dockerd
688719
# under every container. 10.200.<port-3200>.0/24 is deterministic and allowlisted
689720
# on the data ports.
690721
# `subnet_octet` in sites.d moves a site off a /24 another stack already holds
691722
# (bittorrented.com was hand-built on c0ncerts.com's 10.200.78.0/24).
692723
n = s.get("subnet_octet", s["port"] - FIRST_PORT)
693-
y.append(f"networks:\n default:\n ipam:\n config:\n - subnet: 10.200.{n}.0/24")
724+
nets = s.get("external_networks") or []
725+
# sites.d "external_networks": [{"name": "emailqueue", "network": "mynapostercom_default"}]
726+
# joins another stack's network, e.g. to reach the shared email-queue-redis.
727+
ext = "".join(f" {e['name']}:\n external: true\n name: {e['network']}\n" for e in nets)
728+
y.append(f"networks:\n{ext} default:\n ipam:\n config:\n - subnet: 10.200.{n}.0/24")
694729
# Healthchecks chosen by `dev2-site healthchecks` survive a re-render.
695730
return health_compose("\n".join(y) + "\n", st.get("healthchecks") or {})
696731

‎dev2/sites.d/mynaposter.com.json‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,9 @@
2828
"companion_commands": {
2929
"mynaposter-api": "bun apps/api/src/server.ts"
3030
},
31-
"node_version": "22"
32-
}
31+
"node_version": "22",
32+
"email_queue_redis": {
33+
"host_port": 6395,
34+
"volume": "mynaposter-email-queue-data"
35+
}
36+
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
{ "env_remove": ["TURSO_AUTH_TOKEN"], "notes": "Turso -> shared Postgres 2026-09-25 (profullstack/outreachgraph#99); TURSO_DATABASE_URL is rewritten to the cluster URL by provision (the app reads DATABASE_URL first, that name as a fallback)" }
1+
{
2+
"env_remove": [
3+
"TURSO_AUTH_TOKEN"
4+
],
5+
"notes": "Turso -> shared Postgres 2026-09-25 (profullstack/outreachgraph#99); TURSO_DATABASE_URL is rewritten to the cluster URL by provision (the app reads DATABASE_URL first, that name as a fallback)",
6+
"external_networks": [
7+
{
8+
"name": "emailqueue",
9+
"network": "mynapostercom_default"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)