# a minimal Dockerfile for CI
ARG KICAD_VERSION=9.0.6
FROM ghcr.io/kicad/kicad:${KICAD_VERSION}

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PATH=/venv/bin:/root/.local/bin:$PATH

ENV UV_LINK_MODE=copy
ENV UV_COMPILE_BYTECODE=1
ENV UV_HTTP_TIMEOUT=300

# build all targets
ENV NONINTERACTIVE=1
ENV ATO_TARGET="all"
ENV ATO_FROZEN=1
ENV ATO_VIA_DOCKER=1

# We use root for this container, despite the permission-turds
# since it's all Github actions currently supports.
# In the future we might consider creating a distinct github-actions
# container to reconcile this with other more standard CI systems.
# FIXME: consider something like this instead:
# https://github.com/myoung34/docker-github-actions-runner/pull/223
USER root

WORKDIR /opt/atopile

RUN <<EORUN
chown -R kicad:kicad /opt/atopile

# We need to set the github workspace as a safe directory according
# to git so we can get version information like the githash from it
# Safety doesnt apply, as a single user system https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9
git config --global --add safe.directory '*'
EORUN

COPY --from=ghcr.io/astral-sh/uv:0.8 /uv /bin/uv

# Pre-download Python 3.14 (KiCad image has Python 3.11)
RUN uv python install 3.14

COPY --chown=kicad:kicad dist/atopile-*-cp314-cp314-manylinux*.whl /tmp/

RUN uv tool install --python 3.14 /tmp/atopile-*-cp314-cp314-manylinux*.whl

ENTRYPOINT ["ato"]

CMD ["build"]
