-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathentrypoint.sh
More file actions
100 lines (88 loc) · 3.36 KB
/
entrypoint.sh
File metadata and controls
100 lines (88 loc) · 3.36 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
#!/bin/ash -e
# check for .env file or symlink and generate app keys if missing
if [ -f /var/www/html/.env ]; then
echo "external vars exist."
# load specific env vars from .env used in the entrypoint and they are not already set
for VAR in "APP_KEY" "APP_INSTALLED" "DB_CONNECTION" "DB_HOST" "DB_PORT"; do if ! (printenv | grep -q ${VAR}); then export $(grep ${VAR} .env | grep -ve "^#"); fi; done
else
echo "external vars don't exist."
# webroot .env is symlinked to this path
touch /pelican-data/.env
# manually generate a key because key generate --force fails
if [ -z ${APP_KEY} ]; then
echo -e "Generating key."
APP_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo -e "Generated app key: $APP_KEY"
echo -e "APP_KEY=$APP_KEY" > /pelican-data/.env
else
echo -e "APP_KEY exists in environment, using that."
echo -e "APP_KEY=$APP_KEY" > /pelican-data/.env
fi
# enable installer
echo -e "APP_INSTALLED=false" >> /pelican-data/.env
fi
# create directories for volumes
mkdir -p /pelican-data/database /pelican-data/storage/avatars /pelican-data/storage/fonts /pelican-data/storage/icons /pelican-data/plugins /var/www/html/storage/logs/supervisord 2>/dev/null
# if the app is installed then we need to run migrations on start. New installs will run migrations when you run the installer.
if [ "${APP_INSTALLED}" == "true" ]; then
#if the db is anything but sqlite wait until it's accepting connections
if [ "${DB_CONNECTION}" != "sqlite" ]; then
# check for DB up before starting the panel
echo "Checking database status."
until nc -z -v -w30 $DB_HOST $DB_PORT
do
echo "Waiting for database connection..."
# wait for 1 seconds before check again
sleep 1
done
fi
# run migration
php artisan migrate --force
fi
echo -e "Optimizing Filament"
php artisan filament:optimize
# default to caddy not starting
export SUPERVISORD_CADDY=false
export PARSED_APP_URL=${APP_URL}
# checking if app url is using https
if echo "${APP_URL}" | grep -qE '^https://'; then
echo "https domain found setting email var"
export PARSED_LE_EMAIL="email ${LE_EMAIL}"
fi
# when running behind a proxy
if [ "${BEHIND_PROXY}" == "true" ]; then
echo "running behind proxy"
echo "listening on port 80 internally"
export PARSED_LE_EMAIL=""
export PARSED_APP_URL=":80"
export PARSED_AUTO_HTTPS="auto_https off"
export ASSET_URL=${APP_URL}
# Write ASSET_URL to .env so PHP-FPM workers can read it (clear_env = yes by default)
ENV_FILE="/var/www/html/.env"
if [ -e "$ENV_FILE" ]; then
ENV_FILE="$(readlink -f "$ENV_FILE")"
else
ENV_FILE="/pelican-data/.env"
fi
ESCAPED_APP_URL="$(printf '%s' "$APP_URL" | sed 's/[&|]/\\&/g')"
if grep -q "^ASSET_URL=" "$ENV_FILE"; then
sed -i "s|^ASSET_URL=.*|ASSET_URL=${ESCAPED_APP_URL}|" "$ENV_FILE"
else
echo "ASSET_URL=${APP_URL}" >> "$ENV_FILE"
fi
fi
# disable caddy if SKIP_CADDY is set
if [ "${SKIP_CADDY:-}" == "true" ]; then
echo "Starting PHP-FPM only"
else
echo "Starting PHP-FPM and Caddy"
# enable caddy
export SUPERVISORD_CADDY=true
# handle trusted proxies for caddy when variable has data
if [ ! -z ${TRUSTED_PROXIES} ]; then
export CADDY_TRUSTED_PROXIES=$(echo "trusted_proxies static ${TRUSTED_PROXIES}" | sed 's/,/ /g')
export CADDY_STRICT_PROXIES="trusted_proxies_strict"
fi
fi
echo "Starting Supervisord"
exec "$@"