Repository navigation
Expand file tree
/
Copy pathcompose.yml
More file actions
127 lines (119 loc) · 5.4 KB
/
Copy pathcompose.yml
File metadata and controls
127 lines (119 loc) · 5.4 KB
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
name: wingsmith
# The plane, as processes something else supervises.
#
# api and hub are the same image with a different argument. They run here instead of in the
# background of a shell because a process nothing owns outlives the code it was built from:
# a migration lands, the running process keeps the old models in memory, and the endpoints touching
# the changed tables 500 while everything beside them stays green. Rebuilding is how you restart,
# so the two cannot drift apart.
#
# The console is left out intentionally. It wants a dev server with hot reload against a file tree,
# which is a worse thing inside a container than outside one: `just dev` runs it beside this.
# The image does bake a console bundle (see libs/plane/Dockerfile), but the source mount below
# shadows the directory it lands in, so the api here serves the API alone and 404s on `/`. That is
# the intended local shape: the dev server owns the console, and the deployed image owns both.
#
# The reactor runs inside the hub (WINGSMITH_REACTOR_ENABLED defaults on), so it has no service here.
#
# This is a local stack and nothing else. Every port is published on 127.0.0.1 only, the database
# password is `wingsmith`, and WINGSMITH_APP_ENV=local turns admin authentication off: anyone who can
# reach the api is an administrator. Do not publish these ports to a network, and do not deploy
# this file.
# One image, built once by `migrate` (which every other plane service waits for) and reused by
# name. Each service declaring its own `build` is the same image built three times.
x-plane-image: &plane-image
image: wingsmith-plane:local
x-plane: &plane
<<: *plane-image
pull_policy: never
# The source is mounted over what the image baked, so an edit is a reload instead of a rebuild.
# The image still owns the virtualenv at /opt/venv, which is why this is a mount of ./app and not
# of the whole context: shadowing the installed dependencies with a host directory that has none
# is how this trick usually breaks. A dependency change is still a rebuild.
# The contract table is mounted for the same reason the source is: it is data the plane reads at
# runtime and the contract is where it is edited. Baked in, a new device class means a rebuild
# before the local plane can place against it. The failure is quiet: an unknown class
# slugifies instead of erroring, so the fleet looks fine and the catalog is a generation behind.
volumes: &plane-source
- ./libs/plane/app:/app/app:ro
- ./libs/plane/migrations:/app/migrations:ro
- ./libs/packages/contract:/app/contract:ro
environment: &plane-env
WINGSMITH_DATABASE_URL: postgresql+psycopg://wingsmith:wingsmith@db:5442/wingsmith
# Overrides the image's baked-in `production`. This file is the local stack, and `local` is
# what makes the admin password and the session secret optional; see config/settings.py.
WINGSMITH_APP_ENV: local
# `local` binds loopback by default, which inside a container is unreachable. The ports below
# are published on the host's loopback only, so this does not put the API on the network.
WINGSMITH_API_HOST: 0.0.0.0
WINGSMITH_APP_LOG_FORMAT: console
depends_on:
db:
condition: service_healthy
migrate:
condition: service_completed_successfully
restart: unless-stopped
services:
db:
image: postgres:17-alpine
environment:
POSTGRES_USER: wingsmith
POSTGRES_PASSWORD: wingsmith
POSTGRES_DB: wingsmith
PGPORT: "5442"
ports:
- "127.0.0.1:5442:5442"
volumes:
- db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U wingsmith -d wingsmith -p 5442"]
interval: 5s
timeout: 5s
retries: 10
start_period: 10s
# Runs to completion before either process starts. That is why it is a service and not a
# step someone remembers. `service_completed_successfully` means a failed
# migration stops the stack instead of leaving an api to discover it one query at a time.
migrate:
<<: *plane-image
build:
context: ./libs
dockerfile: plane/Dockerfile
command: ["migrate", "upgrade", "head"]
# The same mounts as api and hub, and this is the service that most needs them. Without one,
# migrate only ever sees the revisions baked at image-build time: a migration written since is
# invisible to it, so the moment the database is stamped at a revision the image has never heard
# of (which happens the first time anyone runs `alembic upgrade` from the host), this
# job fails with `Can't locate revision` and takes api and hub down with it as a dependency.
volumes: *plane-source
environment:
<<: *plane-env
depends_on:
db:
condition: service_healthy
restart: "no"
api:
<<: *plane
command: ["api", "--reload"]
ports:
- "127.0.0.1:8000:8000"
healthcheck:
test:
- CMD
- python
- -c
- import urllib.request; urllib.request.urlopen("http://localhost:8000/health")
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
# No --reload: the hub holds long-lived operator sessions and there is nothing to reload into
# that would not drop them. `docker compose restart hub` picks up an edit, and choosing to drop a
# session is different from a file watcher doing it whenever a file is saved.
hub:
<<: *plane
command: ["hub"]
ports:
- "127.0.0.1:8001:8001"
volumes:
db_data: