-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.withauth.yml
More file actions
169 lines (161 loc) · 5.18 KB
/
docker-compose.withauth.yml
File metadata and controls
169 lines (161 loc) · 5.18 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# docker-compose.withauth.yml — Self-hosted Underlay with bundled auth.
#
# Runs: Underlay app + KF Auth (auth + account) + Postgres + Caddy
# One command: docker compose -f docker-compose.withauth.yml up
#
# First run generates secrets automatically via the init container.
# Set DOMAIN=https://your-domain.com in your shell or .env file.
name: underlay-withauth
services:
# --- Init container: generates secrets + config ---
withauth-init:
image: alpine:3.20
entrypoint: /bin/sh
command:
- -c
- |
if [ -f /config/.env.withauth ]; then
echo "Config already exists, skipping init."
exit 0
fi
apk add --no-cache openssl
AUTH_SECRET=$$(openssl rand -hex 32)
CLIENT_SECRET=$$(openssl rand -hex 32)
INTERNAL_KEY=$$(openssl rand -hex 32)
printf '%s\n' \
"BETTER_AUTH_SECRET=$$AUTH_SECRET" \
"BETTER_AUTH_URL=$${DOMAIN:-http://localhost}/auth" \
"ACCOUNT_URL=$${DOMAIN:-http://localhost}/account" \
"DATABASE_URL=postgres://kfauth:kfauth@postgres:5432/kfauth" \
"SMTP_HOST=$${SMTP_HOST:-localhost}" \
"SMTP_PORT=$${SMTP_PORT:-25}" \
"SMTP_FROM=$${SMTP_FROM:-noreply@localhost}" \
"SMTP_USER=$${SMTP_USER:-}" \
"SMTP_PASS=$${SMTP_PASS:-}" \
"KF_INTERNAL_API_KEY=$$INTERNAL_KEY" \
"BASE_PATH=/auth" \
"APPS_REGISTRY_FILE=/config/apps.withauth.yaml" \
"GITHUB_CLIENT_ID=$${GITHUB_CLIENT_ID:-}" \
"GITHUB_CLIENT_SECRET=$${GITHUB_CLIENT_SECRET:-}" \
"GOOGLE_CLIENT_ID=$${GOOGLE_CLIENT_ID:-}" \
"GOOGLE_CLIENT_SECRET=$${GOOGLE_CLIENT_SECRET:-}" \
"ORCID_CLIENT_ID=$${ORCID_CLIENT_ID:-}" \
"ORCID_CLIENT_SECRET=$${ORCID_CLIENT_SECRET:-}" \
"AUTH_SERVICE_NAME=$${AUTH_SERVICE_NAME:-Underlay Auth}" \
> /config/.env.withauth
printf '%s\n' \
"- client_id: underlay" \
" client_secret: $$CLIENT_SECRET" \
" redirect_uris:" \
" - $${DOMAIN:-http://localhost}/auth/callback" \
" skip_consent: true" \
" display_name: \"Underlay\"" \
" allow_sign_up: true" \
> /config/apps.withauth.yaml
printf '%s\n' \
"OIDC_ISSUER_URL=$${DOMAIN:-http://localhost}/auth" \
"OIDC_ISSUER_INTERNAL_URL=http://auth:3000" \
"OIDC_CLIENT_ID=underlay" \
"OIDC_CLIENT_SECRET=$$CLIENT_SECRET" \
"AUTH_INTERNAL_API_KEY=$$INTERNAL_KEY" \
"DATABASE_URL=postgres://kfauth:kfauth@postgres:5432/app" \
> /config/.env.app
echo "Init complete."
volumes:
- withauth-config:/config
environment:
- DOMAIN
- SMTP_HOST
- SMTP_PORT
- SMTP_FROM
- SMTP_USER
- SMTP_PASS
- GITHUB_CLIENT_ID
- GITHUB_CLIENT_SECRET
- GOOGLE_CLIENT_ID
- GOOGLE_CLIENT_SECRET
- ORCID_CLIENT_ID
- ORCID_CLIENT_SECRET
- AUTH_SERVICE_NAME
# --- Shared Postgres (two databases: kfauth + app) ---
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: kfauth
POSTGRES_PASSWORD: kfauth
POSTGRES_DB: kfauth
volumes:
- pgdata:/var/lib/postgresql/data
- ./selfhost/init-db.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U kfauth']
interval: 5s
timeout: 5s
retries: 10
# --- Auth server (kf-auth) ---
auth:
image: ghcr.io/knowledgefutures/kf-auth:latest
depends_on:
postgres:
condition: service_healthy
withauth-init:
condition: service_completed_successfully
environment:
NODE_ENV: production
PORT: 3000
volumes:
- withauth-config:/config:ro
command: sh -c "set -a && . /config/.env.withauth && set +a && node dist/server.js"
# --- Account server (kf-auth account UI) ---
account:
image: ghcr.io/knowledgefutures/kf-auth:latest
depends_on:
postgres:
condition: service_healthy
withauth-init:
condition: service_completed_successfully
environment:
NODE_ENV: production
PORT: 3001
volumes:
- withauth-config:/config:ro
command: sh -c "set -a && . /config/.env.withauth && set +a && node dist/server-account.js"
# --- Underlay app ---
app:
image: ghcr.io/knowledgefutures/underlay:latest
depends_on:
postgres:
condition: service_healthy
withauth-init:
condition: service_completed_successfully
auth:
condition: service_started
environment:
NODE_ENV: production
PORT: 4100
APP_URL: ${DOMAIN:-http://localhost}
volumes:
- withauth-config:/config:ro
command: sh -c "set -a && . /config/.env.app && set +a && node dist/server.js"
# --- Caddy reverse proxy ---
caddy:
image: caddy:2-alpine
ports:
- '80:80'
- '443:443'
volumes:
- ./selfhost/Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
environment:
DOMAIN: ${DOMAIN:-localhost}
APP_PORT: '4100'
depends_on:
- auth
- account
- app
volumes:
pgdata:
withauth-config:
caddy-data:
caddy-config: