FROM python:3.11-slim

ENV TZ=Europe/Berlin

# Install system packages + Node.js
RUN apt-get update && \
    apt-get install -y curl gnupg cron nginx ffmpeg tzdata git && \
    curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

# Create working dir
WORKDIR /app

# Copy all files into the container
COPY . .

# Install Python deps
RUN pip install --no-cache-dir -r requirements.txt

# Install Node.js deps (for server.js)
RUN npm install

# Set execution permissions
RUN chmod +x daily_producer.py

# Configure cron
COPY cronjob /etc/cron.d/daily-task
RUN chmod 0644 /etc/cron.d/daily-task && crontab /etc/cron.d/daily-task

# Configure nginx
COPY nginx.conf /etc/nginx/sites-available/default

# Expose nginx port
EXPOSE 80

# Create logs
RUN touch /app/logs.txt

# Copy start script and make it executable
COPY start.sh /start.sh
RUN chmod +x /start.sh

# Replace CMD with start script
CMD ["/start.sh"]