forked from OpenDroneMap/WebODM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
186 lines (162 loc) · 7.07 KB
/
Dockerfile
File metadata and controls
186 lines (162 loc) · 7.07 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
# syntax=docker/dockerfile:1
FROM ubuntu:22.04 AS common
LABEL maintainer="Piero Toffanin <pt@masseranolabs.com>"
# Build-time variables
ARG DEBIAN_FRONTEND=noninteractive
ARG NODE_MAJOR=20
ARG PYTHON_VERSION=3.9
ARG RELEASE_CODENAME=jammy
ARG WORKDIR=/webodm
# Run-time variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=$WORKDIR
ENV PROJ_LIB=/usr/share/proj
#### Common setup ####
# Create and change into working directory
WORKDIR $WORKDIR
# Allow multi-line runs, break on errors and output commands for debugging.
# The following does not work in Podman unless you build in Docker
# compatibility mode: <https://github.com/containers/podman/issues/8477>
# You can manually prepend every RUN script with `set -ex` too.
SHELL ["sh", "-exc"]
RUN <<EOT
# Common system configuration, should change very infrequently
# Set timezone to UTC
echo "UTC" > /etc/timezone
EOT
FROM common AS build
# Install Python deps -- install & remove cleanup build-only deps in the process
COPY requirements.txt ./
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
<<EOT
# Build-time dependencies
rm -rf /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*
apt-get -qq update
apt-get install -y --no-install-recommends curl ca-certificates gnupg
# Python 3.9 support
curl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf23c5a6cf475977595c89f51ba6932366a755776' | gpg --dearmor -o /etc/apt/trusted.gpg.d/deadsnakes.gpg
echo "deb http://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu $RELEASE_CODENAME main" > /etc/apt/sources.list.d/deadsnakes.list
# Node.js deb source
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/nodesource.gpg
echo "deb https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" > /etc/apt/sources.list.d/nodesource.list
# Update package list
apt-get update
# Install common deps, starting with NodeJS
apt-get -qq install -y -o APT::Keep-Downloaded-Packages=false nodejs
# Python3.9, GDAL, PDAL, nginx, letsencrypt, psql
apt-get install -y --no-install-recommends -o APT::Keep-Downloaded-Packages=false \
python$PYTHON_VERSION python$PYTHON_VERSION-venv python$PYTHON_VERSION-dev libpq-dev build-essential git libproj-dev gdal-bin pdal \
libgdal-dev nginx certbot gettext-base cron postgresql-client gettext tzdata
# Create virtualenv
python$PYTHON_VERSION -m venv $WORKDIR/venv
# Clean up apt caches to keep cache mount small
apt-get clean
rm -rf /var/lib/apt/lists/*
EOT
# Modify PATH to prioritize venv, effectively activating venv
ENV PATH="$WORKDIR/venv/bin:$PATH"
RUN --mount=type=cache,target=/root/.cache/pip \
<<EOT
# Install Python dependencies
# Install pip
pip install pip==24.0
# Install Python requirements, including correct Python GDAL bindings.
pip install -r requirements.txt "boto3==1.14.14" gdal[numpy]=="$(gdal-config --version).*"
EOT
# Install project Node dependencies
COPY package.json ./
RUN --mount=type=cache,target=/root/.npm \
<<EOT
npm install --quiet
# Clear npm cache to avoid filling the build cache volume (prevents ENOSPC)
npm cache clean --force
# Install webpack, webpack CLI
npm install --quiet -g webpack@5.89.0
npm install --quiet -g webpack-cli@5.1.4
EOT
# Copy remaining files
COPY . ./
# Apply Tapis OAuth2 integration fixes
RUN <<EOT
# Make scripts executable
if [ -f scripts/setup_tapis_oauth2.py ]; then
chmod +x scripts/setup_tapis_oauth2.py
echo "✓ Made Tapis setup script executable"
fi
if [ -f scripts/entrypoint-tapis.sh ]; then
chmod +x scripts/entrypoint-tapis.sh
echo "✓ Made Tapis entrypoint script executable"
fi
# Temporarily exclude OAuth2 models and admin during build (will be re-enabled at runtime)
if [ -f app/models/__init__.py ]; then
sed -i 's/^from \.oauth2 import/#TAPIS_TEMP_DISABLE#from \.oauth2 import/' app/models/__init__.py
echo "✓ Temporarily disabled OAuth2 models for build compatibility"
fi
if [ -f app/admin.py ]; then
sed -i 's/^from \.admin\.oauth2 import/#TAPIS_TEMP_DISABLE#from \.admin\.oauth2 import/' app/admin.py
echo "✓ Temporarily disabled OAuth2 admin for build compatibility"
fi
EOT
# Defining this here allows for caching of previous layers.
ARG TEST_BUILD
RUN <<EOT
# Final build steps (in one roll to prevent too many layers).
# Setup cron
chmod 0644 ./nginx/crontab
ln -s ./nginx/crontab /var/spool/cron/crontabs/root
# NodeODM setup
chmod +x ./nginx/letsencrypt-autogen.sh
./nodeodm/setup.sh
./nodeodm/cleanup.sh
# Run webpack build, Django setup and final cleanup
webpack --mode production
# Django setup
rm -rf /webodm/build
mkdir -p /webodm/build/static
python manage.py collectstatic --noinput
python manage.py rebuildplugins
python manage.py translate build --safe
# Final cleanup
# Remove stale temp files
rm -rf /tmp/* /var/tmp/*
# Remove auto-generated secret key (happens on import of settings when none is defined)
rm -f /webodm/webodm/secret_key.py
EOT
FROM common AS app
# Modify PATH to prioritize venv, effectively activating venv
ENV PATH="$WORKDIR/venv/bin:$PATH"
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=cache,target=/root/.npm \
<<EOT
# Run-time dependencies
rm -rf /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*
apt-get -qq update
apt-get install -y --no-install-recommends curl ca-certificates gnupg
# Legacy Python support
curl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf23c5a6cf475977595c89f51ba6932366a755776' | gpg --dearmor -o /etc/apt/trusted.gpg.d/deadsnakes.gpg
echo "deb http://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu $RELEASE_CODENAME main" > /etc/apt/sources.list.d/deadsnakes.list
# Node.js deb source
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/nodesource.gpg
echo "deb https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" > /etc/apt/sources.list.d/nodesource.list
# Update package list
apt-get update
# Install common deps, starting with NodeJS
apt-get -qq install -y -o APT::Keep-Downloaded-Packages=false nodejs
# Python, GDAL, PDAL, nginx, letsencrypt, psql, git
apt-get install -y --no-install-recommends -o APT::Keep-Downloaded-Packages=false \
python$PYTHON_VERSION python$PYTHON_VERSION-distutils gdal-bin pdal \
nginx certbot gettext-base cron postgresql-client gettext tzdata git
# Install webpack, webpack CLI
npm install --quiet -g webpack@5.89.0
npm install --quiet -g webpack-cli@5.1.4
# Cleanup of build requirements
apt-get autoremove -y
apt-get clean
rm -rf /var/lib/apt/lists/*
# Remove stale temp files
rm -rf /tmp/* /var/tmp/*
EOT
COPY --from=build $WORKDIR ./
VOLUME /webodm/app/media