FROM odoo:18.0

USER root

# Copy requirements and install Python dependencies
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install --break-system-packages --no-cache-dir --ignore-installed typing-extensions -r /tmp/requirements.txt

# Copy addons
COPY ./addons /mnt/extra-addons

# Copy production configuration
COPY ./config/odoo.prod.conf /etc/odoo/odoo.conf

# Set proper permissions
RUN chown -R odoo:odoo /mnt/extra-addons

# Install Infisical CLI
RUN apt-get update && apt-get install -y curl && \
    curl -1sLf 'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' | bash && \
    apt-get install -y infisical && \
    rm -rf /var/lib/apt/lists/*

USER odoo

# Use Infisical to inject env vars and start Odoo with DB config
CMD infisical run -- /bin/bash -c 'odoo --db_host="$ODOO_DB_HOST" --db_port="$ODOO_DB_PORT" --db_user="$ODOO_DB_USER" --db_password="$ODOO_DB_PASSWORD" --database="$ODOO_DB_NAME"'
