-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (57 loc) · 2.04 KB
/
Dockerfile
File metadata and controls
71 lines (57 loc) · 2.04 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# syntax=docker/dockerfile:1
FROM python:3.11-slim
# Accept build-time version metadata (optional)
ARG SF_APP_VERSION_SHORT
ARG SF_APP_VERSION_HASH
ARG SF_APP_VERSION_BRANCH
ARG SF_APP_VERSION_DATE
# Set environment
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PORT=8080 \
SF_DATA_PATH=/data \
SF_REPO_PATH=/data/datarepo \
SF_APP_VERSION_SHORT=${SF_APP_VERSION_SHORT} \
SF_APP_VERSION_HASH=${SF_APP_VERSION_HASH} \
SF_APP_VERSION_BRANCH=${SF_APP_VERSION_BRANCH} \
SF_APP_VERSION_DATE=${SF_APP_VERSION_DATE}
# Install system dependencies (git, curl for healthcheck)
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Copy only requirements first for better layer caching
COPY requirements.txt ./requirements.txt
COPY web/requirements.txt ./web/requirements.txt
# Install Python dependencies
RUN pip install --upgrade pip && \
pip install -r requirements.txt -r web/requirements.txt
# Copy the rest of the source
COPY . .
# Bake version metadata file for runtime (if args provided)
RUN set -e; \
V_SHORT="${SF_APP_VERSION_SHORT}"; \
V_HASH="${SF_APP_VERSION_HASH}"; \
V_BRANCH="${SF_APP_VERSION_BRANCH}"; \
V_DATE="${SF_APP_VERSION_DATE}"; \
if [ -n "${V_SHORT}${V_HASH}${V_BRANCH}${V_DATE}" ]; then \
printf '{\n "short": "%s",\n "hash": "%s",\n "branch": "%s",\n "date": "%s"\n}\n' \
"${V_SHORT}" "${V_HASH}" "${V_BRANCH}" "${V_DATE}" \
> /app/.app_version.json; \
fi
# Create a non-root user and ensure writable dirs
RUN useradd -u 10001 -m sf && \
mkdir -p /data /data/datarepo && \
chown -R sf:sf /app /data
# Copy entrypoint
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
USER sf
EXPOSE 8080
# Healthcheck: basic GET on root (adjust as needed)
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -fsS http://127.0.0.1:${PORT}/ || exit 1
ENTRYPOINT ["/entrypoint.sh"]