Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current versions, carto, map.html #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 33 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,36 @@
# <http://switch2osm.org/serving-tiles/manually-building-a-tile-server-12-04/>.
#

FROM phusion/baseimage:0.9.11
FROM phusion/baseimage:latest
MAINTAINER Homme Zwaagstra <[email protected]>

# Set the locale. This affects the encoding of the Postgresql template
# databases.
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
RUN update-locale LANG=C.UTF-8

# Ensure `add-apt-repository` is present
RUN apt-get update -y
RUN apt-get install -y software-properties-common python-software-properties

RUN apt-get install -y libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-system-dev libboost-thread-dev

# Install remaining dependencies
RUN apt-get install -y subversion git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libpq-dev libbz2-dev munin-node munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev libpng12-dev libtiff4-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont

RUN apt-get install -y autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libgdal1-dev mapnik-utils python-mapnik libmapnik-dev

# Install postgresql and postgis
RUN apt-get install -y postgresql-9.3-postgis-2.1 postgresql-contrib postgresql-server-dev-9.3
# install needed packages & mapnik
RUN apt-get -y update && \
apt-get -y install libboost-all-dev git-core tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev libpng12-dev libtiff5-dev libicu-dev libgdal-dev libcairo-dev libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg sudo && \
apt-get -y install postgresql postgresql-contrib postgis postgresql-9.5-postgis-2.2 && \
apt-get -y install make cmake g++ libboost-dev libboost-system-dev libboost-filesystem-dev libexpat1-dev zlib1g-dev libbz2-dev libpq-dev libgeos-dev libgeos++-dev libproj-dev lua5.2 liblua5.2-dev && \
apt-get -y install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libgdal1-dev libmapnik-dev mapnik-utils python-mapnik && \
apt-get -y install npm nodejs-legacy && \
apt-get -y install fonts-noto && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /usr/share/doc && \
rm -rf /usr/share/man


# Install osm2pgsql
RUN cd /tmp && git clone git://github.com/openstreetmap/osm2pgsql.git
RUN cd /tmp/osm2pgsql && \
./autogen.sh && \
./configure && \
make && make install

# Install the Mapnik library
RUN cd /tmp && git clone git://github.com/mapnik/mapnik
RUN cd /tmp/mapnik && \
git checkout 2.2.x && \
python scons/scons.py configure INPUT_PLUGINS=all OPTIMIZATION=3 SYSTEM_FONTS=/usr/share/fonts/truetype/ && \
python scons/scons.py && \
python scons/scons.py install && \
ldconfig

# Verify that Mapnik has been installed correctly
RUN python -c 'import mapnik'
RUN cd /tmp && git clone git://github.com/openstreetmap/osm2pgsql.git && \
cd /tmp/osm2pgsql && \
mkdir build && cd build && \
cmake .. && \
make && make install && \
cd /tmp && rm -rf /tmp/osm2pgsql

# Install mod_tile and renderd
RUN cd /tmp && git clone git://github.com/openstreetmap/mod_tile.git
Expand All @@ -57,20 +47,19 @@ RUN cd /tmp/mod_tile && \
make && \
make install && \
make install-mod_tile && \
ldconfig
ldconfig && \
cd /tmp && rm -rf /tmp/mod_tile

# Install the Mapnik stylesheet
RUN cd /usr/local/src && svn co http://svn.openstreetmap.org/applications/rendering/mapnik mapnik-style
RUN cd /usr/local/src && git clone git://github.com/gravitystorm/openstreetmap-carto.git
RUN cd /usr/local/src/openstreetmap-carto && \
npm install -g carto && \
carto project.mml > mapnik.xml

# Install the coastline data
RUN cd /usr/local/src/mapnik-style && ./get-coastlines.sh /usr/local/share

