FROM python:3.12-slim

LABEL org.opencontainers.image.title="AssetManager" \
      org.opencontainers.image.description="Self-hosted asset management with optional MeshCentral integration" \
      org.opencontainers.image.authors="Roland Reich" \
      org.opencontainers.image.licenses="Apache-2.0"

WORKDIR /opt/meshcentral
RUN apt-get update \
    && apt-get install -y --no-install-recommends nodejs npm ca-certificates postgresql-client \
    && rm -rf /var/lib/apt/lists/* \
    && npm install --omit=dev meshcentral \
    && chown -R root:root /opt/meshcentral

WORKDIR /app
COPY requirements.txt .
COPY tools/export_dependency_licenses.py /tmp/export_dependency_licenses.py
RUN pip install --no-cache-dir -r requirements.txt \
    && python /tmp/export_dependency_licenses.py \
         --output /app/THIRD_PARTY_LICENSES \
         --node-modules /opt/meshcentral/node_modules \
    && rm /tmp/export_dependency_licenses.py

COPY app ./app
COPY VERSION LICENSE.txt THIRD_PARTY_NOTICES.md ./
COPY APPINFO.json /app/default-config/APPINFO.json
COPY docker-entrypoint.sh /usr/local/bin/assetmanager-entrypoint
RUN chmod +x /usr/local/bin/assetmanager-entrypoint \
    && mkdir -p /app/app/static/uploads /app/config /app/data/logs/sync /app/data/logs/diagnostics /data/backups

HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
    CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/api/software-callback/health', timeout=3).read()"]

ENTRYPOINT ["/usr/local/bin/assetmanager-entrypoint"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
