Make the image smaller (#214)
* Update Dockerfile * Add comment * rm debs after install * Get ready for buildkit * Update Dockerfile * Cleanup indenting * Update Dockerfile * Update Dockerfile * Install certificates required for downloads Co-authored-by: Alexander Overvoorde <overv161@gmail.com>
This commit is contained in:
parent
0a4d079b08
commit
4b93ca3e52
336
Dockerfile
336
Dockerfile
@ -1,185 +1,213 @@
|
||||
FROM ubuntu:20.04
|
||||
FROM ubuntu:20.04 AS compiler-common
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
git-core \
|
||||
checkinstall \
|
||||
g++ \
|
||||
make \
|
||||
tar \
|
||||
wget \
|
||||
ca-certificates
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM compiler-common AS compiler-postgis
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
postgresql-server-dev-12 \
|
||||
libxml2-dev \
|
||||
libgeos-dev \
|
||||
libproj-dev
|
||||
RUN wget https://download.osgeo.org/postgis/source/postgis-3.1.1.tar.gz -O postgis.tar.gz \
|
||||
&& mkdir -p postgis_src \
|
||||
&& tar -xvzf postgis.tar.gz --strip 1 -C postgis_src \
|
||||
&& rm postgis.tar.gz \
|
||||
&& cd postgis_src \
|
||||
&& ./configure --without-protobuf --without-raster \
|
||||
&& make -j $(nproc) \
|
||||
&& checkinstall --pkgversion="3.1.1" --install=no --default make install
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM compiler-common AS compiler-osm2pgsql
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
cmake \
|
||||
libboost-dev \
|
||||
libboost-system-dev \
|
||||
libboost-filesystem-dev \
|
||||
libexpat1-dev \
|
||||
zlib1g-dev \
|
||||
libbz2-dev \
|
||||
libpq-dev \
|
||||
libproj-dev \
|
||||
lua5.3 \
|
||||
liblua5.3-dev \
|
||||
pandoc
|
||||
RUN cd ~ \
|
||||
&& git clone -b master --single-branch https://github.com/openstreetmap/osm2pgsql.git --depth 1 \
|
||||
&& cd osm2pgsql \
|
||||
&& mkdir build \
|
||||
&& cd build \
|
||||
&& cmake .. \
|
||||
&& make -j $(nproc) \
|
||||
&& checkinstall --pkgversion="1" --install=no --default make install
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM compiler-common AS compiler-modtile-renderd
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
apache2-dev \
|
||||
automake \
|
||||
autoconf \
|
||||
autotools-dev \
|
||||
libtool \
|
||||
libmapnik-dev
|
||||
RUN cd ~ \
|
||||
&& git clone -b switch2osm --single-branch https://github.com/SomeoneElseOSM/mod_tile.git --depth 1 \
|
||||
&& cd mod_tile \
|
||||
&& ./autogen.sh \
|
||||
&& ./configure \
|
||||
&& make -j $(nproc) \
|
||||
&& checkinstall --pkgversion="1" --install=no --pkgname "renderd" --default make install \
|
||||
&& checkinstall --pkgversion="1" --install=no --pkgname "mod_tile" --default make install-mod_tile
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM compiler-common AS compiler-stylesheet
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
npm
|
||||
RUN cd ~ \
|
||||
&& git clone --single-branch --branch v5.3.1 https://github.com/gravitystorm/openstreetmap-carto.git --depth 1 \
|
||||
&& cd openstreetmap-carto \
|
||||
&& sed -ie 's#https:\/\/naciscdn.org\/naturalearth\/110m\/cultural\/ne_110m_admin_0_boundary_lines_land.zip#https:\/\/naturalearth.s3.amazonaws.com\/110m_cultural\/ne_110m_admin_0_boundary_lines_land.zip#g' external-data.yml \
|
||||
&& npm install -g carto@0.18.2 \
|
||||
&& carto project.mml > mapnik.xml
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM compiler-common AS compiler-helper-script
|
||||
RUN mkdir -p /home/renderer/src \
|
||||
&& cd /home/renderer/src \
|
||||
&& git clone https://github.com/zverik/regional \
|
||||
&& cd regional \
|
||||
&& git checkout 889d630a1e1a1bacabdd1dad6e17b49e7d58cd4b \
|
||||
&& rm -rf .git \
|
||||
&& chmod u+x /home/renderer/src/regional/trim_osc.py
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM ubuntu:20.04 AS final-base
|
||||
|
||||
# Based on
|
||||
# https://switch2osm.org/serving-tiles/manually-building-a-tile-server-18-04-lts/
|
||||
|
||||
# Set up environment
|
||||
ENV TZ=UTC
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV AUTOVACUUM=on
|
||||
ENV UPDATES=disabled
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
# Install dependencies
|
||||
# Get packages
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y wget gnupg2 lsb-core apt-transport-https ca-certificates curl \
|
||||
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
|
||||
&& echo "deb [ trusted=yes ] https://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list \
|
||||
&& wget --quiet -O - https://deb.nodesource.com/setup_14.x | bash - \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y nodejs
|
||||
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
apache2 \
|
||||
apache2-dev \
|
||||
autoconf \
|
||||
build-essential \
|
||||
bzip2 \
|
||||
cmake \
|
||||
cron \
|
||||
fonts-noto-cjk \
|
||||
fonts-noto-hinted \
|
||||
fonts-noto-unhinted \
|
||||
gcc \
|
||||
gdal-bin \
|
||||
git-core \
|
||||
libagg-dev \
|
||||
libboost-filesystem-dev \
|
||||
libboost-system-dev \
|
||||
libbz2-dev \
|
||||
libcairo-dev \
|
||||
libcairomm-1.0-dev \
|
||||
libexpat1-dev \
|
||||
libfreetype6-dev \
|
||||
libgdal-dev \
|
||||
libgeos++-dev \
|
||||
libgeos-dev \
|
||||
libicu-dev \
|
||||
liblua5.3-dev \
|
||||
libmapnik-dev \
|
||||
libpq-dev \
|
||||
libproj-dev \
|
||||
libprotobuf-c-dev \
|
||||
libtiff5-dev \
|
||||
libtool \
|
||||
libxml2-dev \
|
||||
lua5.3 \
|
||||
make \
|
||||
mapnik-utils \
|
||||
osmium-tool \
|
||||
osmosis \
|
||||
postgis \
|
||||
postgresql-12 \
|
||||
postgresql-contrib-12 \
|
||||
postgresql-server-dev-12 \
|
||||
protobuf-c-compiler \
|
||||
python-is-python3 \
|
||||
python3-mapnik \
|
||||
python3-lxml \
|
||||
python3-psycopg2 \
|
||||
python3-shapely \
|
||||
python3-pip \
|
||||
sudo \
|
||||
tar \
|
||||
ttf-unifont \
|
||||
unzip \
|
||||
wget \
|
||||
zlib1g-dev \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
apache2 \
|
||||
cron \
|
||||
fonts-noto-cjk \
|
||||
fonts-noto-hinted \
|
||||
fonts-noto-unhinted \
|
||||
gdal-bin \
|
||||
liblua5.3-dev \
|
||||
lua5.3 \
|
||||
mapnik-utils \
|
||||
osmium-tool \
|
||||
osmosis \
|
||||
postgresql-12 \
|
||||
python-is-python3 \
|
||||
python3-mapnik \
|
||||
python3-lxml \
|
||||
python3-psycopg2 \
|
||||
python3-shapely \
|
||||
python3-pip \
|
||||
sudo \
|
||||
ttf-unifont \
|
||||
wget \
|
||||
&& apt-get clean autoclean \
|
||||
&& apt-get autoremove --yes \
|
||||
&& rm -rf /var/lib/{apt,dpkg,cache,log}/
|
||||
|
||||
# Install python libraries
|
||||
RUN pip3 install requests \
|
||||
&& pip3 install pyyaml
|
||||
|
||||
# Set up PostGIS
|
||||
RUN wget https://download.osgeo.org/postgis/source/postgis-3.1.1.tar.gz -O postgis.tar.gz \
|
||||
&& mkdir -p postgis_src \
|
||||
&& tar -xvzf postgis.tar.gz --strip 1 -C postgis_src \
|
||||
&& rm postgis.tar.gz \
|
||||
&& cd postgis_src \
|
||||
&& ./configure \
|
||||
&& make -j $(nproc) \
|
||||
&& make -j $(nproc) install \
|
||||
&& cd .. && rm -rf postgis_src
|
||||
|
||||
# Set up renderer user
|
||||
RUN adduser --disabled-password --gecos "" renderer
|
||||
|
||||
# Install latest osm2pgsql
|
||||
RUN mkdir -p /home/renderer/src \
|
||||
&& cd /home/renderer/src \
|
||||
&& git clone -b master https://github.com/openstreetmap/osm2pgsql.git --depth 1 \
|
||||
&& cd /home/renderer/src/osm2pgsql \
|
||||
&& rm -rf .git \
|
||||
&& mkdir build \
|
||||
&& cd build \
|
||||
&& cmake .. \
|
||||
&& make -j $(nproc) \
|
||||
&& make -j $(nproc) install \
|
||||
&& mkdir /nodes \
|
||||
&& chown renderer:renderer /nodes \
|
||||
&& rm -rf /home/renderer/src/osm2pgsql
|
||||
|
||||
# Install mod_tile and renderd
|
||||
RUN mkdir -p /home/renderer/src \
|
||||
&& cd /home/renderer/src \
|
||||
&& git clone -b switch2osm https://github.com/SomeoneElseOSM/mod_tile.git --depth 1 \
|
||||
&& cd mod_tile \
|
||||
&& rm -rf .git \
|
||||
&& ./autogen.sh \
|
||||
&& ./configure \
|
||||
&& make -j $(nproc) \
|
||||
&& make -j $(nproc) install \
|
||||
&& make -j $(nproc) install-mod_tile \
|
||||
&& ldconfig \
|
||||
&& cd ..
|
||||
|
||||
# Configure stylesheet
|
||||
RUN mkdir -p /home/renderer/src \
|
||||
&& cd /home/renderer/src \
|
||||
&& git clone --single-branch --branch v5.3.1 https://github.com/gravitystorm/openstreetmap-carto.git --depth 1 \
|
||||
&& cd openstreetmap-carto \
|
||||
&& rm -rf .git \
|
||||
&& sed -ie 's#https:\/\/naciscdn.org\/naturalearth\/110m\/cultural\/ne_110m_admin_0_boundary_lines_land.zip#https:\/\/naturalearth.s3.amazonaws.com\/110m_cultural\/ne_110m_admin_0_boundary_lines_land.zip#g' external-data.yml \
|
||||
&& npm install -g carto@0.18.2 \
|
||||
&& carto project.mml > mapnik.xml
|
||||
|
||||
# Configure renderd
|
||||
RUN sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf \
|
||||
&& sed -i 's/\/truetype//g' /usr/local/etc/renderd.conf \
|
||||
&& sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf
|
||||
# Install python libraries
|
||||
RUN pip3 install \
|
||||
requests \
|
||||
pyyaml
|
||||
|
||||
# Configure Apache
|
||||
RUN mkdir /var/lib/mod_tile \
|
||||
&& chown renderer /var/lib/mod_tile \
|
||||
&& mkdir /var/run/renderd \
|
||||
&& chown renderer /var/run/renderd \
|
||||
&& echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \
|
||||
&& echo "LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so" >> /etc/apache2/conf-available/mod_headers.conf \
|
||||
&& a2enconf mod_tile && a2enconf mod_headers
|
||||
&& chown renderer /var/lib/mod_tile \
|
||||
&& mkdir /var/run/renderd \
|
||||
&& chown renderer /var/run/renderd \
|
||||
&& echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \
|
||||
&& echo "LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so" >> /etc/apache2/conf-available/mod_headers.conf \
|
||||
&& a2enconf mod_tile && a2enconf mod_headers
|
||||
COPY apache.conf /etc/apache2/sites-available/000-default.conf
|
||||
COPY leaflet-demo.html /var/www/html/index.html
|
||||
RUN ln -sf /dev/stdout /var/log/apache2/access.log \
|
||||
&& ln -sf /dev/stderr /var/log/apache2/error.log
|
||||
|
||||
# Configure PosgtreSQL
|
||||
COPY postgresql.custom.conf.tmpl /etc/postgresql/12/main/
|
||||
RUN chown -R postgres:postgres /var/lib/postgresql \
|
||||
&& chown postgres:postgres /etc/postgresql/12/main/postgresql.custom.conf.tmpl \
|
||||
&& echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/12/main/pg_hba.conf \
|
||||
&& echo "host all all ::/0 md5" >> /etc/postgresql/12/main/pg_hba.conf
|
||||
&& ln -sf /dev/stderr /var/log/apache2/error.log
|
||||
|
||||
# Copy update scripts
|
||||
COPY openstreetmap-tiles-update-expire /usr/bin/
|
||||
RUN chmod +x /usr/bin/openstreetmap-tiles-update-expire \
|
||||
&& mkdir /var/log/tiles \
|
||||
&& chmod a+rw /var/log/tiles \
|
||||
&& ln -s /home/renderer/src/mod_tile/osmosis-db_replag /usr/bin/osmosis-db_replag \
|
||||
&& echo "* * * * * renderer openstreetmap-tiles-update-expire\n" >> /etc/crontab
|
||||
&& mkdir /var/log/tiles \
|
||||
&& chmod a+rw /var/log/tiles \
|
||||
&& ln -s /home/renderer/src/mod_tile/osmosis-db_replag /usr/bin/osmosis-db_replag \
|
||||
&& echo "* * * * * renderer openstreetmap-tiles-update-expire\n" >> /etc/crontab
|
||||
|
||||
# Install trim_osc.py helper script
|
||||
RUN mkdir -p /home/renderer/src \
|
||||
&& cd /home/renderer/src \
|
||||
&& git clone https://github.com/zverik/regional \
|
||||
&& cd regional \
|
||||
&& git checkout 889d630a1e1a1bacabdd1dad6e17b49e7d58cd4b \
|
||||
&& rm -rf .git \
|
||||
&& chmod u+x /home/renderer/src/regional/trim_osc.py
|
||||
RUN mkdir /nodes \
|
||||
&& chown renderer:renderer /nodes
|
||||
|
||||
# Configure PosgtreSQL
|
||||
COPY postgresql.custom.conf.tmpl /etc/postgresql/12/main/
|
||||
RUN chown -R postgres:postgres /var/lib/postgresql \
|
||||
&& chown postgres:postgres /etc/postgresql/12/main/postgresql.custom.conf.tmpl \
|
||||
&& echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/12/main/pg_hba.conf \
|
||||
&& echo "host all all ::/0 md5" >> /etc/postgresql/12/main/pg_hba.conf
|
||||
|
||||
###########################################################################################################
|
||||
|
||||
FROM final-base AS final
|
||||
|
||||
# Install PostGIS
|
||||
COPY --from=compiler-postgis postgis_src/postgis-src_3.1.1-1_amd64.deb .
|
||||
RUN dpkg -i postgis-src_3.1.1-1_amd64.deb \
|
||||
&& rm postgis-src_3.1.1-1_amd64.deb
|
||||
|
||||
# Install osm2pgsql
|
||||
COPY --from=compiler-osm2pgsql /root/osm2pgsql/build/build_1-1_amd64.deb .
|
||||
RUN dpkg -i build_1-1_amd64.deb \
|
||||
&& rm build_1-1_amd64.deb
|
||||
|
||||
# Install renderd
|
||||
COPY --from=compiler-modtile-renderd /root/mod_tile/renderd_1-1_amd64.deb .
|
||||
RUN dpkg -i renderd_1-1_amd64.deb \
|
||||
&& rm renderd_1-1_amd64.deb \
|
||||
&& sed -i 's/renderaccount/renderer/g' /usr/local/etc/renderd.conf \
|
||||
&& sed -i 's/\/truetype//g' /usr/local/etc/renderd.conf \
|
||||
&& sed -i 's/hot/tile/g' /usr/local/etc/renderd.conf
|
||||
|
||||
# Install mod_tile
|
||||
COPY --from=compiler-modtile-renderd /root/mod_tile/mod-tile_1-1_amd64.deb .
|
||||
RUN dpkg -i mod-tile_1-1_amd64.deb \
|
||||
&& ldconfig \
|
||||
&& rm mod-tile_1-1_amd64.deb
|
||||
|
||||
# Install stylesheet
|
||||
COPY --from=compiler-stylesheet /root/openstreetmap-carto /home/renderer/src/openstreetmap-carto
|
||||
|
||||
# Install helper script
|
||||
COPY --from=compiler-helper-script /home/renderer/src/regional /home/renderer/src/regional
|
||||
|
||||
# Start running
|
||||
COPY run.sh /
|
||||
ENTRYPOINT ["/run.sh"]
|
||||
CMD []
|
||||
|
||||
EXPOSE 80 5432
|
||||
|
Loading…
Reference in New Issue
Block a user