Skip to content

Commit

Permalink
First version to develop with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
britiger committed Jun 7, 2021
1 parent 29a2cff commit 901b9b3
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
config

database/*.pbf
database/tools/osmconvert
database/tools/osmupdate
database/tools/*
database/cache/*
database/tmp/*
webapp/venv
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM postgres:13

RUN apt-get update; \
apt install -y --no-install-recommends \
postgis \
python3 \
python3-dev \
python3-pip \
python3-venv \
osm2pgsql \
postgresql-13-postgis-3 \
unzip \
wget \
gcc \
libz-dev

# install/build current ogr2ogr into /usr/local
RUN cd / ; \
apt install -y --no-install-recommends g++ libsqlite3-dev sqlite3 pkg-config libtiff-dev libcurl4-openssl-dev make libpq-dev; \
wget https://github.com/OSGeo/gdal/releases/download/v3.2.3/gdal-3.2.3.tar.gz; \
wget https://download.osgeo.org/proj/proj-8.0.1.tar.gz; \
tar xzf gdal-3.2.3.tar.gz; \
tar xzf proj-8.0.1.tar.gz; \
cd /proj-8.0.1; \
./configure; \
make -j8 ; \
make install ; \
ldconfig ; \
cd /gdal-3.2.3 ; \
./configure ; \
make -j8 ; \
make install ; \
ldconfig ; \
rm -f gdal-3.2.3 proj-8.0.1 gdal-3.2.3.tar.gz proj-8.0.1.tar.gz

ADD docker/create_db.sql /docker-entrypoint-initdb.d/create_db.sql

EXPOSE 5432 5000
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# [bikeparking.lorenz.lu](https://bikeparking.lorenz.lu/)

You can start it by your own using Docker. By the script the source directory is linked as volume into the container, so you can localy edit the webapp.

1. Building a local image:
```
./build-docker.sh
```
2. Download and Link a pbf-File:
```
# Here as example of Brandenburg incl. Berlin
wget http://download.geofabrik.de/europe/germany/brandenburg-latest.osm.pbf
ln -s brandenburg-latest.osm.pbf import.osm.pbf
```
3. Start container and import data
```
./run-docker.sh
```
4. Work with the container
```
# Start Webapp
./run-docker.sh webapp
# Need to Open the Browser http://127.0.0.1:5000/
# Update Database
./run-docker.sh update
# Import or update external data
./run-docker.sh external
# Import or update rental stations
./run-docker.sh rental
```

If you want to persit your data in the database you need to edit `run-docker.sh` by adding a database volume:
```bash
# create a Volume / otherwise you can use a local directory
docker volume create pgdata

# docker run -e POSTGRES_PASSWORD=bikeparking -p 127.0.0.1:5000:5000 -v `pwd`:/bikeparking --rm -d --name $CONTAINER_NAME bikeparking
docker run -e POSTGRES_PASSWORD=bikeparking -p 127.0.0.1:5000:5000 -v `pwd`:/bikeparking -v pgdata:/var/lib/postgresql/data --rm -d --name $CONTAINER_NAME bikeparking
```
7 changes: 7 additions & 0 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# goto this path
cd `dirname $(readlink -f $0)`

docker pull postgres:13
docker build -t bikeparking:latest .
2 changes: 2 additions & 0 deletions database/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export PATH=`pwd`/tools/:$PATH
imposm3 import -srid 3857 -overwritecache ${IMPOSM_PARAMETER} -connection "postgis://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}" -config config.json -read ${IMPORT_PBF} -write -dbschema-production imposm3 -deployproduction

# create views
psql -f sql/create_external_table.sql
psql -f sql/create_rental_table.sql
psql -f sql/create_views.sql
psql -f sql/create_statistic.sql

Expand Down
5 changes: 5 additions & 0 deletions docker/create_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE USER osm PASSWORD 'osm';
CREATE DATABASE osm_parking OWNER osm;
\c osm_parking
CREATE EXTENSION postgis;
CREATE EXTENSION hstore;
69 changes: 69 additions & 0 deletions run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# goto this path
cd `dirname $(readlink -f $0)`
CMD=$1

CONTAINER_NAME=bikeparkingcontainer

# Check Installed imposm
if ! [ -f "database/tools/imposm-0.11.1-linux-x86-64.tar.gz" ]
then
wget -P database/tools/ https://github.com/omniscale/imposm3/releases/download/v0.11.1/imposm-0.11.1-linux-x86-64.tar.gz
tar -xzf database/tools/imposm-0.11.1-linux-x86-64.tar.gz -C database/tools/
mv -f database/tools/imposm-0.11.1-linux-x86-64/* database/tools/
rm -rf database/tools/imposm-0.11.1-linux-x86-64
fi

if ! [ -f config ]
then
cp config.sample config
fi

source ./config

if ! [ "$( docker container inspect -f '{{.State.Status}}' $CONTAINER_NAME )" == "running" ]
then
echo "Container not running ..."
# Start container
docker run -e POSTGRES_PASSWORD=bikeparking -p 127.0.0.1:5000:5000 -v `pwd`:/bikeparking --rm -d --name $CONTAINER_NAME bikeparking
echo "Waiting for statup ..."
sleep 10
DO_IMPORT=1
else
echo "Container is running."
if [ -z "${CMD}" ]
then
echo "Use Parameter: "
echo " external - Import/Update data of external sources"
echo " reimport - Reimport Database from PBF-File"
echo " rental - Import/Update data of rental sources"
echo " update - Update Database from osm"
echo " webapp - Start Webapp"
fi
fi

if [ "${CMD}" == "reimport" ] || [ -n "${DO_IMPORT}" ]
then
# Import
if [ -f "${IMPORT_PBF}" ]
then
docker exec -it $CONTAINER_NAME /bikeparking/database/import.sh
else
echo "Please Download a PBF-File (${IMPORT_PBF}) for import!"
echo "After this you should run '$0 reimport' for import."
fi
elif [ "${CMD}" == "webapp" ]
then
# run webapp in container
docker exec -it $CONTAINER_NAME /bikeparking/webapp/start.sh
elif [ "${CMD}" == "update" ]
then
docker exec -it $CONTAINER_NAME /bikeparking/database/update.sh
elif [ "${CMD}" == "external" ]
then
docker exec -it $CONTAINER_NAME /bikeparking/database/import_external.sh
elif [ "${CMD}" == "rental" ]
then
docker exec -it $CONTAINER_NAME /bikeparking/database/import_rental.sh
fi
1 change: 0 additions & 1 deletion webapp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
flask
flask-sqlalchemy
flask-babel
psycopg2
psycopg2-binary
pylint
python-dotenv
4 changes: 3 additions & 1 deletion webapp/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

cd `dirname $0`

source ../config

export PGHOST
Expand All @@ -17,4 +19,4 @@ pip install --upgrade setuptools
pip install --upgrade pip
pip install -r requirements.txt

flask run
flask run --host=0.0.0.0

0 comments on commit 901b9b3

Please sign in to comment.