-
-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathdocker-entrypoint-nginx.sh
More file actions
224 lines (208 loc) Β· 6.52 KB
/
Copy pathdocker-entrypoint-nginx.sh
File metadata and controls
224 lines (208 loc) Β· 6.52 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
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
#!/bin/sh
set -e
# Nginx-enabled Docker Entrypoint for Plunk
# Starts all Plunk services with nginx reverse proxy
echo "π Starting Plunk with Nginx reverse proxy..."
echo "π¦ Service: ${SERVICE:-all}"
# Only run with SERVICE=all for nginx setup
if [ "$SERVICE" != "all" ]; then
echo "β οΈ This nginx-enabled image only supports SERVICE=all"
echo " For individual services, use the standard Plunk image"
exit 1
fi
# Run database migrations
echo "ποΈ Running database migrations..."
# Call Prisma binary directly for fastest startup (avoids Yarn workspace resolution and npx overhead)
# The Prisma client and schema are already available from the build
if ! /app/node_modules/.bin/prisma migrate deploy --schema=/app/packages/db/prisma/schema.prisma; then
echo ""
echo "β ERROR: Database migration failed!"
echo " The container cannot start with failed migrations."
echo " Please check:"
echo " 1. DATABASE_URL is set correctly"
echo " 2. Database server is accessible from this container"
echo " 3. Database credentials are valid"
echo " 4. Migration logs above for specific errors"
echo ""
exit 1
fi
echo "β
Database migrations completed successfully"
# Setup nginx configuration and source it to get env vars
. /app/docker/nginx/setup-nginx.sh
# Verify environment variables are set
echo "π Domain configuration:"
echo " API_DOMAIN=${API_DOMAIN}"
echo " DASHBOARD_DOMAIN=${DASHBOARD_DOMAIN}"
echo " LANDING_DOMAIN=${LANDING_DOMAIN}"
echo " WIKI_DOMAIN=${WIKI_DOMAIN}"
echo " USE_HTTPS=${USE_HTTPS}"
echo ""
echo "π Generated URIs:"
echo " API_URI=${API_URI}"
echo " DASHBOARD_URI=${DASHBOARD_URI}"
echo " LANDING_URI=${LANDING_URI}"
echo " WIKI_URI=${WIKI_URI}"
# Debug: Check if API documentation was built
echo "π Checking if API documentation files exist..."
# Check if openapi.local.json exists in the standalone directory
if [ -f "/app/apps/wiki/.next/standalone/apps/wiki/openapi.local.json" ]; then
echo " β
openapi.local.json found in standalone directory"
# Check the server URL in the OpenAPI spec
SERVER_URL=$(grep -o '"url":\s*"[^"]*"' /app/apps/wiki/.next/standalone/apps/wiki/openapi.local.json | head -1 | sed 's/"url":\s*"\([^"]*\)"/\1/')
echo " π OpenAPI server URL: $SERVER_URL"
else
echo " β ERROR: openapi.local.json not found! API pages will not work."
fi
echo ""
echo "βΉοΈ URLs are generated at runtime from domain configuration"
echo " To use custom domains, set these environment variables:"
echo " API_DOMAIN=api.example.com"
echo " DASHBOARD_DOMAIN=app.example.com"
echo " LANDING_DOMAIN=www.example.com"
echo " WIKI_DOMAIN=docs.example.com"
echo " USE_HTTPS=true"
# Source the optimized URL replacement script
. /app/docker/replace-urls-optimized.sh
# Replace URLs in all Next.js apps using optimized function
# This uses pre-generated manifests from build time instead of scanning all files
replace_urls_in_app "web" "/app/apps/web/.next/standalone/apps/web"
replace_urls_in_app "landing" "/app/apps/landing/.next/standalone/apps/landing"
replace_urls_in_app "wiki" "/app/apps/wiki/.next/standalone/apps/wiki"
echo "π Starting services with PM2..."
# Create PM2 ecosystem file with environment variables
cat > /tmp/ecosystem.config.js << PMEOF
module.exports = {
apps: [
{
name: 'nginx',
script: 'nginx',
args: '-g "daemon off;"',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false
},
{
name: 'api',
script: '/app/apps/api/dist/app.js',
cwd: '/app',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
PORT: 8080,
API_URI: '${API_URI}',
DASHBOARD_URI: '${DASHBOARD_URI}',
LANDING_URI: '${LANDING_URI}',
WIKI_URI: '${WIKI_URI}'
}
},
{
name: 'worker',
script: '/app/apps/api/dist/jobs/worker.js',
cwd: '/app',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
API_URI: '${API_URI}',
DASHBOARD_URI: '${DASHBOARD_URI}',
LANDING_URI: '${LANDING_URI}',
WIKI_URI: '${WIKI_URI}'
}
},
{
name: 'smtp',
script: '/app/apps/smtp/dist/server.js',
cwd: '/app',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
API_URI: '${API_URI}',
SMTP_DOMAIN: '${SMTP_DOMAIN:-}',
PORT_SECURE: '465',
PORT_SUBMISSION: '587',
MAX_RECIPIENTS: '${MAX_RECIPIENTS:-5}',
CERT_PATH: '/certs',
ACME_JSON_PATH: '/certs/acme.json'
}
},
{
name: 'web',
script: 'apps/web/server.js',
cwd: '/app/apps/web/.next/standalone',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
PORT: 3000,
HOSTNAME: '0.0.0.0',
API_URI: '${API_URI}',
DASHBOARD_URI: '${DASHBOARD_URI}',
LANDING_URI: '${LANDING_URI}',
WIKI_URI: '${WIKI_URI}'
}
},
{
name: 'landing',
script: 'apps/landing/server.js',
cwd: '/app/apps/landing/.next/standalone',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
PORT: 4000,
HOSTNAME: '0.0.0.0',
API_URI: '${API_URI}',
DASHBOARD_URI: '${DASHBOARD_URI}',
LANDING_URI: '${LANDING_URI}',
WIKI_URI: '${WIKI_URI}',
PLUNK_API_KEY: '${PLUNK_API_KEY:-}'
}
},
{
name: 'wiki',
script: 'apps/wiki/server.js',
cwd: '/app/apps/wiki/.next/standalone',
instances: 1,
exec_mode: 'fork',
autorestart: true,
watch: false,
env: {
NODE_ENV: 'production',
PORT: 1000,
HOSTNAME: '0.0.0.0',
API_URI: '${API_URI}',
DASHBOARD_URI: '${DASHBOARD_URI}',
LANDING_URI: '${LANDING_URI}',
WIKI_URI: '${WIKI_URI}'
}
}
]
};
PMEOF
# Display configuration summary
echo ""
echo "β
Configuration complete!"
echo ""
echo "π Your Plunk instance will be available at:"
echo " API: http://${API_DOMAIN}"
echo " Dashboard: http://${DASHBOARD_DOMAIN}"
echo " Landing: http://${LANDING_DOMAIN}"
echo " Docs: http://${WIKI_DOMAIN}"
echo ""
echo "π Starting all services..."
echo ""
# Start all services with PM2
exec pm2-runtime start /tmp/ecosystem.config.js