-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
272 lines (218 loc) · 6.48 KB
/
Copy pathDockerfile
File metadata and controls
272 lines (218 loc) · 6.48 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# syntax=docker/dockerfile:1
FROM python:3.12-alpine3.22 AS builder
LABEL maintainer="OpenDroneMap Developers <maintainers@opendronemap.org>"
# Build-time variables
ARG WORKDIR=/webui
# Run-time variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=$WORKDIR
ENV PROJ_LIB=/usr/share/proj
# Create and change into working directory
WORKDIR $WORKDIR
# Allow multi-line runs, break on errors and output commands for debugging
SHELL ["sh", "-exc"]
RUN echo "UTC" > /etc/timezone
#### BUILD STAGE ####
# Install build dependencies and runtime dependencies
RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
<<EOT
# Enable community and testing repos for PDAL
echo "https://dl-cdn.alpinelinux.org/alpine/v3.24/main" > /etc/apk/repositories
echo "https://dl-cdn.alpinelinux.org/alpine/v3.24/community" >> /etc/apk/repositories
# Update package index
apk update
# Upgrade packages
apk upgrade
apk upgrade -alv
# Build dependencies
apk add --no-cache \
build-base \
cmake \
ninja \
git \
curl \
ca-certificates \
bash \
coreutils
# Install libexecinfo from Alpine 3.16 (removed in 3.17+)
apk add --no-cache --update --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ \
libexecinfo-dev \
libexecinfo
# Geospatial libraries
apk add --no-cache \
gdal \
gdal-dev \
gdal-tools \
gdal-driver-png \
gdal-driver-jpeg \
gdal-driver-webp \
pdal \
pdal-dev \
proj \
proj-dev \
proj-util \
geos \
geos-dev \
sqlite \
sqlite-dev \
py3-shapely
# PostgreSQL
apk add --no-cache \
postgresql-dev \
postgresql-client
# Python development
apk add --no-cache \
python3-dev
# Image libraries for Pillow
apk add --no-cache \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
zlib-dev \
tiff-dev
# System utilities
apk add --no-cache \
nginx \
dcron \
tzdata \
gettext \
gettext-dev
# Node.js and npm
apk add --no-cache \
nodejs \
npm
EOT
# Build Entwine from source (using latest version for PDAL 2.8+ compatibility)
RUN --mount=type=cache,target=/root/.cache,sharing=locked \
<<EOT
mkdir /staging && cd /staging
git clone https://github.com/connormanning/entwine && cd entwine
git checkout 3.2.1
mkdir build && cd build
cmake .. \
-G Ninja \
-DWITH_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=/staging/entwine/build/install \
-DCMAKE_BUILD_TYPE=Release
ninja -j$(nproc)
ninja install
cd $WORKDIR
EOT
# Create virtualenv
RUN python3 -m venv $WORKDIR/venv
# Modify PATH to prioritize venv, effectively activating venv
ENV PATH="$WORKDIR/venv/bin:$PATH"
# Copy requirements first for better caching
COPY requirements.txt ./
# Upgrade pip and install Python dependencies
RUN --mount=type=cache,target=/root/.cache/pip \
<<EOT
pip install --upgrade pip setuptools wheel
# Install GDAL Python bindings matching system GDAL version
GDAL_VERSION=$(gdal-config --version)
pip install "gdal[numpy]==${GDAL_VERSION}.*"
# Install requirements (will be updated separately)
pip install -r requirements.txt
# Install additional geospatial packages
pip install "boto3>=1.34.0"
EOT
# Install project Node dependencies
COPY package.json package-lock.json* ./
RUN --mount=type=cache,target=/root/.npm \
<<EOT
npm install --quiet
# Install webpack and webpack CLI globally
npm install --quiet -g webpack@5.89.0 webpack-cli@5.1.4
EOT
# Copy remaining files
COPY . ./
# Defining this here allows for caching of previous layers
ARG TEST_BUILD
# Final build steps
RUN <<EOT
# Setup cron
chmod 0644 ./nginx/crontab
mkdir -p /var/spool/cron/crontabs
ln -sf $WORKDIR/nginx/crontab /var/spool/cron/crontabs/root
mkdir -p external/NodeODM
# NodeODM setup
chmod +x ./nginx/letsencrypt-autogen.sh
./nodeodm/setup.sh
./nodeodm/cleanup.sh
# Run webpack build
webpack --mode production
# Django setup
python manage.py collectstatic --noinput
python manage.py rebuildplugins
# python manage.py translate build --safe
# Remove auto-generated secret key
rm -f /webui/webui/secret_key.py
EOT
#### RUNTIME STAGE ####
FROM python:3.12-alpine3.22 AS runtime
ARG WORKDIR=/webui
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=$WORKDIR
ENV PROJ_LIB=/usr/share/proj
ENV PATH="$WORKDIR/venv/bin:$PATH"
WORKDIR $WORKDIR
SHELL ["sh", "-exc"]
# Install only runtime dependencies
RUN --mount=type=cache,target=/var/cache/apk,sharing=locked \
<<EOT
echo "UTC" > /etc/timezone
# Enable community repo
echo "https://dl-cdn.alpinelinux.org/alpine/v3.24/main" > /etc/apk/repositories
echo "https://dl-cdn.alpinelinux.org/alpine/v3.24/community" >> /etc/apk/repositories
# Update package index
apk update
# Upgrade packages
apk upgrade
apk upgrade -alv
# Runtime dependencies only
apk add --no-cache \
bash \
coreutils \
curl \
ca-certificates \
gdal \
gdal-tools \
gdal-driver-png \
gdal-driver-jpeg \
gdal-driver-webp \
pdal \
proj \
proj-util \
geos \
sqlite \
postgresql-client \
nginx \
dcron \
tzdata \
gettext \
nodejs \
npm \
git \
libjpeg-turbo \
libpng \
libwebp \
tiff \
py3-shapely
# Install libexecinfo from Alpine 3.16 (removed in 3.17+)
apk add --no-cache --update --repository=https://dl-cdn.alpinelinux.org/alpine/v3.16/main/ \
libexecinfo
# Install webpack globally (needed for dev mode)
npm install --quiet -g webpack@5.89.0 webpack-cli@5.1.4
# Cleanup
rm -rf /var/cache/apk/* /tmp/* /var/tmp/*
EOT
# Copy virtualenv from builder
COPY --from=builder $WORKDIR/venv $WORKDIR/venv
# Make system packages (py3-shapely) accessible to venv
RUN echo "/usr/lib/python3.12/site-packages" > $WORKDIR/venv/lib/python3.12/site-packages/system-packages.pth
# Copy Entwine binary and libraries
COPY --from=builder /staging/entwine/build/install/bin/entwine /usr/bin/entwine
COPY --from=builder /staging/entwine/build/install/lib/libentwine* /usr/lib/
# Copy application code and built assets
COPY --from=builder $WORKDIR $WORKDIR
VOLUME /webui/app/media