diff --git a/Dockerfile b/Dockerfile index c69dba0..2b834c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,18 @@ FROM python:3.12-slim AS builder WORKDIR /build -RUN pip install poetry +# Install system build dependencies (required for ARM & C-extension packages) +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + gcc \ + libffi-dev \ + libssl-dev \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# Upgrade pip & install Poetry +RUN pip install --upgrade pip setuptools wheel && pip install poetry + COPY pyproject.toml poetry.lock ./ RUN poetry install --no-root @@ -18,8 +29,8 @@ RUN poetry run python3 main.py --env prod # =============================== FROM php:8.4-apache -# Install cron -RUN apt-get update && apt-get install -y cron \ +# Install cron and cleanup +RUN apt-get update && apt-get install -y --no-install-recommends cron \ && rm -rf /var/lib/apt/lists/* # Enable Apache rewrite module @@ -30,23 +41,22 @@ RUN mkdir -p /var/www/crondns/data /var/www/crondns/lib /var/www/crondns/public /var/lib/php/sessions WORKDIR /var/www/crondns -# Copy Python-built files +# Copy built Python artifacts COPY --from=builder /build/dist/ /var/www/crondns/ -# Copy Apache vhost +# Configure Apache site COPY apache-crondns.conf /etc/apache2/sites-available/crondns.conf RUN a2dissite 000-default.conf && a2ensite crondns.conf -# Make everything writable for PHP/Apache +# Permissions RUN chown -R www-data:www-data /var/www/crondns /var/lib/php/sessions \ && chmod -R 775 /var/www/crondns -# Copy cron job +# Add cron job COPY crondns.cron /etc/cron.d/crondns -RUN chmod 0644 /etc/cron.d/crondns \ - && crontab /etc/cron.d/crondns +RUN chmod 0644 /etc/cron.d/crondns && crontab /etc/cron.d/crondns -# Set DocumentRoot only to public/ +# Restrict DocumentRoot RUN sed -i 's|DocumentRoot /var/www/html|DocumentRoot /var/www/crondns/public|g' /etc/apache2/sites-available/crondns.conf # =============================== @@ -61,7 +71,6 @@ RUN { \ echo "zlib.output_compression=Off"; \ } > /usr/local/etc/php/conf.d/custom.ini -# Configure OPcache exactly like host RUN { \ echo "opcache.enable=1"; \ echo "opcache.memory_consumption=128"; \ @@ -69,11 +78,11 @@ RUN { \ echo "opcache.validate_timestamps=On"; \ } > /usr/local/etc/php/conf.d/opcache.ini -# Expose port EXPOSE 80 -# Entrypoint script to run cron + apache +# Entrypoint COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh RUN chmod +x /usr/local/bin/docker-entrypoint.sh ENTRYPOINT ["docker-entrypoint.sh"] +