源文件
app/Dockerfile
离线配置。未部署到任何云账号。
# Insights API image for the fictional Thistle Analytics demo.
# Multi-stage, digest-pinned, non-root. make check does not build or push this image.
FROM python:3.12-slim@sha256:05cda9777409a9c3ffddd94a4c476b79f0769a0b4857f0c7ed9226b6800b0d6f AS build
WORKDIR /src
COPY pyproject.toml README.md ./
COPY insights_api ./insights_api
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir .
FROM python:3.12-slim@sha256:05cda9777409a9c3ffddd94a4c476b79f0769a0b4857f0c7ed9226b6800b0d6f
LABEL org.opencontainers.image.source="https://example.invalid/thistle-analytics/insights-api"
LABEL org.opencontainers.image.title="insights-api"
LABEL org.opencontainers.image.description="Fictional Thistle Analytics insights API. Not deployed to any cloud account."
RUN useradd --uid 10001 --create-home --shell /usr/sbin/nologin appuser
WORKDIR /app
COPY --from=build /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=build /usr/local/bin/uvicorn /usr/local/bin/uvicorn
USER 10001
EXPOSE 8080
ENV PORT=8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/healthz', timeout=2).read()"]
ENTRYPOINT ["uvicorn", "insights_api.main:app", "--host", "0.0.0.0", "--port", "8080"]