run-stack 0.6.4

One command to boot a full local stack in Docker: API, Vite apps, Expo mobile, desktop renderer, database, mail and a status dashboard.
Documentation
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
name: ${COMPOSE_PROJECT_NAME:-myapp}

# The per-package node_modules volumes live in the generated
# docker-compose.packages.yml: they depend on what the frontend monorepo
# actually contains, so ./run.sh regenerates that file on every up/rebuild.
# Named volumes shadow every node_modules path inside the bind-mounted
# monorepo, so the host's macOS-built dependencies never leak into the
# Linux containers (and vice versa).
x-frontend-volumes: &frontend-volumes
  - ${FRONTEND_DIR:-../frontend}:/app
  # Mounted so entrypoint edits take effect on restart, without a rebuild.
  - ./docker/frontend/entrypoint.sh:/usr/local/bin/entrypoint.sh:ro
  - ./docker/frontend/mobile-stack.sh:/usr/local/bin/mobile-stack.sh:ro
  - pnpm_store:/pnpm-store
  - fe_nm_root:/app/node_modules

x-frontend-env: &frontend-env
  NODE_ENV: development
  CHOKIDAR_USEPOLLING: "true"
  WATCHPACK_POLLING: "true"
  METRO_DISABLE_WATCHMAN: "1"
  METRO_POKE: ${METRO_POKE:-true}
  METRO_POKE_INTERVAL: ${METRO_POKE_INTERVAL:-1}
  METRO_POKE_SETTLE: ${METRO_POKE_SETTLE:-1}
  WEB_APP: ${WEB_APP:-web}
  ADMIN_APP: ${ADMIN_APP:-admin}
  LANDING_APP: ${LANDING_APP:-landing}
  DESKTOP_APP: ${DESKTOP_APP:-desktop}
  MOBILE_APP: ${MOBILE_APP:-mobile-client}
  RUN_DESKTOP: ${RUN_DESKTOP:-false}
  MOBILE_WATCH_PACKAGES: ${MOBILE_WATCH_PACKAGES:-}
  EXTRA_DEPS_APPS: ${EXTRA_DEPS_APPS:-}
  RUN_ADMIN: ${RUN_ADMIN:-true}
  RUN_LANDING: ${RUN_LANDING:-true}
  VITE_API_BASE_URL: ${VITE_API_BASE_URL:-http://localhost:8000/api}
  VITE_WEB_APP_URL: ${VITE_WEB_APP_URL:-http://localhost:5173}
  # A dev server proxying /api to localhost reaches its own container, not the
  # API — the page loads and every request fails. The API is on the compose
  # network under its service name, so hand that URL over under the names a
  # vite.config is likely to read. VITE_API_BASE_URL above stays on localhost
  # on purpose: that one is resolved by the browser, this one by the proxy.
  API_PROXY: http://backend:${BACKEND_CONTAINER_PORT:-8000}
  API_PROXY_TARGET: http://backend:${BACKEND_CONTAINER_PORT:-8000}
  VITE_API_PROXY: http://backend:${BACKEND_CONTAINER_PORT:-8000}
  DEV_PROXY_TARGET: http://backend:${BACKEND_CONTAINER_PORT:-8000}
  # So a config with a "am I in a container?" branch takes it.
  DOCKER: "1"
  IN_DOCKER: "true"
  VITE_SENTRY_DSN: ${VITE_SENTRY_DSN:-}
  VITE_SENTRY_ENV: ${VITE_SENTRY_ENV:-local}

x-frontend-service: &frontend-service
  build:
    context: ./docker/frontend
  image: ${COMPOSE_PROJECT_NAME:-myapp}/frontend:local
  working_dir: /app
  environment: *frontend-env
  volumes: *frontend-volumes
  depends_on:
    frontend-deps:
      condition: service_completed_successfully
  restart: unless-stopped
  shm_size: ${DOCKER_SHM_SIZE:-64m}

x-backend-env: &backend-env
  # Generic — every stack gets these.
  # The port the API listens on inside its container, published as
  # BACKEND_PORT. Apps do not agree on what to call this, and one reading a
  # name we never set would silently bind its own default instead — leaving the
  # published port pointing at nothing. So set all the usual spellings rather
  # than guess which one this project picked. An app that hardcodes its port
  # and reads no variable at all still needs BACKEND_CONTAINER_PORT; the
  # backend logs the port it actually bound when that happens.
  PORT: ${BACKEND_CONTAINER_PORT:-8000}
  API_PORT: ${BACKEND_CONTAINER_PORT:-8000}
  APP_PORT: ${BACKEND_CONTAINER_PORT:-8000}
  HTTP_PORT: ${BACKEND_CONTAINER_PORT:-8000}
  SERVER_PORT: ${BACKEND_CONTAINER_PORT:-8000}
  NODE_ENV: ${NODE_ENV:-development}
  # DB_* below are derived from DB_ENGINE by run/scripts/common.sh.
  DATABASE_URL: ${DATABASE_URL:-postgresql://${DB_USERNAME:-myapp}:${DB_PASSWORD:-secret}@postgres:5432/${DB_DATABASE:-myapp}}
  REDIS_URL: redis://redis:6379
  S3_ENDPOINT: ${S3_ENDPOINT:-}
  S3_BUCKET: ${MINIO_BUCKET:-local}
  S3_ACCESS_KEY: ${MINIO_ROOT_USER:-minio}
  S3_SECRET_KEY: ${MINIO_ROOT_PASSWORD:-minio123}
  BACKEND_INSTALL_CMD: ${BACKEND_INSTALL_CMD:-}
  BACKEND_BUILD_CMD: ${BACKEND_BUILD_CMD:-}
  BACKEND_START_CMD: ${BACKEND_START_CMD:-}
  BACKEND_MIGRATE_CMD: ${BACKEND_MIGRATE_CMD:-}
  BACKEND_SEED_CMD: ${BACKEND_SEED_CMD:-}
  BACKEND_QUEUE_CMD: ${BACKEND_QUEUE_CMD:-}
  BACKEND_SCHEDULE_CMD: ${BACKEND_SCHEDULE_CMD:-}
  # Laravel.
  APP_ENV: ${APP_ENV:-local}
  APP_DEBUG: ${APP_DEBUG:-true}
  APP_URL: http://localhost:${BACKEND_PORT:-8000}
  # Passed under a different name on purpose: exporting an empty APP_KEY would
  # shadow the real key in .env, because Laravel's dotenv never overwrites a
  # variable that already exists in the environment.
  OVERRIDE_APP_KEY: ${APP_KEY:-}
  DB_CONNECTION: ${DB_CONNECTION:-pgsql}
  DB_HOST: ${DB_HOST:-postgres}
  DB_PORT: ${DB_INTERNAL_PORT:-5432}
  DB_DATABASE: ${DB_DATABASE:-myapp}
  DB_USERNAME: ${DB_USERNAME:-myapp}
  DB_PASSWORD: ${DB_PASSWORD:-secret}
  REDIS_CLIENT: phpredis
  REDIS_HOST: redis
  REDIS_PORT: 6379
  REDIS_PASSWORD: "null"
  CACHE_STORE: database
  SESSION_DRIVER: database
  QUEUE_CONNECTION: database
  MAIL_MAILER: smtp
  MAIL_HOST: mailpit
  MAIL_PORT: 1025
  MAIL_USERNAME: "null"
  MAIL_PASSWORD: "null"
  MAIL_SCHEME: "null"
  RUN_MIGRATIONS: ${RUN_MIGRATIONS:-true}
  RUN_SEEDERS: ${RUN_SEEDERS:-false}

# BACKEND_STACK picks the image: docker/backend/laravel or docker/backend/node.
x-backend-service: &backend-service
  build:
    context: ./docker/backend/${BACKEND_STACK:-laravel}
  image: ${COMPOSE_PROJECT_NAME:-myapp}/backend-${BACKEND_STACK:-laravel}:local
  # BACKEND_SUBDIR lets the API live inside a larger repo: the whole repo is
  # mounted (so workspace symlinks resolve) but commands run in the subdir.
  working_dir: /app/${BACKEND_SUBDIR:-}
  environment: *backend-env
  volumes:
    - ${BACKEND_DIR:-../backend}:/app
    # Mounted so entrypoint edits take effect on restart, without a rebuild.
    - ./docker/backend/${BACKEND_STACK:-laravel}/entrypoint.sh:/usr/local/bin/entrypoint.sh:ro
    - backend_state:/run-state
  # required: false so a stack that turns an engine off still starts.
  depends_on:
    postgres:
      condition: service_healthy
      required: false
    mysql:
      condition: service_healthy
      required: false
    redis:
      condition: service_started
      required: false
  restart: unless-stopped
  shm_size: ${DOCKER_SHM_SIZE:-64m}

services:
  # ---- Infrastructure -------------------------------------------------------
  # DB_ENGINE picks postgres, mysql or neither.
  postgres:
    profiles: ["postgres"]
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${DB_DATABASE:-myapp}
      POSTGRES_USER: ${DB_USERNAME:-myapp}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-secret}
    ports:
      - "${POSTGRES_PORT:-5434}:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-myapp} -d ${DB_DATABASE:-myapp}"]
      interval: 5s
      timeout: 5s
      retries: 20
    restart: unless-stopped
    shm_size: ${DOCKER_SHM_SIZE:-64m}

  mysql:
    profiles: ["mysql"]
    image: mysql:8
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-myapp}
      MYSQL_USER: ${DB_USERNAME:-myapp}
      MYSQL_PASSWORD: ${DB_PASSWORD:-secret}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-secret}
    ports:
      - "${MYSQL_PORT:-3307}:3306"
    volumes:
      - mysqldata:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u root -p${DB_ROOT_PASSWORD:-secret}"]
      interval: 5s
      timeout: 5s
      retries: 30
    restart: unless-stopped
    shm_size: ${DOCKER_SHM_SIZE:-64m}

  redis:
    profiles: ["redis"]
    image: redis:7-alpine
    ports:
      - "${REDIS_PORT:-6380}:6379"
    volumes:
      - redisdata:/data
    restart: unless-stopped

  # S3-compatible object storage, on with RUN_MINIO=true.
  minio:
    profiles: ["minio"]
    image: minio/minio:latest
    command: ["server", "/data", "--console-address", ":9001"]
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minio}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minio123}
    ports:
      - "${MINIO_PORT:-9000}:9000"
      - "${MINIO_CONSOLE_PORT:-9001}:9001"
    volumes:
      - miniodata:/data
    healthcheck:
      test: ["CMD-SHELL", "mc ready local || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 20
    restart: unless-stopped

  # ---- Status dashboard -----------------------------------------------------
  dashboard:
    build:
      context: ./docker/dashboard
    image: ${COMPOSE_PROJECT_NAME:-myapp}/dashboard:local
    environment:
      COMPOSE_PROJECT_NAME: ${COMPOSE_PROJECT_NAME:-myapp}
      PROJECT_LABEL: ${PROJECT_LABEL:-${COMPOSE_PROJECT_NAME:-myapp}}
      PORT: 8080
      BACKEND_PORT: ${BACKEND_PORT:-8000}
      BACKEND_CONTAINER_PORT: ${BACKEND_CONTAINER_PORT:-8000}
      BACKEND_HEALTH_PATH: ${BACKEND_HEALTH_PATH:-/api/health}
      BACKEND_LOGIN_PATH: ${BACKEND_LOGIN_PATH:-/api/auth/login}
      WEB_PORT: ${WEB_PORT:-5173}
      ADMIN_PORT: ${ADMIN_PORT:-5174}
      LANDING_PORT: ${LANDING_PORT:-5175}
      DESKTOP_PORT: ${DESKTOP_PORT:-5176}
      MOBILE_CLIENT_PORT: ${MOBILE_CLIENT_PORT:-8081}
      POSTGRES_PORT: ${POSTGRES_PORT:-5434}
      MYSQL_PORT: ${MYSQL_PORT:-3307}
      REDIS_PORT: ${REDIS_PORT:-6380}
      MAILPIT_UI_PORT: ${MAILPIT_UI_PORT:-8025}
      MINIO_PORT: ${MINIO_PORT:-9000}
      MINIO_CONSOLE_PORT: ${MINIO_CONSOLE_PORT:-9001}
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minio}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minio123}
      MINIO_BUCKET: ${MINIO_BUCKET:-local}
      HOST_OPEN_PORT: ${HOST_OPEN_PORT:-8091}
      EXTRA_SERVICES: ${EXTRA_SERVICES:-}
      COMPOSE_PROJECTS: ${COMPOSE_PROJECT_NAME:-myapp}
      DB_DATABASE: ${DB_DATABASE:-myapp}
      DB_USERNAME: ${DB_USERNAME:-myapp}
      DB_PASSWORD: ${DB_PASSWORD:-secret}
      BACKEND_STACK: ${BACKEND_STACK:-laravel}
      BACKEND_SUBDIR: ${BACKEND_SUBDIR:-}
      DB_ENGINE: ${DB_ENGINE:-postgres}
      DESKTOP_STACK: ${DESKTOP_STACK:-none}
      WEB_APP: ${WEB_APP:-web}
      ADMIN_APP: ${ADMIN_APP:-admin}
      LANDING_APP: ${LANDING_APP:-landing}
      DESKTOP_APP: ${DESKTOP_APP:-desktop}
      MOBILE_APP: ${MOBILE_APP:-mobile-client}
      RUN_ADMIN: ${RUN_ADMIN:-true}
      RUN_LANDING: ${RUN_LANDING:-true}
      RUN_DESKTOP: ${RUN_DESKTOP:-false}
      RUN_MOBILE: ${RUN_MOBILE:-auto}
      RUN_QUEUE: ${RUN_QUEUE:-true}
      RUN_SCHEDULER: ${RUN_SCHEDULER:-true}
      RUN_REDIS: ${RUN_REDIS:-true}
      RUN_MAILPIT: ${RUN_MAILPIT:-true}
      RUN_MINIO: ${RUN_MINIO:-false}
      DEPLOY_WEB_TARGET: ${DEPLOY_WEB_TARGET:-none}
      DEPLOY_MOBILE_TARGET: ${DEPLOY_MOBILE_TARGET:-none}
      DEPLOY_DESKTOP_TARGET: ${DEPLOY_DESKTOP_TARGET:-none}
      # Resolved from the target presets by run/scripts/common.sh.
      DEPLOY_WEB_CMD: ${DEPLOY_WEB_CMD:-}
      DEPLOY_MOBILE_CMD: ${DEPLOY_MOBILE_CMD:-}
      DEPLOY_DESKTOP_CMD: ${DEPLOY_DESKTOP_CMD:-}
      DEPLOY_DEFAULT_ENV: ${DEPLOY_DEFAULT_ENV:-staging}
      DEPLOY_ENVS: ${DEPLOY_ENVS:-staging production}
    volumes:
      # Container state for the cards, plus the restart / clear-cache / deploy
      # buttons, which exec inside the stack's own containers.
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./docker/dashboard:/srv
      # Optional: describes the seeded accounts shown in the credentials panel.
      - ./config:/config:ro
      # Read-only, so the credentials panel shows the same values the seeder
      # actually used instead of a hardcoded guess.
      - ${BACKEND_ENV_FILE:-${BACKEND_DIR:-../backend}/${BACKEND_SUBDIR:-}/.env}:/backend.env:ro
    extra_hosts:
      - "host.docker.internal:host-gateway"
    ports:
      - "${DASHBOARD_PORT:-8090}:8080"
    restart: unless-stopped

  mailpit:
    profiles: ["mailpit"]
    image: axllent/mailpit:latest
    ports:
      - "${MAILPIT_UI_PORT:-8025}:8025"
    restart: unless-stopped

  # ---- Backend (BACKEND_STACK: laravel | node) ------------------------------
  backend:
    <<: *backend-service
    command: ["serve"]
    ports:
      - "${BACKEND_PORT:-8000}:${BACKEND_CONTAINER_PORT:-8000}"

  # Off with RUN_QUEUE / RUN_SCHEDULER=false, for stacks with no workers.
  queue:
    <<: *backend-service
    profiles: ["queue"]
    command: ["queue"]

  scheduler:
    <<: *backend-service
    profiles: ["scheduler"]
    command: ["schedule"]

  # ---- Frontend (pnpm monorepo) ---------------------------------------------
  frontend-deps:
    build:
      context: ./docker/frontend
    image: ${COMPOSE_PROJECT_NAME:-myapp}/frontend:local
    working_dir: /app
    environment: *frontend-env
    volumes: *frontend-volumes
    command: ["deps"]
    restart: "no"

  frontend-packages:
    <<: *frontend-service
    command: ["watch"]

  # Reinstalls when a workspace manifest changes, so a dependency added on the
  # host lands in the node_modules volumes the containers actually read.
  frontend-sync:
    <<: *frontend-service
    command: ["sync"]

  web:
    <<: *frontend-service
    command: ["app", "web", "5173"]
    environment:
      <<: *frontend-env
      APP_CMD: ${WEB_CMD:-}
    ports:
      - "${WEB_PORT:-5173}:5173"

  # Opt out with RUN_ADMIN=false / RUN_LANDING=false in run/.env.
  admin:
    <<: *frontend-service
    profiles: ["admin"]
    command: ["app", "admin", "5174"]
    environment:
      <<: *frontend-env
      APP_CMD: ${ADMIN_CMD:-}
    ports:
      - "${ADMIN_PORT:-5174}:5174"

  landing:
    <<: *frontend-service
    profiles: ["landing"]
    command: ["app", "landing", "5175"]
    environment:
      <<: *frontend-env
      APP_CMD: ${LANDING_CMD:-}
    ports:
      - "${LANDING_PORT:-5175}:5175"

  # ---- Desktop renderer. The Electron / Tauri shell runs on the host. -------
  # On with RUN_DESKTOP=true; ./run.sh desktop launches the shell.
  desktop:
    <<: *frontend-service
    profiles: ["desktop"]
    command: ["app", "desktop", "5176"]
    environment:
      <<: *frontend-env
      APP_CMD: ${DESKTOP_CMD:-}
    ports:
      - "${DESKTOP_PORT:-5176}:5176"

  # ---- Mobile (Metro). Simulator / native builds still run on the host. ----
  # Opt out with RUN_MOBILE=false in run/.env (./run.sh scales these to zero).
  mobile-deps:
    build:
      context: ./docker/frontend
    image: ${COMPOSE_PROJECT_NAME:-myapp}/frontend:local
    working_dir: /app
    environment: *frontend-env
    volumes: *frontend-volumes
    command: ["deps-mobile"]
    depends_on:
      frontend-deps:
        condition: service_completed_successfully
    restart: "no"

  mobile-packages:
    <<: *frontend-service
    command: ["watch-mobile"]
    depends_on:
      frontend-deps:
        condition: service_completed_successfully
      mobile-deps:
        condition: service_completed_successfully

  mobile-client:
    <<: *frontend-service
    environment:
      <<: *frontend-env
      APP_CMD: ${MOBILE_CMD:-}
      MOBILE_STACK: ${MOBILE_STACK:-auto}
      EXPO_NO_TELEMETRY: "1"
      EXPO_DEVTOOLS_LISTEN_ADDRESS: 0.0.0.0
      REACT_NATIVE_PACKAGER_HOSTNAME: ${REACT_NATIVE_PACKAGER_HOSTNAME:-localhost}
      RCT_METRO_PORT: ${MOBILE_CLIENT_PORT:-8081}
      EXPO_PUBLIC_API_BASE_URL: ${EXPO_PUBLIC_API_BASE_URL:-http://localhost:8000/api}
    command: ["metro", "mobile"]
    ports:
      - "${MOBILE_CLIENT_PORT:-8081}:${MOBILE_CLIENT_PORT:-8081}"
    depends_on:
      frontend-deps:
        condition: service_completed_successfully
      mobile-deps:
        condition: service_completed_successfully

volumes:
  pgdata:
  mysqldata:
  miniodata:
  backend_state:
  redisdata:
  pnpm_store:
  fe_nm_root: