Skip to content

Commit f34fae8

Browse files
authored
Merge pull request #6 from gedankenstuecke/binderrize
Expand on docker/binder descriptions
2 parents 60b0e97 + bf01d60 commit f34fae8

File tree

5 files changed

+1666
-27
lines changed

5 files changed

+1666
-27
lines changed

Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ RUN apt-get update \
55
ca-certificates gnupg lsb-release locales \
66
wget curl \
77
git-core unzip \
8+
netcat \
89
&& locale-gen $LANG && update-locale LANG=$LANG
910

1011

@@ -47,19 +48,22 @@ RUN mv fonts/ /usr/share/fonts/type1/gsfonts
4748

4849
# Install python libraries
4950

50-
RUN pip install pyyaml nik4 requests
51+
RUN pip install pyyaml nik4 requests notebook jupyterlab ipywidgets
5152

5253
# Install carto for stylesheet
5354
RUN npm install -g [email protected]
5455

56+
ENV HOME=/home/postgres
5557

56-
COPY . /workdir
57-
58-
RUN mkdir -p /workdir/openstreetmap-carto/data
59-
RUN mkdir -p /workdir/output
60-
61-
WORKDIR /workdir
58+
# Make sure the contents of our repo are in ${HOME}
59+
COPY . ${HOME}
60+
RUN usermod -u 1000 postgres
61+
RUN chown -R 1000 ${HOME}
62+
USER postgres
6263

63-
RUN chown postgres:postgres -R /workdir
64+
RUN mkdir -p ${HOME}/openstreetmap-carto/data
65+
RUN mkdir -p ${HOME}/output
66+
RUN mkdir -p ${HOME}/pgdata
67+
WORKDIR ${HOME}
6468

65-
USER postgres
69+
ENTRYPOINT ["./entrypoint-new.sh"]

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
Make a image of OSM data of an area from 2 dates, showing what was changed.
44

5-
## Installation
5+
You can either install the necessary dependencies on your computer or run the script via Docker (both via MyBinder or in a local container).
6+
7+
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/gedankenstuecke/osm-mapping-party-before-after/binderrize?labpath=make-images.ipynb)
8+
9+
## Making a local Installation
610

