# syntax=docker/dockerfile:1.7
FROM ollama/ollama:0.40.19 AS tailscale
ARG TARGETARCH
ARG TAILSCALE_VERSION=1.104.7
ARG TAILSCALE_SHA256=e56693ff74a64f2591b7e819c280635a100aae1ddfb0ef058fcd052b7cd8d16c
RUN if [ "$TARGETARCH" != amd64 ]; then echo 'This image supports linux/amd64 only (TARGETARCH must be amd64).' >&2; exit 1; fi
ADD --checksum=sha256:${TAILSCALE_SHA256} https://pkgs.tailscale.com/stable/tailscale_${TAILSCALE_VERSION}_amd64.tgz /tmp/tailscale.tgz
RUN mkdir -p /opt/tailscale && tar -xzf /tmp/tailscale.tgz -C /opt/tailscale --strip-components=1 \
    "tailscale_${TAILSCALE_VERSION}_amd64/tailscale" \
    "tailscale_${TAILSCALE_VERSION}_amd64/tailscaled"

FROM ollama/ollama:0.40.19
ARG IMAGE_VERSION=dev
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
COPY --from=tailscale /opt/tailscale/tailscale /opt/tailscale/tailscaled /usr/local/bin/
COPY --chmod=0755 entrypoint.sh /usr/local/bin/llmstarter-entrypoint
ENV OLLAMA_HOST=127.0.0.1:11434 OLLAMA_MODELS=/workspace/ollama/models
LABEL org.opencontainers.image.source="https://github.com/kcherry497/runpod-llm-starter" \
      org.opencontainers.image.licenses="MIT" \
      org.opencontainers.image.description="Ollama for RunPod GPU pods with private Tailscale userspace networking" \
      org.opencontainers.image.title="runpod-llm-starter-ollama" \
      org.opencontainers.image.version="${IMAGE_VERSION}"
STOPSIGNAL SIGTERM
ENTRYPOINT ["/usr/local/bin/llmstarter-entrypoint"]
CMD []
