forked from jphacks/tk_a_2515
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.deploy
More file actions
108 lines (82 loc) · 3.41 KB
/
Dockerfile.deploy
File metadata and controls
108 lines (82 loc) · 3.41 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Global build arguments (shared across stages)
# =============================================================================
ARG FRONTEND_PORT=3400
ARG BACKEND_PORT=8200
# Stage 1: Frontend Build
# =============================================================================
FROM node:24-bookworm-slim AS frontend-builder
ARG FRONTEND_PORT
ARG BACKEND_PORT
ENV DEBIAN_FRONTEND=noninteractive
RUN corepack enable && corepack prepare pnpm@10.24.0 --activate
WORKDIR /build
COPY frontend/package.json frontend/pnpm-lock.yaml frontend/pnpm-workspace.yaml* ./
# Cache pnpm store across builds
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY frontend/ ./
# NEXT_PUBLIC_* variables for build-time injection
ARG NEXT_PUBLIC_FULL_URL
ARG NEXT_PUBLIC_BACKEND_URL
ARG NEXT_PUBLIC_BASE_PATH
ENV NEXT_PUBLIC_FULL_URL=${NEXT_PUBLIC_FULL_URL:-http://localhost:${FRONTEND_PORT}/peak-sight}
ENV NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL:-http://localhost:${BACKEND_PORT}}
ENV NEXT_PUBLIC_BASE_PATH=${NEXT_PUBLIC_BASE_PATH:-/peak-sight}
RUN pnpm build
# Stage 2: Backend Build
# =============================================================================
FROM python:3.12-slim-bookworm AS backend-builder
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app/backend
COPY backend/pyproject.toml backend/uv.lock ./
# Cache uv downloads across builds
RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen
COPY backend/ ./
# Stage 3: Final All-in-One Image
# =============================================================================
FROM python:3.12-slim-bookworm
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app/backend \
REDIS_URL="redis://localhost:6379"
# Combine package installs to minimize layers and clear cache
RUN apt-get update && apt-get install --no-install-recommends -y \
postgresql-15 postgresql-15-postgis-3 \
redis-server \
supervisor \
curl \
screen \
gdal-bin libgdal-dev libgeos-dev libproj-dev binutils \
&& curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
&& apt-get install -y nodejs \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Detection and symlinking for architecture-independent GDAL/GEOS paths
RUN for lib in gdal geos_c; do \
LIB_PATH=$(find /usr/lib -name "lib${lib}.so*" | head -1); \
ln -sf "$LIB_PATH" "/usr/lib/lib${lib}.so"; \
done
ENV GDAL_LIBRARY_PATH=/usr/lib/libgdal.so \
GEOS_LIBRARY_PATH=/usr/lib/libgeos_c.so
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
# 1. Backend & dependencies
COPY --from=backend-builder /app/backend /app/backend
# 2. Frontend Standalone
COPY --from=frontend-builder /build/.next/standalone /app/frontend
COPY --from=frontend-builder /build/.next/static /app/frontend/.next/static
COPY --from=frontend-builder /build/public /app/frontend/public
# 3. Entrypoint and Supervisor
COPY entrypoint.sh /app/entrypoint.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x /app/entrypoint.sh
# Dynamic ports from build args
ARG FRONTEND_PORT
ARG BACKEND_PORT
ENV PORT=${FRONTEND_PORT} \
API_PORT=${BACKEND_PORT}
EXPOSE ${FRONTEND_PORT} ${BACKEND_PORT}
CMD ["/app/entrypoint.sh"]