Add Redis healthchecks and startup wait in PHP entrypoint
- Introduce Redis healthchecks in `docker-compose.prod.yml` for better container monitoring. - Extend PHP Dockerfile with `redis-tools` and enable Composer dependency auto-install. - Update `docker-entrypoint.sh` to wait for Redis readiness before starting PHP-FPM. - Remove local Nginx override and simplify development setup.
This commit is contained in:
@@ -27,6 +27,7 @@ RUN set -eux; \
|
||||
unzip \
|
||||
git \
|
||||
curl \
|
||||
redis-tools \
|
||||
libzip-dev \
|
||||
libssl-dev \
|
||||
ca-certificates \
|
||||
@@ -62,11 +63,11 @@ ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Copy and enable entrypoint that installs Composer deps on first run
|
||||
#COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
#RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Expose port 9000
|
||||
EXPOSE 9000
|
||||
|
||||
#ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
CMD ["php-fpm"]
|
||||
@@ -11,6 +11,32 @@ AUTO_COMPOSER_INSTALL="${AUTO_COMPOSER_INSTALL:-true}"
|
||||
|
||||
log() { printf "[entrypoint] %s\n" "$*"; }
|
||||
|
||||
wait_for_redis() {
|
||||
host="${REDIS_CONFIG_HOST:-redis}"
|
||||
port="${REDIS_CONFIG_PORT:-6379}"
|
||||
pass="${REDIS_CONFIG_PASSWORD:-}"
|
||||
timeout="${REDIS_WAIT_TIMEOUT:-60}"
|
||||
i=0
|
||||
|
||||
log "Waiting for Redis at ${host}:${port} (timeout: ${timeout}s) ..."
|
||||
while [ "$i" -lt "$timeout" ]; do
|
||||
if [ -n "$pass" ]; then
|
||||
if redis-cli -h "$host" -p "$port" -a "$pass" PING >/dev/null 2>&1; then
|
||||
log "Redis is ready"
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
if redis-cli -h "$host" -p "$port" PING >/dev/null 2>&1; then
|
||||
log "Redis is ready"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
sleep 1; i=$((i+1))
|
||||
done
|
||||
log "ERROR: Timed out waiting for Redis at ${host}:${port}"
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_file() {
|
||||
target="$1"; timeout="${2:-120}"; i=0
|
||||
while [ "$i" -lt "$timeout" ]; do
|
||||
@@ -75,4 +101,9 @@ else
|
||||
log "AUTO_COMPOSER_INSTALL=false — skipping Composer auto-install"
|
||||
fi
|
||||
|
||||
# Wait for Redis before starting PHP-FPM (if host is defined)
|
||||
if [ -n "${REDIS_CONFIG_HOST:-}" ]; then
|
||||
wait_for_redis
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
|
||||
Reference in New Issue
Block a user