diff --git a/docker-compose.override.yml b/docker-compose.override.yml deleted file mode 100644 index 1e5c23d9..00000000 --- a/docker-compose.override.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3.9' - -services: - nginx: - # Use HTTP-only Nginx config for local development - volumes: - - ./services/nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro - # Expose only port 80 locally; HTTPS (443) not needed in dev - ports: - - "80:80" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index d4eccaf3..16471b50 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -8,13 +8,14 @@ services: ports: - "80:80" - "443:443" - - # Remove public exposure of internal datastores in production - db: - ports: [] - redis: ports: [] + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s ## Usage (examples): ## - With explicit files (recommended): diff --git a/services/php/Dockerfile b/services/php/Dockerfile index 437da7df..ae0332d0 100644 --- a/services/php/Dockerfile +++ b/services/php/Dockerfile @@ -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"] \ No newline at end of file diff --git a/services/php/docker-entrypoint.sh b/services/php/docker-entrypoint.sh index 9e720cac..34ee78e4 100644 --- a/services/php/docker-entrypoint.sh +++ b/services/php/docker-entrypoint.sh @@ -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 "$@"