Spaces:
Running

File size: 5,879 Bytes
25834e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# beta.spoo.me — thin staging slice on the prod box (rung 3 of the edge
# cache rollout; design: thoughts/cf-edge-cache-v2.md).
#
# Runs as its OWN compose project so the prod deploy workflow never
# touches it, joining the existing prod network so Caddy can reach it:
#
#   docker compose -p spoo-beta -f docker-compose.beta.yml --env-file .env up -d
#
# Traffic path: CF edge (beta Worker route) → :443 → Caddy vhost
# beta.spoo.me → spoo_app_beta. Uses the same image tag as prod, a
# separate `url-shortener-beta` database on the same Atlas cluster, and
# its own cache/queue Redis pair — zero shared state with prod except
# the box and the Caddy process.
#
# Requires /opt/spoo/.env.beta with at minimum:
#   MONGODB_URI=...            # same cluster as prod
#   DB_NAME=url-shortener-beta
#   APP_URL=https://beta.spoo.me
#   REDIS_URI=redis://spoo_redis_beta:6379/0
#   CLICK_EVENTS_SINK=stream
#   CLICK_EVENTS_QUEUE_REDIS_URI=redis://spoo_redis_queue_beta:6379/0
#   CLICK_EVENTS_HOTNESS_ENABLED=true
#   EDGE_CACHE_CF_ACCOUNT_ID=...
#   EDGE_CACHE_CF_API_TOKEN=...      # KV-write scope
#   EDGE_CACHE_KV_NAMESPACE_ID=...   # beta namespace id from wrangler.jsonc
#   SECRET_KEY=... JWT_* etc.        # copy non-secret-critical bits from prod as needed

services:
  app-beta:
    image: ghcr.io/spoo-me/spoo:${IMAGE_TAG:-latest}
    container_name: spoo_app_beta
    restart: always
    command: >
      uv run uvicorn app.main:app
      --host 0.0.0.0
      --port 8000
      --workers 1
      --no-access-log
      --timeout-keep-alive 5
      --timeout-graceful-shutdown 30
    env_file:
      - .env.beta
    depends_on:
      redis-beta:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8000/health"]
      interval: 15s
      timeout: 5s
      retries: 3
      start_period: 30s
    mem_limit: 768m
    mem_reservation: 128m
    networks:
      spoonet:
        ipv4_address: 172.30.0.200
        # The public link surfaces tenant-scope by Host header, so the
        # frontend's server-side fetches must arrive AS beta.spoo.me —
        # docker DNS makes the URL's host produce the right Host header
        # (the backend strips the :8000). Nothing else on spoonet dials
        # this name; Caddy uses container names.
        aliases:
          - beta.spoo.me
    logging:
      driver: json-file
      options:
        max-size: "5m"
        max-file: "2"
        tag: "{{.Name}}"

  redis-beta:
    image: redis:7-alpine
    container_name: spoo_redis_beta
    restart: always
    command: >
      redis-server
      --maxmemory 64mb
      --maxmemory-policy allkeys-lru
      --save ""
      --appendonly no
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping | grep -q PONG"]
      interval: 10s
      timeout: 3s
      retries: 5
    mem_limit: 96m
    networks:
      spoonet:
        ipv4_address: 172.30.0.201
    logging:
      driver: json-file
      options:
        max-size: "5m"
        max-file: "2"
        tag: "{{.Name}}"

  redis-queue-beta:
    image: redis:8-alpine
    container_name: spoo_redis_queue_beta
    restart: always
    command: >
      redis-server
      --maxmemory 64mb
      --maxmemory-policy noeviction
      --appendonly yes
      --appendfsync everysec
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping | grep -q PONG"]
      interval: 10s
      timeout: 3s
      retries: 5
    mem_limit: 96m
    networks:
      spoonet:
        ipv4_address: 172.30.0.202
    logging:
      driver: json-file
      options:
        max-size: "5m"
        max-file: "2"
        tag: "{{.Name}}"

  click-worker-beta:
    image: ghcr.io/spoo-me/spoo:${IMAGE_TAG:-latest}
    container_name: spoo_click_worker_beta
    restart: always
    command: >
      uv run uvicorn --factory app.workers.click_worker:create_app
      --host 0.0.0.0 --port 8001
      --no-access-log
      --timeout-graceful-shutdown 30
    env_file:
      - .env.beta
    depends_on:
      redis-queue-beta:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:8001/health"]
      interval: 15s
      timeout: 5s
      retries: 3
      start_period: 20s
    mem_limit: 384m
    mem_reservation: 96m
    networks:
      spoonet:
        ipv4_address: 172.30.0.203
    logging:
      driver: json-file
      options:
        max-size: "5m"
        max-file: "2"
        tag: "{{.Name}}"

  # Next frontend slice — Caddy's beta @next matcher routes page paths
  # here; everything else (auth, api, short codes) still hits app-beta
  # directly. SPOO_API_URL points the container's SSR fetches and dormant
  # rewrites at the beta backend over docker DNS (never out via CF) —
  # via the beta.spoo.me network alias, NOT the container name: the
  # public link surfaces tenant-scope by Host, and undici won't let a
  # fetch override Host, so the URL's host has to be the tenant.
  next-beta:
    image: ghcr.io/spoo-me/frontend:${NEXT_IMAGE_TAG:-edge}
    container_name: spoo_next_beta
    restart: always
    environment:
      - SPOO_API_URL=http://beta.spoo.me:8000
    depends_on:
      app-beta:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-qO-", "--tries=1", "--timeout=3", "http://127.0.0.1:3000/api/health"]
      interval: 15s
      timeout: 5s
      retries: 3
      start_period: 20s
    mem_limit: 512m
    mem_reservation: 128m
    networks:
      spoonet:
        ipv4_address: 172.30.0.204
    logging:
      driver: json-file
      options:
        max-size: "5m"
        max-file: "2"
        tag: "{{.Name}}"

networks:
  spoonet:
    external: true
    name: spoo_spoonet