Repository navigation
Expand file tree
/
Copy pathDockerfile.vercel
More file actions
38 lines (33 loc) · 1.75 KB
/
Copy pathDockerfile.vercel
File metadata and controls
38 lines (33 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# The scoring API as a Vercel container function. Only the scoring path's packages go in, from
# their sources; the exported bundles in results/models go in beside them. Vercel routes to port 80
# unless PORT is set in the project.
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PYTHONPATH=/app/src \
FRICTION_MODELS=/app/models \
PORT=80
RUN apt-get update \
&& apt-get install -y --no-install-recommends libgomp1 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY packages/api/requirements-serving.txt /app/requirements.txt
RUN pip install --require-hashes --no-deps --only-binary :all: -r /app/requirements.txt \
&& find /usr/local/lib/python3.12 -name "tests" -type d -prune -exec rm -rf {} + \
&& find /usr/local/lib/python3.12 -name "*.pyc" -delete
COPY packages/core/src/friction_core /app/src/friction_core
COPY packages/features/src/friction_features /app/src/friction_features
COPY packages/models/src/friction_models /app/src/friction_models
COPY packages/policy/src/friction_policy /app/src/friction_policy
COPY packages/reasons/src/friction_reasons /app/src/friction_reasons
COPY packages/api/src/friction_api /app/src/friction_api
COPY results/models /app/models
RUN useradd --create-home --uid 10001 friction
USER friction
EXPOSE 80
# For a local docker run; Vercel has its own check. The slim image has no curl, so Python asks.
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD python -c "import os, urllib.request; urllib.request.urlopen('http://127.0.0.1:' + os.environ.get('PORT', '80') + '/health', timeout=4)"
CMD ["sh", "-c", "uvicorn friction_api.main:app --host 0.0.0.0 --port ${PORT} --proxy-headers --forwarded-allow-ips='*'"]