Repository navigation
Expand file tree
/
Copy pathdocker-compose.hub.yml
More file actions
153 lines (149 loc) · 7.2 KB
/
Copy pathdocker-compose.hub.yml
File metadata and controls
153 lines (149 loc) · 7.2 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
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
# BarakoCMS — run everything from prebuilt Docker Hub images (no build step).
# A one-shot job creates the database role the API connects as (DB_APP_USER, no superuser), the same
# as docker-compose.prod.yml, and the API starts after it. Production is docker-compose.prod.yml.
#
# docker compose -f docker-compose.hub.yml up -d
#
# Set JWT_SECRET, DB_PASSWORD and DB_APP_PASSWORD first, in your shell or a .env file
# (cp .env.example .env). DB_PASSWORD is the database owner's, DB_APP_PASSWORD is the API's role:
#
# export JWT_SECRET=$(openssl rand -base64 48)
# export DB_PASSWORD=$(openssl rand -base64 24)
# export DB_APP_PASSWORD=$(openssl rand -base64 24)
#
# Run it from a checkout: the role job mounts ./scripts/db-app-role.sql, so this file needs the
# checkout's scripts/ folder next to it.
#
# The API is on http://localhost:5005. For the console, run BaryoDev/barakoBrew's quickstart
# against it.
#
# This is a local try-out: no TLS, and the API listens on localhost only. For a real
# deployment use docker-compose.prod.yml, which runs these same published images behind Caddy with
# required secrets. See docs/deploy-in-production.md.
services:
postgres:
image: pgvector/pgvector:pg16@sha256:484e838076e04939d27d3e176e91c86eea96236126023be8d3059761122e579f # pgvector/pgvector:pg16
container_name: barako-postgres
restart: unless-stopped
environment:
POSTGRES_DB: ${DB_NAME:-barako_cms}
POSTGRES_USER: ${DB_USER:-postgres}
POSTGRES_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD}
# pg_stat_statements is loaded so slow queries can be found; the postgres-extensions job below
# creates it and the app role the API connects as.
command:
- postgres
- -c
- shared_preload_libraries=pg_stat_statements
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U ${DB_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
read_only: true
tmpfs:
- /tmp:mode=1777,size=64m
- /var/run/postgresql:mode=1777,size=8m
cap_drop: [ALL]
cap_add:
- CHOWN # the entrypoint fixes the data directory's owner on a fresh volume
- DAC_OVERRIDE # initdb and the entrypoint write into directories they do not own
- FOWNER # initdb sets modes on files it created as root
- SETGID # gosu drops to the postgres group
- SETUID # gosu drops to the postgres user
security_opt:
- no-new-privileges:true
labels:
org.barakocms.hardening.root: "the image entrypoint starts as root to prepare the data directory, then drops to the postgres user"
mem_limit: ${DB_MEM_LIMIT:-2g}
pids_limit: ${DB_PIDS_LIMIT:-512}
# Runs scripts/db-app-role.sql as the database owner once Postgres is up, then exits. It creates
# the login role the API connects as (DB_APP_USER, no superuser), sets its password and makes it
# owner of what is in schema public. The script is safe to run on every start. The API waits for
# this job to finish, and if it fails the API does not start; its log says why. It reads
# DB_APP_USER and DB_APP_PASSWORD from its environment, never from the command line.
postgres-extensions:
image: postgres:16-alpine@sha256:f2f98726820d0342055351c6e9d36e705f5bfffb3dd53ff556325114b08afb6d # postgres:16-alpine
container_name: barako-postgres-extensions
restart: "no"
depends_on:
postgres:
condition: service_healthy
environment:
PGHOST: postgres
PGDATABASE: ${DB_NAME:-barako_cms}
PGUSER: ${DB_USER:-postgres}
PGPASSWORD: ${DB_PASSWORD:?set DB_PASSWORD}
DB_APP_USER: ${DB_APP_USER:-barako_app}
DB_APP_PASSWORD: ${DB_APP_PASSWORD:?set DB_APP_PASSWORD, the API connects as this role}
command: ["psql", "-X", "-v", "ON_ERROR_STOP=1", "-f", "/db-app-role.sql"]
volumes:
- ./scripts/db-app-role.sql:/db-app-role.sql:ro
user: "70:70"
read_only: true
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
mem_limit: ${EXTENSIONS_MEM_LIMIT:-128m}
pids_limit: ${EXTENSIONS_PIDS_LIMIT:-64}
labels:
org.barakocms.hardening.one-shot: "runs the app role script and exits, so it has nothing to check"
app:
# Barako — the full suite (engine + all modules). For the lean core, swap in
# ghcr.io/baryodev/barako-cms-decaf:latest and add only the modules you want in your own host.
# Required rather than defaulting to latest, because with a default the next pull is an
# unplanned major upgrade.
image: ghcr.io/baryodev/barako-cms:${BARAKO_TAG:?pin a version in .env or your shell, for example 5.9.0}
container_name: barako-cms
restart: unless-stopped
ports:
# Bound to this machine only. To reach it from other hosts, change this to "5005:8080" and put
# TLS in front of it (see docs/deploy-in-production.md).
- "127.0.0.1:5005:8080"
environment:
- ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Production}
- ConnectionStrings__DefaultConnection=Host=postgres;Database=${DB_NAME:-barako_cms};Username=${DB_APP_USER:-barako_app};Password=${DB_APP_PASSWORD:?set DB_APP_PASSWORD, the API connects as this role}
# JWT key must be at least 32 characters or the API refuses to start.
- JWT__Key=${JWT_SECRET:?set JWT_SECRET to a random value of 32+ characters}
- InitialAdmin__Username=${ADMIN_USER:-admin}
# No default. Unset, the seeder generates a password and prints it once to the container log
# (docker compose -f docker-compose.hub.yml logs app).
- InitialAdmin__Password=${ADMIN_PASSWORD:-}
# The API refuses to start in Production when it accepts any host. The port above is bound to
# this machine, so localhost is what it is reached on. Behind a domain, set ALLOWED_HOSTS to it
# (semicolon separated). To accept any host on purpose, set Security__AllowAnyHost=true.
- AllowedHosts=${ALLOWED_HOSTS:-localhost;127.0.0.1}
# Off by default here. This file runs the published images, so it is the one people copy
# toward a host, and if the environment is set to Development, that would otherwise
# turn the API explorer on for them without anyone choosing it. Set SWAGGER_ENABLED=true.
- Swagger__Enabled=${SWAGGER_ENABLED:-false}
# The role job first: it creates the role this API connects as.
depends_on:
postgres:
condition: service_healthy
postgres-extensions:
condition: service_completed_successfully
user: "1654:1654"
read_only: true
tmpfs:
# Upload buffering and the runtime's scratch files. The image root is read-only, so this and
# the home directory are the only places the API can write.
- /tmp:mode=1777,size=${API_TMP_SIZE:-512m}
- /home/app:uid=1654,gid=1654,mode=0700,size=16m
cap_drop: [ALL]
security_opt:
- no-new-privileges:true
mem_limit: ${API_MEM_LIMIT:-1g}
pids_limit: ${API_PIDS_LIMIT:-512}
# The image has no shell or curl, so the probe is built into the app. It asks this container's own
# listener, so no host or database is involved.
healthcheck:
test: ["CMD", "dotnet", "barakoCMS.dll", "--health-probe"]
interval: 15s
timeout: 10s
retries: 5
start_period: 60s
volumes:
postgres_data: