-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (41 loc) · 1.85 KB
/
Dockerfile
File metadata and controls
56 lines (41 loc) · 1.85 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
# Development
# docker build --no-cache -t filesync --load .
# docker build --no-cache --platform linux/amd64 -t filesync --output=type=docker,dest=filesync.tar .
# ==============================
# Stage 1: Build Python dependencies
# ==============================
FROM python:3.14-alpine AS builder
# Install build dependencies
RUN apk add --no-cache --virtual .build-deps build-base libffi-dev musl-dev python3-dev
WORKDIR /filesync
# Copy requirements
COPY api/requirements.txt .
# Install Python dependencies to a separate location
RUN pip install --no-cache-dir --prefer-binary --upgrade pip setuptools wheel \
&& pip install --no-cache-dir --prefix=/install -r requirements.txt
# Optional: remove tests and unnecessary files from site-packages
RUN find /install/lib/ -path "*/site-packages/tests" -type d -exec rm -rf {} + \
&& find /install/lib/ -name "*.pyc" -delete \
&& find /install/lib/ -name "*.pyo" -delete \
&& find /install/lib/ -name "*.so" -exec strip --strip-unneeded {} +
# ==============================
# Stage 2: Runtime image
# ==============================
FROM python:3.14-alpine
# Install Nginx runtime
RUN apk add --no-cache nginx
WORKDIR /filesync
# Copy Python dependencies from builder
COPY --from=builder /install /usr/local
# Copy app code
COPY api /filesync/api
COPY --chown=nginx:nginx web /filesync/web
# Copy Nginx config
COPY nginx.conf /etc/nginx/http.d/default.conf
# Health check: verify nginx (/) and backend (/health) are both responding
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO /dev/null http://127.0.0.1/ && wget -qO /dev/null http://127.0.0.1:8000/health
# Expose ports
EXPOSE 80
# Start FastAPI + Nginx
CMD ["sh", "-c", "python3 -m uvicorn api.main:app --host 0.0.0.0 --port 8000 & nginx -g 'daemon off;'"]