fiddle with docker
This commit is contained in:
@@ -6,6 +6,8 @@ APP_TARGET=${APP_TARGET:-/var/www/html}
|
|||||||
APP_USER=${APP_USER:-www-data}
|
APP_USER=${APP_USER:-www-data}
|
||||||
APP_GROUP=${APP_GROUP:-www-data}
|
APP_GROUP=${APP_GROUP:-www-data}
|
||||||
SKIP_CODE_SYNC=${SKIP_CODE_SYNC:-0}
|
SKIP_CODE_SYNC=${SKIP_CODE_SYNC:-0}
|
||||||
|
DB_WAIT_TIMEOUT=${DB_WAIT_TIMEOUT:-60}
|
||||||
|
REDIS_WAIT_TIMEOUT=${REDIS_WAIT_TIMEOUT:-60}
|
||||||
|
|
||||||
sync_code() {
|
sync_code() {
|
||||||
if [[ "$SKIP_CODE_SYNC" == "1" ]]; then
|
if [[ "$SKIP_CODE_SYNC" == "1" ]]; then
|
||||||
@@ -42,9 +44,72 @@ prepare_storage() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait_for_service() {
|
||||||
|
local name="$1" host="$2" port="$3" timeout="$4"
|
||||||
|
local start
|
||||||
|
start=$(date +%s)
|
||||||
|
|
||||||
|
echo "[entrypoint] Waiting for ${name} at ${host}:${port} (timeout ${timeout}s)..."
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if exec 3<>"/dev/tcp/${host}/${port}" 2>/dev/null; then
|
||||||
|
exec 3>&- 3<&-
|
||||||
|
echo "[entrypoint] ${name} is available."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( $(date +%s) - start >= timeout )); then
|
||||||
|
echo "[entrypoint] Timeout while waiting for ${name}." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_for_dependencies() {
|
||||||
|
local should_wait_db="false"
|
||||||
|
|
||||||
|
case "${DB_CONNECTION:-sqlite}" in
|
||||||
|
mysql|mariadb)
|
||||||
|
should_wait_db="true"
|
||||||
|
DB_HOST=${DB_HOST:-mysql}
|
||||||
|
DB_PORT=${DB_PORT:-3306}
|
||||||
|
;;
|
||||||
|
pgsql)
|
||||||
|
should_wait_db="true"
|
||||||
|
DB_HOST=${DB_HOST:-postgres}
|
||||||
|
DB_PORT=${DB_PORT:-5432}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ "${WAIT_FOR_DB:-$should_wait_db}" == "true" && "$should_wait_db" == "true" ]]; then
|
||||||
|
wait_for_service "database" "$DB_HOST" "$DB_PORT" "$DB_WAIT_TIMEOUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local should_wait_redis="false"
|
||||||
|
if [[ "${QUEUE_CONNECTION:-}" == redis* ]]; then
|
||||||
|
should_wait_redis="true"
|
||||||
|
fi
|
||||||
|
if [[ "${CACHE_DRIVER:-}" == redis ]]; then
|
||||||
|
should_wait_redis="true"
|
||||||
|
fi
|
||||||
|
if [[ "${SESSION_DRIVER:-}" == redis ]]; then
|
||||||
|
should_wait_redis="true"
|
||||||
|
fi
|
||||||
|
if [[ "${FORCE_WAIT_FOR_REDIS:-false}" == "true" ]]; then
|
||||||
|
should_wait_redis="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${WAIT_FOR_REDIS:-$should_wait_redis}" == "true" && "$should_wait_redis" == "true" ]]; then
|
||||||
|
wait_for_service "redis" "${REDIS_HOST:-redis}" "${REDIS_PORT:-6379}" "$REDIS_WAIT_TIMEOUT"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
sync_code
|
sync_code
|
||||||
ensure_helper_scripts
|
ensure_helper_scripts
|
||||||
prepare_storage
|
prepare_storage
|
||||||
|
wait_for_dependencies
|
||||||
|
|
||||||
cd "$APP_TARGET"
|
cd "$APP_TARGET"
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user