-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_stack.ctst
More file actions
66 lines (59 loc) · 1.86 KB
/
full_stack.ctst
File metadata and controls
66 lines (59 loc) · 1.86 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
// Full-stack application: API + PostgreSQL + Redis + background worker.
// Demonstrates IMPORT, FROM, CONNECT, env, variable interpolation,
// secrets, volumes, and healthcheck.
// Run with: ctst run examples/full_stack.ctst
IMPORT "templates/postgres.ctst" AS pg
IMPORT "templates/redis.ctst" AS redis_tmpl
COMPONENT api {
image = "file:///opt/images/myapp-api"
port = 8080
memory = "256MiB"
cpu = "1024"
env = {
RUST_LOG = "${env.RUST_LOG}"
DATABASE_URL = "postgres://${db.host}:${db.port}/myapp"
REDIS_URL = "redis://${cache.host}:${cache.port}/0"
JWT_SECRET = "${secret.jwt_key}"
}
command = ["./api-server", "--bind", "0.0.0.0:8080"]
readonly = true
restart = "on-failure"
healthcheck = {
command = ["curl", "-f", "http://localhost:8080/healthz"]
interval = "10s"
timeout = "3s"
retries = 5
start_period = "15s"
}
}
COMPONENT db FROM pg {
memory = "1GiB"
volume = "/data/myapp-pg:/var/lib/postgresql/data"
env = {
POSTGRES_DB = "myapp"
POSTGRES_USER = "myapp_user"
POSTGRES_PASSWORD = "${secret.db_password}"
}
}
COMPONENT cache FROM redis_tmpl {
memory = "256MiB"
command = ["redis-server", "--maxmemory", "200mb", "--maxmemory-policy", "allkeys-lru"]
}
COMPONENT worker {
image = "file:///opt/images/myapp-worker"
memory = "128MiB"
cpu = "512"
env = {
DATABASE_URL = "postgres://${db.host}:${db.port}/myapp"
REDIS_URL = "redis://${cache.host}:${cache.port}/0"
WORKER_QUEUE = "default,email,reports"
}
command = ["./worker", "--concurrency", "4"]
readonly = true
restart = "on-failure"
}
CONNECT api -> db
CONNECT api -> cache
CONNECT worker -> db
CONNECT worker -> cache
EXPOSE 8080