forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
196 lines (175 loc) · 6.78 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1
##
# osgeo/gdal:alpine-small
# This file is available at the option of the licensee under:
# Public domain
# or licensed under MIT (LICENSE.TXT) Copyright 2019 Even Rouault <[email protected]>
ARG ALPINE_VERSION=3.20
FROM alpine:${ALPINE_VERSION} AS builder
# Derived from osgeo/proj by Howard Butler <[email protected]>
LABEL maintainer="Even Rouault <[email protected]>"
ENV HOME="/root"
# Setup build env for PROJ
RUN apk add --no-cache wget curl unzip make libtool autoconf automake pkgconfig g++ sqlite sqlite-dev
# For PROJ and GDAL
RUN apk add --no-cache \
ccache \
cmake ninja-build \
linux-headers \
curl-dev tiff-dev \
zlib-dev zstd-dev lz4-dev libdeflate-dev libarchive-dev \
libjpeg-turbo-dev libpng-dev libwebp-dev expat-dev \
postgresql-dev \
rsync \
openjpeg-dev
# Ninja is not in the default path on Alpine.
ENV PATH=/usr/lib/ninja-build/bin:$PATH
# Build openjpeg
#ARG OPENJPEG_VERSION=2.3.1
RUN if test "${OPENJPEG_VERSION}" != ""; then ( \
curl -LO -fsS https://github.com/uclouvain/openjpeg/archive/v${OPENJPEG_VERSION}.tar.gz \
&& tar xzf v${OPENJPEG_VERSION}.tar.gz \
&& rm -f v${OPENJPEG_VERSION}.tar.gz \
&& cd openjpeg-${OPENJPEG_VERSION} \
&& cmake . -G Ninja -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
&& ninja \
&& ninja install \
&& mkdir -p /build_thirdparty/usr/lib \
&& cp -P /usr/lib/libopenjp2*.so* /build_thirdparty/usr/lib \
&& for i in /build_thirdparty/usr/lib/*; do strip -s $i 2>/dev/null || /bin/true; done \
&& cd .. \
&& rm -rf openjpeg-${OPENJPEG_VERSION} \
); fi
ARG PROJ_DATUMGRID_LATEST_LAST_MODIFIED
RUN \
mkdir -p /build_projgrids/usr/share/proj \
&& curl -LO -fsS http://download.osgeo.org/proj/proj-datumgrid-latest.zip \
&& unzip -q -j -u -o proj-datumgrid-latest.zip -d /build_projgrids/usr/share/proj \
&& rm -f *.zip
ARG RSYNC_REMOTE
ARG WITH_CCACHE
# Build PROJ
ARG PROJ_VERSION=master
RUN --mount=type=cache,id=alpine-small-proj,target=$HOME/.cache \
mkdir proj \
&& curl -L -fsS https://github.com/OSGeo/PROJ/archive/${PROJ_VERSION}.tar.gz \
| tar xz -C proj --strip-components=1 \
&& cd proj \
&& if test "${RSYNC_REMOTE}" != ""; then \
echo "Downloading cache..."; \
rsync -ra ${RSYNC_REMOTE}/proj/$(uname -m)/ $HOME/.cache/; \
echo "Finished"; \
fi \
&& if [ -n "${WITH_CCACHE:-}" ]; then \
export CC="ccache gcc"; \
export CXX="ccache g++"; \
export PROJ_DB_CACHE_PARAM="-DPROJ_DB_CACHE_DIR=$HOME/.cache"; \
ccache -M 100M; \
fi \
# IPO disabled since it crashes with gcc 13.2.1
&& cmake . \
-G Ninja \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DENABLE_IPO=OFF \
-DBUILD_TESTING=OFF \
$PROJ_DB_CACHE_PARAM \
&& ninja \
&& ninja install \
&& DESTDIR="/build_proj" ninja install \
&& if test "${RSYNC_REMOTE}" != ""; then \
echo "Uploading cache..."; \
rsync -ra --delete $HOME/.cache/ ${RSYNC_REMOTE}/proj/$(uname -m)/; \
echo "Finished"; \
fi \
&& if [ -n "${WITH_CCACHE:-}" ]; then \
ccache -s; \
unset CC; \
unset CXX; \
fi \
&& cd .. \
&& rm -rf proj \
&& for i in /build_proj/usr/lib/*; do strip -s $i 2>/dev/null || /bin/true; done \
&& for i in /build_proj/usr/bin/*; do strip -s $i 2>/dev/null || /bin/true; done
# Build GDAL
ARG GDAL_VERSION=master
ARG GDAL_RELEASE_DATE
ARG GDAL_BUILD_IS_RELEASE
ARG GDAL_REPOSITORY=OSGeo/gdal
RUN --mount=type=cache,id=alpine-small-gdal,target=$HOME/.cache \
if test "${GDAL_VERSION}" = "master"; then \
export GDAL_VERSION=$(curl -Ls https://api.github.com/repos/${GDAL_REPOSITORY}/commits/HEAD -H "Accept: application/vnd.github.VERSION.sha"); \
export GDAL_RELEASE_DATE=$(date "+%Y%m%d"); \
fi \
&& if test "x${GDAL_BUILD_IS_RELEASE}" = "x"; then \
export GDAL_SHA1SUM=${GDAL_VERSION}; \
fi \
&& if test "${RSYNC_REMOTE}" != ""; then \
echo "Downloading cache..."; \
rsync -ra ${RSYNC_REMOTE}/gdal/$(uname -m)/ $HOME/.cache/; \
echo "Finished"; \
fi \
&& if [ -n "${WITH_CCACHE:-}" ]; then \
export CC="ccache gcc"; \
export CXX="ccache g++"; \
ccache -M 1G; \
fi \
&& mkdir gdal \
&& curl -L -fsS https://github.com/${GDAL_REPOSITORY}/archive/${GDAL_VERSION}.tar.gz \
| tar xz -C gdal --strip-components=1 \
&& cd gdal \
&& mkdir build \
&& cd build \
&& cmake .. \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DGDAL_USE_TIFF_INTERNAL=ON \
-DGDAL_USE_GEOTIFF_INTERNAL=ON \
-DBUILD_TESTING=OFF \
&& ninja \
&& DESTDIR="/build" ninja install \
&& cd .. \
&& if test "${RSYNC_REMOTE}" != ""; then \
echo "Uploading cache..."; \
rsync -ra --delete $HOME/.cache/ ${RSYNC_REMOTE}/gdal/$(uname -m)/; \
echo "Finished"; \
fi \
&& if [ -n "${WITH_CCACHE:-}" ]; then \
ccache -s; \
unset CC; \
unset CXX; \
fi \
&& cd .. \
&& rm -rf gdal \
&& mkdir -p /build_gdal_version_changing/usr/include \
&& mv /build/usr/lib /build_gdal_version_changing/usr \
&& mv /build/usr/include/gdal_version.h /build_gdal_version_changing/usr/include \
&& mv /build/usr/bin /build_gdal_version_changing/usr \
&& for i in /build_gdal_version_changing/usr/lib/*; do strip -s $i 2>/dev/null || /bin/true; done \
&& for i in /build_gdal_version_changing/usr/bin/*; do strip -s $i 2>/dev/null || /bin/true; done
# Build final image
FROM alpine:${ALPINE_VERSION} AS runner
RUN date
RUN apk add --no-cache \
libstdc++ \
sqlite-libs \
libcurl tiff \
zlib zstd-libs lz4-libs libdeflate libarchive \
libjpeg-turbo libpng openjpeg libwebp expat libpq \
# libturbojpeg.so is not used by GDAL. Only libjpeg.so*
&& rm -f /usr/lib/libturbojpeg.so* \
# Only libwebp.so is used by GDAL
&& rm -f /usr/lib/libwebpmux.so* /usr/lib/libwebpdemux.so* /usr/lib/libwebpdecoder.so*
# Order layers starting with less frequently varying ones
#COPY --from=builder /build_thirdparty/usr/ /usr/
COPY --from=builder /build_projgrids/usr/ /usr/
COPY --from=builder /build_proj/usr/share/proj/ /usr/share/proj/
COPY --from=builder /build_proj/usr/include/ /usr/include/
COPY --from=builder /build_proj/usr/bin/ /usr/bin/
COPY --from=builder /build_proj/usr/lib/ /usr/lib/
COPY --from=builder /build/usr/share/gdal/ /usr/share/gdal/
COPY --from=builder /build/usr/include/ /usr/include/
COPY --from=builder /build_gdal_version_changing/usr/ /usr/