FROM python:3.11-slim

RUN apt-get update -qq && \
    apt-get install -y -q --no-install-recommends git && \
    rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir requests fastapi "uvicorn[standard]" pydantic

ENV GIT_AUTHOR_NAME=outline-sync \
    GIT_AUTHOR_EMAIL=sync@local \
    GIT_COMMITTER_NAME=outline-sync \
    GIT_COMMITTER_EMAIL=sync@local \
    VAULT_DIR=/vault \
    SETTINGS_PATH=/work/settings.json

RUN git config --global user.email "sync@local" && \
    git config --global user.name "outline-sync"

ARG APP_VERSION=dev
ENV APP_VERSION=${APP_VERSION}

WORKDIR /work

COPY outline_sync.py webui.py entrypoint.sh VERSION ./
RUN chmod +x entrypoint.sh

# Initialise vault with both branches needed by outline_sync.py
RUN git init /vault && \
    git -C /vault checkout -b main && \
    touch /vault/.gitkeep && \
    git -C /vault add .gitkeep && \
    git -C /vault commit -m "init: empty vault" && \
    git -C /vault checkout -b outline && \
    git -C /vault checkout main

EXPOSE 8080

ENTRYPOINT ["/work/entrypoint.sh"]
CMD ["uvicorn", "webui:app", "--host", "0.0.0.0", "--port", "8080"]
