forked from Leantime/leantime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
428 lines (354 loc) · 11.1 KB
/
Copy pathDockerfile
File metadata and controls
428 lines (354 loc) · 11.1 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
FROM php:8.2-fpm-alpine AS composer-builder
WORKDIR /build
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN apk add --no-cache \
freetype \
libjpeg-turbo \
libpng \
libwebp \
libzip \
openldap \
&& apk add --no-cache --virtual .build-deps \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
libzip-dev \
openldap-dev \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
&& docker-php-ext-install -j$(nproc) \
gd \
bcmath \
pdo_mysql \
mysqli \
zip \
ldap \
pcntl \
&& apk del .build-deps
COPY composer.json composer.lock ./
RUN composer install \
--no-dev \
--optimize-autoloader \
--no-interaction \
--no-progress \
--prefer-dist
FROM node:18-alpine AS frontend
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY webpack.mix.js .babelrc ./
COPY tailwind.config.js ./
COPY app ./app
COPY public ./public
COPY generateBlocklist.mjs ./
RUN mkdir -p ./storage/framework/cache ./bootstrap/cache && \
rm -rf ./bootstrap/cache/*.php || true
RUN npx mix --production
RUN if [ -f "generateBlocklist.mjs" ]; then \
node generateBlocklist.mjs; \
else \
echo '{}' > blocklist.json; \
fi
RUN echo "=== Frontend Build Verification ===" && \
echo "=== Contents of public/dist/ ===" && \
ls -lah public/dist/ && \
echo "" && \
echo "=== JavaScript files ===" && \
ls -lah public/dist/js/ && \
echo "" && \
echo "=== CSS files ===" && \
ls -lah public/dist/css/ && \
echo "" && \
echo "=== mix-manifest.json ===" && \
cat public/dist/mix-manifest.json && \
echo "" && \
if [ ! -d "public/dist/js" ]; then \
echo "ERROR: Frontend build failed - public/dist/js not found!"; \
exit 1; \
fi && \
if [ ! -d "public/dist/css" ]; then \
echo "ERROR: Frontend build failed - public/dist/css not found!"; \
exit 1; \
fi && \
echo "✓ Frontend assets built successfully"
FROM php:8.2-fpm-alpine
RUN apk add --no-cache \
nginx \
supervisor \
mysql-client \
freetype \
libjpeg-turbo \
libpng \
libwebp \
libzip \
icu-libs \
libxml2 \
oniguruma \
openldap \
font-noto-emoji \
&& apk add --no-cache --virtual .build-deps \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
libzip-dev \
icu-dev \
libxml2-dev \
oniguruma-dev \
openldap-dev \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
&& docker-php-ext-install -j$(nproc) \
gd \
pdo_mysql \
mysqli \
zip \
intl \
opcache \
bcmath \
exif \
mbstring \
xml \
ldap \
pcntl \
&& apk del .build-deps \
&& rm -rf /var/cache/apk/*
COPY --chown=www-data:www-data <<EOF /usr/local/etc/php/conf.d/leantime.ini
memory_limit = 256M
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 300
date.timezone = UTC
opcache.enable = 1
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 2
opcache.fast_shutdown = 1
EOF
COPY --chown=root:root <<'EOF' /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log warn;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 100M;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
include /etc/nginx/conf.d/*.conf;
}
EOF
COPY --chown=root:root <<'EOF' /etc/nginx/conf.d/default.conf
server {
listen 8080;
server_name _;
root /var/www/html/public;
index index.php index.html;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
access_log /var/log/nginx/leantime-access.log;
error_log /var/log/nginx/leantime-error.log;
client_body_timeout 300s;
client_header_timeout 300s;
send_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffering off;
fastcgi_read_timeout 300;
}
location ~ /\. {
deny all;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
EOF
COPY --chown=root:root <<'EOF' /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:php-fpm]
command=php-fpm -F
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startretries=3
[program:nginx]
command=nginx -g 'daemon off;'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autorestart=true
startretries=3
EOF
WORKDIR /var/www/html
COPY --chown=www-data:www-data . .
COPY --from=composer-builder --chown=www-data:www-data /build/vendor ./vendor
RUN rm -rf public/dist
COPY --from=frontend --chown=www-data:www-data /app/public/dist ./public/dist
COPY --from=frontend --chown=www-data:www-data /app/blocklist.json ./blocklist.json
RUN echo "=== FINAL Asset Verification ===" && \
echo "Contents of public/:" && \
ls -lah public/ && \
echo "" && \
echo "Contents of public/dist/:" && \
ls -lah public/dist/ && \
echo "" && \
echo "Contents of public/dist/js/:" && \
ls -lah public/dist/js/ && \
echo "" && \
echo "Contents of public/dist/css/:" && \
ls -lah public/dist/css/ && \
echo "" && \
echo "mix-manifest.json contents:" && \
cat public/dist/mix-manifest.json && \
echo "" && \
APP_SIZE=$(stat -c%s "public/dist/js/compiled-app.3.5.12.min.js" 2>/dev/null || echo "0") && \
echo "✓ compiled-app.js size: $APP_SIZE bytes" && \
CSS_COUNT=$(find public/dist/css -name "*.css" 2>/dev/null | wc -l) && \
echo "✓ CSS files found: $CSS_COUNT" && \
if [ "$APP_SIZE" -lt "100000" ]; then \
echo "ERROR: compiled-app.js is too small ($APP_SIZE bytes)!"; \
exit 1; \
fi && \
if [ "$CSS_COUNT" -eq "0" ]; then \
echo "ERROR: No CSS files found!"; \
exit 1; \
fi && \
echo "✓ All assets verified successfully!"
RUN mkdir -p \
storage/framework/cache \
storage/framework/sessions \
storage/framework/views \
storage/logs \
bootstrap/cache \
userfiles \
public/userfiles \
&& chown -R www-data:www-data \
storage \
bootstrap/cache \
userfiles \
public/userfiles \
&& chmod -R 775 \
storage \
bootstrap/cache \
userfiles \
public/userfiles
COPY --chown=root:root <<'EOF' /entrypoint.sh
#!/bin/sh
set -e
mkdir -p /var/lib/nginx/tmp/client_body
chown -R www-data:www-data /var/lib/nginx
chmod -R 755 /var/lib/nginx
chown -R www-data:www-data /var/www/html/userfiles /var/www/html/public/userfiles
chmod -R 775 /var/www/html/userfiles /var/www/html/public/userfiles
echo "Starting Leantime container..."
if [ -n "$LEAN_DB_HOST" ]; then
echo "Waiting for database at $LEAN_DB_HOST:${LEAN_DB_PORT:-3306}..."
timeout=60
while ! nc -z "$LEAN_DB_HOST" "${LEAN_DB_PORT:-3306}" 2>/dev/null; do
timeout=$((timeout - 1))
if [ $timeout -le 0 ]; then
echo "ERROR: Database connection timeout"
exit 1
fi
echo "Waiting for database... ($timeout seconds remaining)"
sleep 1
done
echo "Database is ready!"
fi
if [ ! -f /var/www/html/config/.env ]; then
echo "Creating config/.env file..."
cat > /var/www/html/config/.env <<ENVEOF
LEAN_APP_URL="${LEAN_APP_URL:-http://localhost:8080}"
LEAN_APP_DIR="${LEAN_APP_DIR:-}"
LEAN_DEBUG=${LEAN_DEBUG:-0}
LEAN_DB_HOST="${LEAN_DB_HOST:-leantime_db}"
LEAN_DB_USER="${LEAN_DB_USER:-leantime}"
LEAN_DB_PASSWORD="${LEAN_DB_PASSWORD:-leantime}"
LEAN_DB_DATABASE="${LEAN_DB_DATABASE:-leantime}"
LEAN_DB_PORT=${LEAN_DB_PORT:-3306}
LEAN_SESSION_PASSWORD="${LEAN_SESSION_PASSWORD:-$(openssl rand -base64 32)}"
LEAN_SESSION_EXPIRATION=${LEAN_SESSION_EXPIRATION:-28800}
LEAN_SESSION_SECURE=${LEAN_SESSION_SECURE:-false}
LEAN_SITENAME="${LEAN_SITENAME:-Leantime}"
LEAN_LANGUAGE="${LEAN_LANGUAGE:-en-US}"
LEAN_DEFAULT_TIMEZONE="${LEAN_DEFAULT_TIMEZONE:-UTC}"
LEAN_LOG_PATH="${LEAN_LOG_PATH:-}"
LEAN_USER_FILE_PATH="${LEAN_USER_FILE_PATH:-userfiles/}"
LEAN_DB_BACKUP_PATH="${LEAN_DB_BACKUP_PATH:-backupdb/}"
LEAN_EMAIL_RETURN="${LEAN_EMAIL_RETURN:-}"
LEAN_EMAIL_USE_SMTP=${LEAN_EMAIL_USE_SMTP:-false}
LEAN_USE_REDIS=${LEAN_USE_REDIS:-false}
ENVEOF
chown www-data:www-data /var/www/html/config/.env
chmod 600 /var/www/html/config/.env
echo "config/.env created successfully"
else
echo "config/.env already exists, skipping creation"
fi
echo "Clearing cache..."
rm -rf /var/www/html/bootstrap/cache/*.php || true
rm -rf /var/www/html/storage/framework/composerPaths.php || true
rm -rf /var/www/html/storage/framework/viewPaths.php || true
find /var/www/html/storage/framework/cache -type f ! -name '.gitignore' -delete 2>/dev/null || true
find /var/www/html/storage/framework/cache -type d -empty -delete 2>/dev/null || true
find /var/www/html/storage/framework/views -type f ! -name '.gitignore' -delete 2>/dev/null || true
find /var/www/html/storage/framework/views -type d -empty -delete 2>/dev/null || true
echo "Cache cleared successfully!"
echo "=== Pre-startup Asset Check ==="
ls -lah /var/www/html/public/dist/js/compiled-app.*.min.js || echo "WARNING: compiled-app.js not found!"
ls -lah /var/www/html/public/dist/css/ || echo "WARNING: CSS directory not found!"
echo "================================"
echo "Leantime initialization complete!"
echo "Starting services..."
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
EOF
RUN sed -i 's/\r$//' /entrypoint.sh && \
chmod +x /entrypoint.sh
RUN mkdir -p /var/log/supervisor
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/healthCheck.php || exit 1
ENTRYPOINT ["/entrypoint.sh"]