711
1. *On macOS:* [install Homebrew](https://brew.sh/#:~:text=Install%20Homebrew)
812
1. [Install `pipx`](https://pipx.pypa.io/stable/installation/#installing-pipx)
@@ -26,10 +30,19 @@ Make a image of OSM data of an area from 2 dates, showing what was changed.
2630
cd osm-mapping-party-before-after
2731
```
2832
29-
### Install & use via Docker image
33+
## Use via Docker or MyBinder
34+
35+
If you do not want to install the whole pipeline yourself, you can run this setup in a Docker container that is ready-to-use and that can also run in the free-to-use open source cloud infrastructure of _MyBinder_.
36+
37+
If you want to use the _MyBinder_ version, [click here and wait a bit](https://mybinder.org/v2/gh/gedankenstuecke/osm-mapping-party-before-after/binderrize?labpath=make-images.ipynb). This will launch the version online in a virtual machine and lets you interact with the code through a small Python notebook that will launch automatically and contains all necessary instructions.
38+
39+
The MyBinder version has two drawbacks: 1. You will have to upload the OSM history file (_\*.osh.pbf_) into the container. Depending on the region of interest these can be quite large. 2. Creating the maps will take longer, as other external downloads will have to be downloaded on the fly. See [this blog post for more details](https://tzovar.as/map-comparisons/).
40+
41+
If you want to run the Docker image on your own computer, you can find the necessary [image is available on Docker Hub under `gedankenstuecke/osm-mapping-party-before-after`](https://hub.docker.com/r/gedankenstuecke/osm-mapping-party-before-after).
3042
31-
Alternatively, if you do not want to install the whole pipeline yourself, you can run this setup in a Docker container that is ready to use.
32-
We start, by cloning this repository:
43+
### Building the Docker container from scratch
44+
45+
Alternatively, you can also build the container locally if you want to make changes to it/improve it: We start by cloning this repository:
3346
3447
```bash
3548
git clone --recurse-submodules https://github.com/amandasaurus/osm-mapping-party-before-after
@@ -45,6 +58,9 @@ docker build -t before_after_builder .
4558
```
4659
4760
This step needs to be run only once, and it can take a few minutes as it will download and build all the dependencies needed.
61+
62+
#### Running the container locally
63+
4864
Once the step is finished, you can launch the container like so:
4965
5066
```bash
@@ -53,26 +69,26 @@ Once the step is finished, you can launch the container like so:
5369
5470
The command takes two parameters:
5571
56-
1. the name of the container (as specified above)
57-
2. a full path to a directory you want to use for accessing and writing files to from the container (i.e. Input and output files). Depending on how you installed/run Docker, this folder might need full read/write permissions for other users (e.g. run `chmod 777`).
72+
1. the name of the container (e.g. as specified during the `docker build` step)
73+
2. a full path to a directory you want to use for accessing and writing files to from the container (i.e. input and output files). Depending on how you installed/run Docker, this folder might need full read/write permissions for other users (e.g. run `chmod 777`).
5874
59-
The `docker_run.sh` command will launch the container itself, including the necessary postgres database etc.
60-
It will also create two virtual docker volumes (named `pgdata` and `osm_data`).
61-
These volumes are used to store external data, i.e. the database contents and the `openstreetmap-carto` external files.
75+
The `docker_run.sh` command will then launch the container itself, including the necessary postgres database and the notebook interface. It will also create two virtual docker volumes (named `pgdata` and `osm_data`). These volumes are used to store external data, i.e. the database contents and the `openstreetmap-carto` external files, so that subsequent launches are faster than the initial one.
6276
63-
Once the docker container is running, you can connect into it to get a bash inside to run the commands as outlined below using:
77+
After running the `./docker_run.sh` command you will see a lot of text running by while the container sets itself up. At the end of this, you should see this:
6478
65-
```bash
66-
docker exec -ti map-before-after bash
79+
```
80+
To access the server, open this file in a browser:
81+
file:///home/postgres/.local/share/jupyter/runtime/jpserver-1-open.html
82+
Or copy and paste one of these URLs:
83+
http://1ce38bef580f:8888/tree?token=asecrettokenwithlotsofcharacters
84+
http://127.0.0.1:8888/tree?token=asecrettokenwithlotsofcharacters
6785
```
6886
69-
The resulting shell puts you into the equivalent of the root of this repository, in a folder called `/workdir`. From there you can use this repository as outlined below.
70-
71-
All output files are saved in the `/workdir` by default, you can from there move them into `/workdir/output` inside the container to access files on your host operating system.
87+
Clicking on the `http://127.0.0.1:8888/tree?` link will open the notebook interface in your web-browser, where you can open the `make-images.ipynb` notebook, which will have all the necessary instructions to get started.
7288
73-
A [ready-built image is available on Docker Hub](https://hub.docker.com/r/gedankenstuecke/osm-mapping-party-before-after).
89+
## Usage of `make.sh` without the container
7490
75-
## Usage
91+
If you have tile-building setup on your computer, you can run `make.sh` without Docker, following these steps:
7692
7793
1. Download an OSM history file (`.osh.pbf`) e.g. from [Geofabrik's internal download server](https://osm-internal.download.geofabrik.de/?landing_page=true). You will need to log in with an OSM account.
7894
1. Calculate the `BBOX` with [BBoxFinder.com](http://bboxfinder.com/).

docker_run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ IMAGE_NAME=$1
1313
OUTPUT_DIR=$2
1414

1515

16-
docker run --rm -e POSTGRES_PASSWORD="unused" -v pgdata:/var/lib/postgresql/data -v osm_data:/workdir/openstreetmap-carto/data -v $OUTPUT_DIR:/workdir/output --name map-before-after $IMAGE_NAME
16+
docker run --rm -e POSTGRES_PASSWORD="unused" -v pgdata:/home/postgres/pgdata -v osm_data:/home/postgres/openstreetmap-carto/data -v $OUTPUT_DIR:/home/postgres/external --name map-before-after -p 8888:8888 $IMAGE_NAME jupyter notebook --NotebookApp.default_url=/lab/ --ip=0.0.0.0 --port=8888

entrypoint-new.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
export POSTGRES_PASSWORD='unused'
4+
export PGDATA="/home/postgres/pgdata"
5+
6+
nohup docker-entrypoint.sh postgres &
7+
8+
while ! nc -z localhost 5432; do
9+
echo "waiting for postgres"
10+
sleep 1;
11+
done;
12+
13+
exec "$@"

0 commit comments

Comments
 (0)