FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive
ENV FLAMENCO_VERSION=3.8

RUN apt-get update && apt-get install -y --no-install-recommends \
    wget ca-certificates ffmpeg python3 python3-pip python3-venv \
    libgl1 libglib2.0-0 libxrender1 libsm6 libxext6 \
    libegl1 libgles2 \
    && rm -rf /var/lib/apt/lists/*

# Install Flamenco binary
RUN mkdir -p /opt/flamenco && \
    wget -qO /tmp/flamenco.tar.gz \
      "https://flamenco.blender.org/downloads/flamenco-${FLAMENCO_VERSION}-linux-amd64.tar.gz" && \
    tar -xzf /tmp/flamenco.tar.gz -C /opt/flamenco --strip-components=1 && \
    rm /tmp/flamenco.tar.gz

# Install cadquery for STEP→STL conversion
RUN python3 -m venv /opt/venv && \
    /opt/venv/bin/pip install --no-cache-dir cadquery

WORKDIR /opt/flamenco

COPY entrypoint.sh /opt/flamenco/entrypoint.sh
COPY manager-config.yaml /opt/flamenco/flamenco-manager.yaml
COPY worker-config.yaml /opt/flamenco/flamenco-worker.yaml
COPY scripts/ /opt/flamenco/scripts/

RUN chmod +x /opt/flamenco/entrypoint.sh

# Shared storage for render outputs
VOLUME ["/shared", "/data"]

EXPOSE 8080

ENTRYPOINT ["/opt/flamenco/entrypoint.sh"]
