# syntax=docker/dockerfile:1

# ---------------------------------------------------------------------------
# Hotel Management System - self-contained production image.
#
# One container runs:
#   * MariaDB (bound to 127.0.0.1 only; schema + demo seed imported on first
#     boot, data persisted in /var/lib/mysql)
#   * the PHP application (front controller via public/router.php) listening
#     on 0.0.0.0:${PORT} (platform-injected; default 8080)
#
# All configuration is read from environment variables (APP_*, DB_*,
# PAYSTACK_*, HUBTEL_*, MAIL_*, SMS_*) - the app's Env class checks the
# process environment, so no .env file is shipped in the image.
# ---------------------------------------------------------------------------

# ---- Stage 1: PHP dependencies (real Composer autoloader + PHPMailer) ------
# --ignore-platform-reqs: the composer image lacks pdo_mysql (installed in
# the runtime stage), which composer.json declares as a platform requirement.
FROM composer:2 AS deps
WORKDIR /build
COPY composer.json ./
RUN composer install --no-dev --optimize-autoloader --no-interaction --no-progress --ignore-platform-reqs

# ---- Stage 2: runtime -------------------------------------------------------
FROM php:8.2-cli

# pdo_mysql for the app; MariaDB so the published site is fully functional
# without an external database service (localhost-only, not exposed).
RUN docker-php-ext-install pdo_mysql \
 && apt-get update \
 && apt-get install -y --no-install-recommends mariadb-server mariadb-client \
 && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY . .
COPY --from=deps /build/vendor ./vendor

# Writable runtime dirs (logs, uploads).
RUN mkdir -p storage/logs public/uploads \
 && chmod -R a+rwX storage public/uploads

ENV PORT=8080 \
    APP_ENV=production \
    APP_TIMEZONE=Africa/Accra \
    DB_HOST=127.0.0.1 \
    DB_PORT=3306 \
    DB_NAME=hms \
    DB_USER=hms \
    PHP_CLI_SERVER_WORKERS=4

EXPOSE 8080

# The initial container process MUST be an ELF binary: some runtimes cannot
# load a shell script as PID 1. php is ELF; entrypoint.php is plain data.
ENTRYPOINT ["/usr/local/bin/php", "/app/docker/entrypoint.php"]
