Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

# ===============================
Expand All @@ -61,19 +71,18 @@ 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"; \
echo "opcache.revalidate_freq=2"; \
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"]