FROM php:8.2-apache

RUN docker-php-ext-install curl && \
    a2enmod rewrite

COPY . /var/www/html/
COPY docker/docker-entrypoint.sh /usr/local/bin/gridtv-entrypoint.sh

RUN mkdir -p /data && \
    chown -R www-data:www-data /var/www/html /data && \
    find /var/www/html -type d -exec chmod 755 {} \; && \
    find /var/www/html -type f -exec chmod 644 {} \; && \
    chmod 755 /usr/local/bin/gridtv-entrypoint.sh

HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
  CMD php -r "exit(@file_get_contents('http://127.0.0.1/') === false ? 1 : 0);"

ENTRYPOINT ["gridtv-entrypoint.sh"]
CMD ["apache2-foreground"]

EXPOSE 80
