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

Fix 0.96.0 and add 1.3.0 #5

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
3 changes: 1 addition & 2 deletions 0.96.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ ENV OSM2PGSQL_VERSION=0.96.0 \
RUN cd /tmp && git clone --depth 1 --branch $OSM2PGSQL_VERSION https://github.com/openstreetmap/osm2pgsql.git && \
mkdir -p osm2pgsql/build && \
cd osm2pgsql/build && \
cmake .. && make install \
rm -rf /tmp/osm2pgsql
cmake .. && make install

# osmctools && clean up
RUN apt-get install -y osmctools=${OSMCTOOLS_VERSION} postgresql-client-10 \
Expand Down
45 changes: 45 additions & 0 deletions 1.3.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ubuntu:bionic
MAINTAINER typebrook "typebrook@gmail.com"

ENV DEBIAN_FRONTEND=noninteractive
RUN sed -e s%http://archive.ubuntu.com/ubuntu/%mirror://mirrors.ubuntu.com/mirrors.txt% -i /etc/apt/sources.list
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y vim

RUN apt-get install -y \
make \
cmake \
g++ \
git-core \
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

ENV OSM2PGSQL_VERSION=1.3.0 \
OSMCTOOLS_VERSION=0.8-1

# osm2pgsql
RUN cd /tmp && git clone --depth 1 --branch $OSM2PGSQL_VERSION https://github.com/openstreetmap/osm2pgsql.git && \
mkdir -p osm2pgsql/build && \
cd osm2pgsql/build && \
cmake .. && make install

# osmctools && clean up
RUN apt-get install -y osmctools=${OSMCTOOLS_VERSION} postgresql-client-10 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# osm replication script
ADD ./osm-importer.sh /usr/local/bin/osm-importer.sh
WORKDIR /osm
CMD ["/bin/bash", "-i", "/usr/local/bin/osm-importer.sh"]
60 changes: 60 additions & 0 deletions 1.3.0/osm-importer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# Rex Tsai <rex.cc.tsai@gmail.com>

echo REGION=${REGION:="asia/taiwan"}
echo COUNTRY=${COUNTRY:=$(basename $REGION)}
echo DATADIR=${DATADIR:="/osm"}
echo PBF=${PBF:=$DATADIR/${COUNTRY}-latest.osm.pbf}
echo LOOP=${LOOP:=600}
HOST=download.geofabrik.de

[ -d $DATADIR ] || (echo "$DATADIR not found" && exit -1)

if [ -z $PG_ENV_POSTGRES_PASSWORD ] \
|| [ -z $PG_ENV_POSTGRES_DB ] \
|| [ -z $PG_ENV_POSTGRES_USER ] \
|| [ -z $PG_PORT_5432_TCP_ADDR ] \
|| [ -z $PG_PORT_5432_TCP_PORT ] ; then
echo "missing Progress settings"

cat <<EOF
PG_PORT_5432_TCP_ADDR=$PG_PORT_5432_TCP_ADDR
PG_PORT_5432_TCP_PORT=$PG_PORT_5432_TCP_PORT
PG_ENV_POSTGRES_DB=$PG_ENV_POSTGRES_DB
PG_ENV_POSTGRES_USER=$PG_ENV_POSTGRES_USER
PG_ENV_POSTGRES_PASSWORD=$PG_ENV_POSTGRES_PASSWORD
EOF
exit 1
fi

function importosm () {
# ping database.
echo "SELECT 1;" | PGPASSWORD=$PG_ENV_POSTGRES_PASSWORD \
psql --no-password \
-h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT \
-U $PG_ENV_POSTGRES_USER $PG_ENV_POSTGRES_DB \
|| return $?

UPDATEPBF=$(mktemp -p $DATADIR XXX.pbf)
if [ ! -f ${PBF} ] ; then
wget -O "${UPDATEPBF}" http://$HOST/${REGION}-latest.osm.pbf \
|| return $?
else
osmupdate -v --base-url=$HOST/${REGION}-updates "$PBF" "$UPDATEPBF" \
|| return $?
fi
trap "Importing in progress, ignored SIGINT & SIGTERM." SIGINT SIGTERM
PGPASSWORD=$PG_ENV_POSTGRES_PASSWORD \
osm2pgsql --create --slim --cache 2000 \
--host $PG_PORT_5432_TCP_ADDR \
--database $PG_ENV_POSTGRES_DB \
--username $PG_ENV_POSTGRES_USER \
--port $PG_PORT_5432_TCP_PORT \
$UPDATEPBF && mv -v $UPDATEPBF $PBF
}

while : ; do
importosm
[ $LOOP -eq 0 ] && exit $?
sleep $LOOP || exit
done
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ docker run --name ${POSTGIS_INSTANCE} \
REGION="asia/taiwan"
DATADIR=/osm
LOOP=600
VERSION="0.96.0"
VERSION="1.3.0"
# run the osm2pgsql instance
# The osm-importer.sh script will run osmupdate every 600 seconds,
# to pull latest osm data from
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ POSTGIS_INSTANCE=${1:-"osmdb"}
REGION=${2:-"asia/taiwan"}
DATADIR=/osm
LOOP=600
VERSION=${3:-"0.96.0"}
VERSION=${3:-"1.3.0"}

docker run -t -i --rm \
--link ${POSTGIS_INSTANCE}:pg \
Expand Down