FROM wordpress:6.7.2-php8.3-apache

# Install WP-CLI and dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
        less \
        default-mysql-client \
        unzip \
    && curl -sL -o /usr/local/bin/wp \
       https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
    && chmod +x /usr/local/bin/wp \
    && rm -rf /var/lib/apt/lists/*

# Pre-install the p2 theme.
# p2 turns WordPress into a real-time microblog stream (Twitter-like) —
# intentionally weird for a traditional blog context.
RUN curl -sL https://downloads.wordpress.org/theme/p2.zip -o /tmp/p2.zip \
    && unzip -q /tmp/p2.zip -d /var/www/html/wp-content/themes/ \
    && rm /tmp/p2.zip \
    && chown -R www-data:www-data /var/www/html/wp-content/themes/p2

# Tell WordPress it's behind an HTTPS reverse proxy
ENV WORDPRESS_CONFIG_EXTRA="if (isset(\$_SERVER['HTTP_X_FORWARDED_PROTO']) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { \$_SERVER['HTTPS'] = 'on'; }"

# Blog identity — baked into the image, overridable at runtime
ENV WORDPRESS_BLOG_TITLE="ATI Training"
ENV WORDPRESS_BLOG_TAGLINE="advanced training intelligence"
ENV WORDPRESS_ADMIN_USER="admin"
ENV WORDPRESS_ADMIN_EMAIL="peterson@sent.com"
ENV WORDPRESS_ACTIVE_THEME="p2"
ENV WORDPRESS_SITEURL="https://atitraining.coldairnetworks.com"

COPY wp-init-bg.sh /usr/local/bin/wp-init-bg.sh
COPY entrypoint.sh /usr/local/bin/atitraining-entrypoint.sh
RUN chmod +x /usr/local/bin/wp-init-bg.sh /usr/local/bin/atitraining-entrypoint.sh

ENTRYPOINT ["/usr/local/bin/atitraining-entrypoint.sh"]
CMD ["apache2-foreground"]
