-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
66 lines (50 loc) · 2 KB
/
Dockerfile.prod
File metadata and controls
66 lines (50 loc) · 2 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
# Build stage
FROM python:3.12-slim AS builder
WORKDIR /app
# Faster compilation from source
RUN export MAKEFLAGS="-j$(nproc)"
RUN export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
# Install required packages for building
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends git bash gdal-bin libgdal-dev g++
# Install dependencies
COPY requirements.txt ./
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade pip && \
pip install -v -r requirements.txt
# Reinstall correct version of GDAL
RUN pip install -v --no-build-isolation --no-cache-dir --force-reinstall gdal==$(gdal-config --version)
# First copy only blackmarble requirements and install (this ensures efficient layer caching)
COPY ./blackmarblepy/requirements.txt ./requirements.blackmarblepy.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.blackmarblepy.txt
# Copy over Blackmarble package and install
COPY .gitmodules ./
COPY .git/modules/blackmarblepy .git/modules/blackmarblepy
COPY ./blackmarblepy ./blackmarblepy
RUN --mount=type=cache,target=/root/.cache/pip \
pip install ./blackmarblepy
# Production stage
FROM python:3.12-slim AS production
WORKDIR /app
# Install runtime dependencies only
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends gdal-bin
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy source files
COPY src src
# Copy static files
COPY static/ static/
WORKDIR /app/src
ENV HOST=0.0.0.0
ENV PORT=8000
ENV DISABLE_NEST_ASYNCIO=True
EXPOSE 8000
# Production command without reload
CMD ["fastapi", "run", "api/main.py", "--host", "0.0.0.0", "--port", "8000"]