# Configure mapnik style-sheets
RUN cd /usr/local/src/mapnik-style/inc && cp fontset-settings.xml.inc.template fontset-settings.xml.inc
ADD datasource-settings.sed /tmp/
RUN cd /usr/local/src/mapnik-style/inc && sed --file /tmp/datasource-settings.sed datasource-settings.xml.inc.template > datasource-settings.xml.inc
ADD settings.sed /tmp/
RUN cd /usr/local/src/mapnik-style/inc && sed --file /tmp/settings.sed settings.xml.inc.template > settings.xml.inc
RUN cd /usr/local/src/openstreetmap-carto && \
scripts/get-shapefiles.py && \
rm -f /usr/local/src/openstreetmap-carto/data/*zip

# Configure renderd
ADD renderd.conf.sed /tmp/
Expand All @@ -86,11 +75,11 @@ ADD mod_tile.conf /etc/apache2/mods-available/
RUN a2enmod mod_tile

# Ensure the webserver user can connect to the gis database
RUN sed -i -e 's/local all all peer/local gis www-data peer/' /etc/postgresql/9.3/main/pg_hba.conf
RUN sed -i -e 's/local all all peer/local gis www-data peer/' /etc/postgresql/9.5/main/pg_hba.conf

# Tune postgresql
ADD postgresql.conf.sed /tmp/
RUN sed --file /tmp/postgresql.conf.sed --in-place /etc/postgresql/9.3/main/postgresql.conf
RUN sed --file /tmp/postgresql.conf.sed --in-place /etc/postgresql/9.5/main/postgresql.conf

# Define the application logging logic
ADD syslog-ng.conf /etc/syslog-ng/conf.d/local.conf
Expand All @@ -108,9 +97,6 @@ RUN update-service --add /etc/sv/apache2
ADD renderd /etc/sv/renderd
RUN update-service --add /etc/sv/renderd

# Clean up APT when done
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Expose the webserver and database ports
EXPOSE 80 5432

Expand All @@ -127,6 +113,8 @@ ADD README.md /usr/local/share/doc/
RUN mkdir -p /usr/local/share/doc/run
ADD help.txt /usr/local/share/doc/run/help.txt

#add demo page for testing
ADD map.html /var/www/html/index.html
# Add the entrypoint
ADD run.sh /usr/local/sbin/run
ENTRYPOINT ["/sbin/my_init", "--", "/usr/local/sbin/run"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ The container runs Ubuntu 14.04 (Trusty) and is based on the
[phusion/baseimage-docker](https://github.com/phusion/baseimage-docker). It
includes:

* Postgresql 9.3
* Apache 2.2
* Postgresql 9.5
* Apache 2.4
* The latest [Osm2pgsql](http://wiki.openstreetmap.org/wiki/Osm2pgsql) code (at
the time of image creation)
* The latest [Mapnik](http://mapnik.org/) code (at the time of image creation)
Expand Down
10 changes: 8 additions & 2 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ Import data:
The following will import the .osm file at `/tmp/import.osm` into the
database.

docker run -v /data/osm-postgresql:/var/lib/postgresql -v /tmp:/data homme/openstreetmap-tiles \
docker run --rm -v /data/osm-postgresql:/var/lib/postgresql -v /tmp:/data/import homme/openstreetmap-tiles \
startdb import

Start the webserver:
Once data is loaded and users have been created run the webserver:

docker run -P -v /data/osm-postgresql:/var/lib/postgresql homme/openstreetmap-tiles \
docker run --rm -P -v /data/osm-postgresql:/var/lib/postgresql homme/openstreetmap-tiles \
startdb startservices

Run the CLI for debugging and starting services manually:
docker run --rm -P -ti -v /data/osm-postgresql:/var/lib/postgresql homme/openstreetmap-tiles \
cli

If you want to keep the rendered tiles: mount a volume with "-v /data/osm-renderd-tiles:/var/lib/mod_tile"

For further information run the cli and look at /usr/local/share/doc/README.md.
43 changes: 43 additions & 0 deletions map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<title>OpenLayers Demo</title>
<style type="text/css">
html, body, #basicMap {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
function init() {
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
20037508.34, 20037508.34),
numZoomLevels: 20,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.KeyboardDefaults()

]
};
map = new OpenLayers.Map("basicMap",options);
var newL = new OpenLayers.Layer.OSM("Default", "/osm_tiles/${z}/${x}/${y}.png", {numZoomLevels: 19});
map.addLayer(newL);
map.zoomIn();
}
</script>
</head>
<body onload="init();">
<div id="basicMap"></div>
</body>
</html>

6 changes: 3 additions & 3 deletions postgresql/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
# permissions setting.
chown -R postgres /var/lib/postgresql/ || exit 1

exec /sbin/setuser postgres /usr/lib/postgresql/9.3/bin/postgres \
-D /var/lib/postgresql/9.3/main \
-c config_file=/etc/postgresql/9.3/main/postgresql.conf
exec /sbin/setuser postgres /usr/lib/postgresql/9.5/bin/postgres \
-D /var/lib/postgresql/9.5/main \
-c config_file=/etc/postgresql/9.5/main/postgresql.conf
6 changes: 3 additions & 3 deletions renderd.conf.sed
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Perform sed substitutions for `renderd.conf`
s/;socketname=/socketname=/
s/plugins_dir=\/usr\/lib\/mapnik\/input/plugins_dir=\/usr\/local\/lib\/mapnik\/input/
s/\(font_dir=\/usr\/share\/fonts\/truetype\)/\1\/ttf-dejavu/
s/XML=.*/XML=\/usr\/local\/src\/mapnik-style\/osm.xml/
s/plugins_dir=\/usr\/lib\/mapnik\/input/plugins_dir=\/usr\/lib\/mapnik\/3.0\/input/
s/\(font_dir=\/usr\/share\/fonts\/truetype\)/\1\/noto/
s/XML=.*/XML=\/usr\/local\/src\/openstreetmap-carto\/mapnik.xml/
s/HOST=tile.openstreetmap.org/HOST=localhost/
24 changes: 12 additions & 12 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ startdb () {

initdb () {
echo "Initialising postgresql"
if [ -d /var/lib/postgresql/9.3/main ] && [ $( ls -A /var/lib/postgresql/9.3/main | wc -c ) -ge 0 ]
if [ -d /var/lib/postgresql/9.5/main ] && [ $( ls -A /var/lib/postgresql/9.5/main | wc -c ) -ge 0 ]
then
die "Initialisation failed: the directory is not empty: /var/lib/postgresql/9.3/main"
die "Initialisation failed: the directory is not empty: /var/lib/postgresql/9.5/main"
fi

mkdir -p /var/lib/postgresql/9.3/main && chown -R postgres /var/lib/postgresql/
sudo -u postgres -i /usr/lib/postgresql/9.3/bin/initdb --pgdata /var/lib/postgresql/9.3/main
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /var/lib/postgresql/9.3/main/server.crt
ln -s /etc/ssl/private/ssl-cert-snakeoil.key /var/lib/postgresql/9.3/main/server.key
mkdir -p /var/lib/postgresql/9.5/main && chown -R postgres /var/lib/postgresql/
sudo -u postgres -i /usr/lib/postgresql/9.5/bin/initdb --pgdata /var/lib/postgresql/9.5/main
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /var/lib/postgresql/9.5/main/server.crt
ln -s /etc/ssl/private/ssl-cert-snakeoil.key /var/lib/postgresql/9.5/main/server.key
}

createuser () {
Expand All @@ -49,22 +49,21 @@ createdb () {
setuser postgres createdb -O www-data $dbname

# Install the Postgis schema
$asweb psql -d $dbname -f /usr/share/postgresql/9.3/contrib/postgis-2.1/postgis.sql
$asweb psql -d $dbname -f /usr/share/postgresql/9.5/contrib/postgis-2.2/postgis.sql
$asweb psql -d $dbname -f /usr/share/postgresql/9.5/contrib/postgis-2.2/spatial_ref_sys.sql

$asweb psql -d $dbname -c 'CREATE EXTENSION HSTORE;'

# Set the correct table ownership
$asweb psql -d $dbname -c 'ALTER TABLE geometry_columns OWNER TO "www-data"; ALTER TABLE spatial_ref_sys OWNER TO "www-data";'

# Add the 900913 Spatial Reference System
$asweb psql -d $dbname -f /usr/local/share/osm2pgsql/900913.sql
}

import () {
# Find the most recent import.pbf or import.osm
import=$( ls -1t /data/import.pbf /data/import.osm 2>/dev/null | head -1 )
import=$( ls -1t /data/import/import.pbf /data/import/import.osm 2>/dev/null | head -1 )
test -n "${import}" || \
die "No import file present: expected /data/import.osm or /data/import.pbf"
die "No import file present: expected /data/import/import.osm or /data/import/import.pbf"

echo "Importing ${import} into gis"
echo "$OSM_IMPORT_CACHE" | grep -P '^[0-9]+$' || \
Expand All @@ -78,7 +77,8 @@ import () {
number_processes=8
fi

$asweb osm2pgsql --slim --hstore --cache $OSM_IMPORT_CACHE --database gis --number-processes $number_processes $import
$asweb osm2pgsql --slim -G --hstore --cache $OSM_IMPORT_CACHE --tag-transform-script /usr/local/src/openstreetmap-carto/scripts/lua/openstreetmap-carto.lua --database gis --number-processes $number_processes -S /usr/local/src/openstreetmap-carto/openstreetmap-carto.style $import

}

dropdb () {
Expand Down