-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcompile
executable file
·541 lines (430 loc) · 18 KB
/
compile
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
#!/bin/bash
set -e
set -o pipefail
shopt -s dotglob
basedir="$( cd -P "$( dirname "$0" )" && pwd )"
source "$basedir/../conf/buildpack.conf"
source $basedir/common.sh
source $basedir/../lib/package
source $basedir/../lib/composer
source $basedir/../lib/datadog
source $basedir/../lib/scout
source $basedir/../lib/newrelic
source $basedir/../lib/apt
source $basedir/../lib/pecl
source $basedir/../lib/pecl_oci8
if [ "$PHP_BUILDPACK_NO_NODE" != "true" ] ; then
source $basedir/../lib/nodejs
fi
if [ -n "$BUILDPACK_DEBUG" ]; then
set -x
fi
BUILD_DIR="$1"
CACHE_DIR="$2"
ENV_DIR="$3"
cd "$BUILD_DIR"
mkdir -p "$CACHE_DIR/package"
export APP_ENV=${APP_ENV:-prod}
function detect_framework() {
BUILD_DIR=$1
for f in "$basedir/../frameworks/"*; do
if "$f" detect "$BUILD_DIR"; then
FRAMEWORK=$f
break
fi
done
}
function best_composer_version() {
local require_composer=""
if [ -f "${BUILD_DIR}/composer.json" ]; then
require_composer=$(jq --raw-output ".extra.${composer_extra_key}.engines.composer // \"\"" < "$BUILD_DIR/composer.json")
fi
if [ -z "${require_composer}" ] ; then
require_composer="${COMPOSER_VERSION:-${DEFAULT_COMPOSER}}"
fi
curl --fail --location --silent "${SEMVER_SERVER}/composer-${STACK}/resolve/${require_composer}"
}
function best_nginx_version() {
local require_nginx=""
if [ -f "${BUILD_DIR}/composer.json" ]; then
for key in ".require.nginx" ".extra.${composer_extra_key}.engines.nginx"; do
require_nginx=$(jq --raw-output "${key} // \"\"" < "${BUILD_DIR}/composer.json")
[ -n "${require_nginx}" ] && break
done
fi
if [ -z "${require_nginx}" ]; then
require_nginx="${NGINX_VERSION:-${DEFAULT_NGINX}}"
fi
curl --fail --location --silent "${SEMVER_SERVER}/nginx-${STACK}/resolve/${require_nginx}"
}
function best_php_version() {
local require_php=""
# First check if we have something in composer.json
# If so, this is the value we want. It must always prevail:
if [ -f "${BUILD_DIR}/composer.json" ]; then
for key in ".require.php" ".config.platform.php" ".extra.${composer_extra_key}.engines.php"; do
require_php="$( jq --raw-output "${key} // \"\"" < "${BUILD_DIR}/composer.json" )"
[ -n "${require_php}" ] && break
done
fi
# If nothing is specified in composer.json
# Or if this is a Classic app, we should check PHP_VERSION:
if [ -z "${require_php}" ]; then
require_php="${PHP_VERSION:-${DEFAULT_PHP}}"
fi
curl --fail --location --silent "${SEMVER_SERVER}/php-${STACK}/resolve/${require_php}"
}
function php_api_version() {
basename "$(php-config --extension-dir)" | tr '-' ' ' | cut -f 5 -d ' '
}
function has_heroku_extra() {
jq --raw-output '.extra.heroku // ""' < "$BUILD_DIR/composer.json"
}
function package_document_root() {
jq --raw-output ".extra.${composer_extra_key}[\"document-root\"] // \"\"" < "$BUILD_DIR/composer.json"
}
function package_index_file() {
jq --raw-output ".extra.${composer_extra_key}[\"index-document\"] // \"index.php\"" < "$BUILD_DIR/composer.json"
}
function package_framework() {
jq --raw-output ".extra.${composer_extra_key}.framework // \"\"" < "$BUILD_DIR/composer.json"
}
function package_nginx_version() {
jq --raw-output ".extra.${composer_extra_key}.engines.nginx // \"default\"" < "$BUILD_DIR/composer.json"
}
function package_php_config() {
jq --raw-output ".extra.${composer_extra_key}[\"php-config\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_php_includes() {
jq --raw-output ".extra.${composer_extra_key}[\"php-includes\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_php_fpm_config() {
jq --raw-output ".extra.${composer_extra_key}[\"php-fpm-config\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_php_fpm_includes() {
jq --raw-output ".extra.${composer_extra_key}[\"php-fpm-includes\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_nginx_http_includes() {
jq --raw-output ".extra.${composer_extra_key}[\"nginx-http-includes\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_nginx_includes() {
jq --raw-output ".extra.${composer_extra_key}[\"nginx-includes\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_log_files() {
jq --raw-output ".extra.${composer_extra_key}[\"log-files\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_access_log_format() {
jq --raw-output ".extra.${composer_extra_key}[\"access-log-format\"] // \"\"" < "$BUILD_DIR/composer.json"
}
function package_compile_cmd() {
jq --raw-output ".extra.${composer_extra_key}[\"compile\"] // [] | .[]" < "$BUILD_DIR/composer.json"
}
function package_datadog_enabled() {
local val=$(jq --raw-output ".extra.${composer_extra_key}.datadog // false" < "$BUILD_DIR/composer.json")
if [ "$val" = "true" ]; then
return 0
else
return 1
fi
}
function package_newrelic_enabled() {
local val=$(jq --raw-output ".extra.${composer_extra_key}[\"new-relic\"] // false" < "$BUILD_DIR/composer.json")
if [ "$val" = "true" ]; then
return 0
else
return 1
fi
}
function package_scout_enabled() {
local val=$(jq --raw-output ".extra.${composer_extra_key}.scout // false" < "$BUILD_DIR/composer.json")
if [ "$val" = "true" ]; then
return 0
else
return 1
fi
}
export_env_dir "$3"
# Create some required directories:
mkdir -p "${BUILD_DIR}/bin" "${BUILD_DIR}/vendor"
DEFAULT_PHP=$(curl --fail --location --silent "${SEMVER_SERVER}/php-${STACK}")
DEFAULT_NGINX=$(curl --fail --location --silent "${SEMVER_SERVER}/nginx-${STACK}")
DEFAULT_COMPOSER=$(curl --fail --location --silent "${SEMVER_SERVER}/composer-${STACK}")
# Read config variables from composer.json if it exists
if [ -f "$BUILD_DIR/composer.json" ]; then
composer_extra_key="paas"
if [ -n "$(has_heroku_extra)" ] ; then
protip "Your composer.json is using the key 'extra' → 'heroku', you should switch to 'extra' → 'paas' for standardization"
composer_extra_key="heroku"
fi
fi
PHP_VERSION=$(best_php_version)
NGINX_VERSION=$(best_nginx_version)
COMPOSER_VERSION=$(best_composer_version)
DOCUMENT_ROOT="${DOCUMENT_ROOT:-}"
INDEX_DOCUMENT="${INDEX_DOCUMENT:-index.php}"
FRAMEWORK="${FRAMEWORK:-}"
PHP_EXTRA_CONFIG="${PHP_EXTRA_CONFIG:-}"
PHP_INCLUDES="${PHP_INCLUDES:-}"
PHP_FPM_INCLUDES="${PHP_FPM_INCLUDES:-}"
PHP_FPM_EXTRA_CONFIG="${PHP_FPM_EXTRA_CONFIG:-}"
COMPILE_CMD="${COMPILE_CMD:-}"
NGINX_HTTP_INCLUDES="${NGINX_HTTP_INCLUDES:-}"
NGINX_INCLUDES="${NGINX_INCLUDES:-}"
ACCESS_LOG_FORMAT_COMPOSER_JSON="${ACCESS_LOG_FORMAT_COMPOSER_JSON:-}"
DATADOG_TRACER_VERSION="${DATADOG_TRACER_VERSION:-latest}"
DATADOG_APPSEC_VERSION="${DATADOG_APPSEC_VERSION:-0}"
SCOUT_APM_VERSION=${SCOUT_APM_VERSION:-1.10.0}
# Version number comes from https://download.newrelic.com/php_agent/archive/
NEWRELIC_VERSION="${NEWRELIC_VERSION:=10.15.0.4}"
LOG_FILES=( "/app/vendor/nginx/logs/access.log" "/app/vendor/nginx/logs/error.log" "/app/vendor/php/var/log/error.log" )
# Display a warning that Composer version 1.x is End of Life
if [[ "$COMPOSER_VERSION" = 1.* ]]; then
echo >&2 ""
echo >&2 "######################################"
echo >&2 "WARNING: You are using Composer ${COMPOSER_VERSION}. Composer 1 is End of Life since the 24th of October 2020 and will soon be deprecated."
echo >&2 "https://doc.scalingo.com/languages/php/start#select-a-composer-version"
echo >&2 "######################################"
echo >&2 ""
fi
check_composer_syntax "$BUILD_DIR"
check_composer_json_and_lock "$BUILD_DIR"
# Read config variables from composer.json if it exists
if [ -f "$BUILD_DIR/composer.json" ]; then
DOCUMENT_ROOT=$(package_document_root)
INDEX_DOCUMENT=$(package_index_file)
FRAMEWORK=$(package_framework)
PHP_EXTRA_CONFIG=$(package_php_config)
PHP_FPM_EXTRA_CONFIG=$(package_php_fpm_config)
PHP_INCLUDES=$(package_php_includes)
PHP_FPM_INCLUDES=$(package_php_fpm_includes)
COMPILE_CMD=$(package_compile_cmd)
NGINX_HTTP_INCLUDES=$(package_nginx_http_includes)
NGINX_INCLUDES=$(package_nginx_includes)
USER_LOG_FILES=$(package_log_files)
ACCESS_LOG_FORMAT_COMPOSER_JSON=$(package_access_log_format)
fi
VENDORED_NGINX=/app/vendor/nginx
VENDORED_PHP=/app/vendor/php
status "Bundling Nginx ${NGINX_VERSION}"
fetch_engine_package nginx "$NGINX_VERSION" "${VENDORED_NGINX}" | indent
status "Bundling PHP ${PHP_VERSION}"
# Install libraries also on build container, so PHP doesn't complain about missing
# dynamic libraries when running it during the slug compilation.
fetch_package "$PHP_BASE_URL" "libmcrypt-${mcrypt_version}" /app/vendor/libmcrypt > /dev/null
fetch_package "$PHP_BASE_URL" "libzip-${zip_version}" /app/vendor/libzip > /dev/null
fetch_package "$PHP_BASE_URL" "libwebp-${webp_version}" /app/vendor/libwebp > /dev/null
fetch_engine_package php "$PHP_VERSION" "${VENDORED_PHP}" | indent
test ! -d ".profile.d" && mkdir -p .profile.d || true
cat > ".profile.d/php.sh" <<SH
export PATH=/app/bin:${VENDORED_NGINX}/sbin:${VENDORED_PHP}/sbin:${VENDORED_PHP}/bin:/app/vendor/bin:\$PATH
export APP_BUILD_TIME=$(date +%Y%m%d%H%M%S)
export LD_LIBRARY_PATH=/app/vendor/libonig:\$LD_LIBRARY_PATH
[ -d "/app/vendor/libsodium" ] && export LD_LIBRARY_PATH=/app/vendor/libsodium:\$LD_LIBRARY_PATH
# Set APP_ENV to prod by default for Symfony based framework.
export APP_ENV="\${APP_ENV:-prod}"
# Configure every how many request PHP-FPM recycle its worker, disabled by default
export PHP_FPM_MAX_REQUESTS="\${PHP_FPM_MAX_REQUESTS:-0}"
SH
if [ $STACK = "scalingo-14" ] ; then
fetch_package "$PHP_BASE_URL" "tail-${coreutils_version}" /app/vendor/coreutils > /dev/null
fi
source ".profile.d/php.sh"
# Lib Oniguruma is only mandatory starting with PHP 7.4
if [[ "$(php_api_version)" -ge "${PHP_MODULE_API_VERSIONS["7.4"]}" ]] ; then
fetch_package "$PHP_BASE_URL" "libonig-${libonig_version}" /app/vendor/libonig > /dev/null
export LD_LIBRARY_PATH="/app/vendor/libonig:$LD_LIBRARY_PATH"
fi
# Fetch additional extensions
status "Bundling platform default extensions"
echo " apcu"
fetch_package "$PHP_BASE_URL" "ext/$(php_api_version)/php-apcu" "/app/vendor/php" | indent
echo " phpredis"
fetch_package "$PHP_BASE_URL" "ext/$(php_api_version)/php-redis" "/app/vendor/php" | indent
echo " mongodb"
fetch_package "$PHP_BASE_URL" "ext/$(php_api_version)/php-mongodb" "/app/vendor/php" | indent
if [ "$(php_api_version)" = "20170718" -o "$(php_api_version)" = "20180731" ] ; then
echo " mcrypt"
fetch_package "$PHP_BASE_URL" "ext/$(php_api_version)/php-mcrypt" "/app/vendor/php" | indent
fi
if [ -f "$BUILD_DIR/composer.json" ] && package_datadog_enabled; then
install_datadog "${DATADOG_TRACER_VERSION}" "${DATADOG_APPSEC_VERSION}"
fi
if [ -f "$BUILD_DIR/composer.json" ] && package_scout_enabled; then
install_scout "${SCOUT_APM_VERSION}"
fi
if [ -f "$BUILD_DIR/composer.json" ] && package_newrelic_enabled; then
status "New Relic usage detected, installing Agent and PHP extension"
LOG_FILES+=( "/app/vendor/newrelic/daemon.log" "/app/vendor/newrelic/agent.log" )
install_newrelic "$NEWRELIC_VERSION"
install_newrelic_user_config
echo 'export NEW_RELIC_LOG_DAEMON=${NEW_RELIC_LOG_DAEMON:=/app/vendor/newrelic/daemon.log}' >> ".profile.d/php.sh"
echo 'export NEW_RELIC_LOG_AGENT=${NEW_RELIC_LOG_AGENT:=/app/vendor/newrelic/agent.log}' >> ".profile.d/php.sh"
fi
if [ -n "$BLACKFIRE_SERVER_ID" -a -n "$BLACKFIRE_SERVER_TOKEN" ] ; then
status "Blackfire usage detected, installing PHP extension"
fetch_package "$PHP_BASE_URL" "ext/$(php_api_version)/php-blackfire" "/app/vendor/php" | indent
cp /app/vendor/php/bin/profile.blackfire.sh $BUILD_DIR/.profile.d
fi
if [ -n "$BUILDPACK_DEBUG" ]; then
ls -R /app/vendor/nginx
ls -R /app/vendor/php
fi
mkdir -p "conf"
cp "$basedir/util/autotune.php" "conf/autotune.php"
cp "$basedir/../conf/nginx/base.conf.erb" "conf/nginx.conf.erb"
# Fix dirty logging on stdout/stderr (WARNING child with PID said on stderr). It
# has been fixed in PHP 7.3 (https://github.com/php/php-src/pull/2458) with a
# custom php-fpm parameter: `decorate_workers_output`
if [[ "$(php_api_version)" -gt "${PHP_MODULE_API_VERSIONS["7.2"]}" ]] ; then
cp "$basedir/../conf/php/php-fpm-73.conf" "/app/vendor/php/etc/php-fpm.conf"
else
cp "$basedir/../conf/php/php-fpm.conf" "/app/vendor/php/etc/php-fpm.conf"
fi
cp "$basedir/../conf/php/php.ini" "/app/vendor/php/etc/php.ini"
mkdir -p /app/vendor/php/etc/fpm.d
echo "; extra configuration for php fpm" >> "/app/vendor/php/etc/fpm.d/extra.conf"
# IFS= to set on multiple line each configuration item
OLDIFS=$IFS
IFS=
echo $PHP_EXTRA_CONFIG | while read conf ; do
echo "$conf" >> "/app/vendor/php/etc/php.ini"
done
echo $PHP_FPM_EXTRA_CONFIG | while read conf ; do
echo "$conf" >> "/app/vendor/php/etc/fpm.d/extra.conf"
done
IFS=$OLDIFS
for include in $PHP_INCLUDES; do
cp "$BUILD_DIR/$include" "/app/vendor/php/etc/conf.d/"
done
if [ -n "$PHP_FPM_INCLUDES" ] ; then
for include in $PHP_FPM_INCLUDES; do
cp "$BUILD_DIR/$include" "/app/vendor/php/etc/fpm.d/"
done
fi
if [ "$PHP_BUILDPACK_NO_NODE" != "true" ] ; then
install_node_deps "$BUILD_DIR"
fi
install_composer_deps "${BUILD_DIR}" "${CACHE_DIR}" "${ENV_DIR}"
# Detect PHP framework
# Set FRAMEWORK if not set in environment by user
if [ -z "$FRAMEWORK" ]; then
detect_framework "$BUILD_DIR"
fi
# Fall back to classic mode
if [ -z "$FRAMEWORK" ]; then
FRAMEWORK="$basedir/../frameworks/default"
fi
# Try to load the framework from the "frameworks" directory if it's just a
# simple framework name like "symfony"
if [ -f "$basedir/../frameworks/$FRAMEWORK" ]; then
FRAMEWORK="$basedir/../frameworks/$FRAMEWORK"
fi
if [ ! -f "$FRAMEWORK" ]; then
error "Framework \"$FRAMEWORK\" not found!"
fi
"$FRAMEWORK" compile "$BUILD_DIR" "$CACHE_DIR"
LOG_FILES=$(unique_array ${LOG_FILES[@]} ${USER_LOG_FILES[@]})
if [ -n "$FRAMEWORK" ] && [ -f "$FRAMEWORK" ]; then
FRAMEWORK_LOG_FILES=$("$FRAMEWORK" get-log-files "$BUILD_DIR")
LOG_FILES=$(unique_array ${LOG_FILES[@]} ${FRAMEWORK_LOG_FILES[@]})
fi
if [ -n "$COMPILE_CMD" ]; then
status "Running compile commands"
while read -r cmd; do
echo "Running '$cmd'" | indent
eval $cmd | indent
done <<< "$COMPILE_CMD"
fi
if [ -n "$FRAMEWORK" ] && [ -f "$FRAMEWORK" ]; then
"$FRAMEWORK" end "$BUILD_DIR" "$CACHE_DIR"
fi
"$FRAMEWORK" post-compile "$BUILD_DIR" "$CACHE_DIR" || true
status "Vendoring binaries into slug"
mv /app/vendor/nginx vendor/nginx
mv /app/vendor/php vendor/php
[ -d "/app/vendor/libmcrypt" ] && mv /app/vendor/libmcrypt vendor/libmcrypt
[ -d "/app/vendor/libonig" ] && mv /app/vendor/libonig vendor/libonig
[ -d "/app/vendor/libzip" ] && mv /app/vendor/libzip vendor/libzip
[ -d "/app/vendor/coreutils" ] && mv /app/vendor/coreutils vendor/coreutils
[ -d "/app/vendor/libmemcached" ] && mv /app/vendor/libmemcached vendor/libmemcached
[ -d "/app/vendor/gmp" ] && mv /app/vendor/gmp vendor/gmp
[ -d "/app/vendor/libtidy" ] && mv /app/vendor/libtidy vendor/libtidy
[ -d "/app/vendor/libsodium" ] && mv /app/vendor/libsodium vendor/libsodium
[ -d "/app/vendor/libwebp" ] && mv /app/vendor/libwebp vendor/libwebp
[ -d "/app/vendor/oracle-client" ] && mv /app/vendor/oracle-client vendor/oracle-client
mkdir -p "bin" "vendor/bin"
if [ "$STACK" = "scalingo-14" ] ; then
test ! -f "bin/tail" && ln -s "/app/vendor/coreutils/bin/tail" "bin/tail"
fi
# If this buildpack is run after the nodejs buildpack remove the WEB_CONCURRENCY script
if [ -f "$BUILD_DIR/.profile.d/WEB_CONCURRENCY.sh" ] ; then
rm "$BUILD_DIR/.profile.d/WEB_CONCURRENCY.sh"
fi
cat > "bin/run" <<SH
#!/usr/bin/env bash
pmsgr=/tmp/pmsgr
rm -f \$pmsgr
mkfifo \$pmsgr
# Loop through all environment variables. Work even though there are multi-lines
# env variables.
env -0 | while IFS='=' read -r -d '' name value; do
echo "env[\$name] = \\$\${name}" >> /app/vendor/php/etc/php-fpm.conf
done
export DOCUMENT_ROOT="\${DOCUMENT_ROOT:-$DOCUMENT_ROOT}"
export INDEX_DOCUMENT="\${INDEX_DOCUMENT:-$INDEX_DOCUMENT}"
export NGINX_HTTP_INCLUDES="\${NGINX_HTTP_INCLUDES:-$NGINX_HTTP_INCLUDES}"
export NGINX_INCLUDES="\${NGINX_INCLUDES:-$NGINX_INCLUDES}"
export ACCESS_LOG_FORMAT_COMPOSER_JSON='$ACCESS_LOG_FORMAT_COMPOSER_JSON'
export ACCESS_LOG_FORMAT="\${ACCESS_LOG_FORMAT:-\$ACCESS_LOG_FORMAT_COMPOSER_JSON}"
if [ -f "/app/vendor/php/etc/conf.d/newrelic.ini" ] ; then
if [ -n "\$NEW_RELIC_LICENSE_KEY" ]; then
echo "newrelic.license=\"\$NEW_RELIC_LICENSE_KEY\"" > /app/vendor/php/etc/conf.d/newrelic_license.ini
else
echo " !"
echo " ! New Relic agent has been installed but is misconfigured"
echo " ! NEW_RELIC_LICENSE_KEY should be define in the application environment"
echo " !"
echo " ! Documentation: https://doc.scalingo.com/languages/php/start"
echo " !"
fi
fi
erb conf/nginx.conf.erb > /app/vendor/nginx/conf/nginx.conf
erb conf/site.conf.erb > /app/vendor/nginx/conf/site.conf
if [[ -z \${WEB_CONCURRENCY:-} ]]; then
ram="512M"
container_size=\${CONTAINER_SIZE:-M}
if [ \$container_size = "S" ] ; then
ram="256M"
elif [ \$container_size = "L" ] ; then
ram="1024M"
elif [ \$container_size = "XL" ] ; then
ram="2048M"
elif [ \$container_size = "2XL" ] ; then
ram="4096M"
elif [ \$container_size = "3XL" ] ; then
ram="8182M"
fi
echo "Optimizing defaults for \${container_size} container..." >&2
# determine number of FPM processes to run
read WEB_CONCURRENCY php_memory_limit <<<\$(php -c "/app/vendor/php/etc/php.ini" /app/conf/autotune.php -y "/app/vendor/php/etc/php-fpm.conf" -t "\$DOCUMENT_ROOT" "\$ram")
[[ \$WEB_CONCURRENCY -lt 3 ]] && WEB_CONCURRENCY=3
export WEB_CONCURRENCY
echo "\${WEB_CONCURRENCY} processes at \${php_memory_limit}B memory limit." >&2
else
echo "Using WEB_CONCURRENCY=\${WEB_CONCURRENCY} processes." >&2
fi
`init_log_plex ${LOG_FILES}`
`tail_log_plex ${LOG_FILES} ${SYS_LOG_FILES}`
(
php-fpm -p "/app/vendor/php"
echo "php-fpm" > \$pmsgr
)&
(
nginx -p "/app/vendor/nginx" -c /app/vendor/nginx/conf/nginx.conf
echo "nginx" > \$pmsgr
)&
read exitproc <\$pmsgr
echo "Boot failed: \$exitproc"
exit 1
SH
chmod +x "bin/run"