# 基礎映像：Ubuntu 24.04
FROM ubuntu:24.04

# 環境變數
# 設定 Node 版本為 24
ARG NODE_VERSION=24
ENV TZ="Asia/Taipei"
ENV LANG=zh_TW.UTF-8
ENV LC_ALL=zh_TW.UTF-8
WORKDIR /var/www/html

# 安裝系統基礎工具
RUN apt-get update && apt-get install -y \
    software-properties-common ca-certificates lsb-release apt-transport-https \
    zip unzip git curl vim wget cron locales supervisor \
    apache2 apache2-utils \
    mysql-client \
    python3 \
    && rm -rf /var/lib/apt/lists/*

# 設定 Locale
RUN locale-gen zh_TW.UTF-8 && update-locale LANG=zh_TW.UTF-8

# 安裝 PHP 8.3 與常用擴充
RUN add-apt-repository ppa:ondrej/php \
    && apt-get update && apt-get install -y \
    php8.3-fpm php8.3-curl php8.3-mbstring php8.3-gd php8.3-zip php8.3-xml \
    php8.3-bcmath php8.3-ldap php8.3-mysql php8.3-sqlite3 php8.3-opcache \
    && a2dismod mpm_prefork \
    && a2enmod mpm_event proxy_fcgi setenvif rewrite headers http2 ssl \
    && a2enconf php8.3-fpm \
    && rm -rf /var/lib/apt/lists/*

# 安裝 Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
    --install-dir=/usr/local/bin --filename=composer

# 安裝 Node.js 24 LTS
# 使用 NodeSource 官方腳本安裝
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
    && apt-get install -y nodejs \
    && npm install -g pnpm \
    && rm -rf /var/lib/apt/lists/*

# 複製 設定檔
COPY ./conf/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY ./conf/supervisord.conf /etc/supervisor/supervisord.conf
COPY ./conf/web.conf /etc/supervisor/conf.d/web.conf

# 啟用 Apache 站台
RUN a2ensite 000-default.conf

# 啟動 Supervisor
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]

EXPOSE 80
