This repository contains a framework for downloading/preparing and building the the [Pelias Geocoder](https://github.com/pelias/pelias) using Docker and [Docker Compose](https://github.com/docker/compose#docker-compose).
## Projects
Example projects are included in the [projects](https://github.com/pelias/docker/tree/master/projects) directory.
We recommend you start with the `portland-metro` example as a first-time user; once you have successfully completed a build you can use this as a base to create your own projects.
We do not recommend running large extracts (anything larger than a US State) inside Docker, the scripts are **not suitable** for full planet builds. If you require global coverage, please see our [install documentation](https://github.com/pelias/documentation/blob/master/getting_started_install.md) or consider using the [geocode.earth](https://geocode.earth/) services hosted by members of our core team.
You will need to have `docker` and `docker-compose` installed before continuing. If you are not using the latest version, please mention that in any bugs reports.
If you are running OSX, you should also install `brew install coreutils` and max-out your Docker limits in `Docker > Preferences > Advanced`.
Scripts can easily download tens of GB of geographic data, so ensure you have enough free disk space!
## Installing the Pelias command
If you haven't done so already, you will need to ensure the `pelias` command is available on your path.
You can find the `pelias` file in the root of this repository.
Advanced users may have a preferance how this is done on their system, but a basic example would be to do something like:
Once the command is correctly installed you should be able to run the following command to confim the pelias command is available on your path:
```bash
which pelias
```
### Resolving PATH issues
If you are having trouble getting this to work then quickly check that the target of the symlink is listed on your $PATH:
```bash
tr ':' '\n' <<< "$PATH"
```
If you used the `ln -s` command above then the directory `/usr/local/bin` should be listed in the output.
If the symlink target path is *not* listed, then you will either need to add its location to your $PATH or create a new symlink which points to a location which is already on your $PATH.
## Configure Environment
The `pelias` command looks for an `.env` file in your **current working directory**, this file contains information specific to your local environment.
If this is your first time, you should change directories to an example project before continuing:
```bash
cd projects/portland-metro
```
Ensure that your current working directory contains the files: `.env`, `docker-compose.yml` and `pelias.json` before continuing.
### Variable: DATA_DIR
The only mandatory variable in `.env` is `DATA_DIR`.
This path reflects the directory Pelias will use to store downloaded data and use to build it's other microservices.
You **must** create a new directory which you will use for this project, for example:
```bash
mkdir /tmp/pelias
```
Then use your text editor to modify the `.env` file to reflect your new path, it should look like this:
You can then list the environment variables to ensure they have been correctly set:
```bash
pelias system env
```
### Variables: COMPOSE_*
The compose variables are optional and are documented here: https://docs.docker.com/compose/env-file/
Note: changing the `COMPOSE_PROJECT_NAME` variable is not advisable unless you know what you are doing. If you are migrating from the deprecated `pelias/dockerfiles` repository then you can set `COMPOSE_PROJECT_NAME=dockerfiles` to enable backwards compatibility with containers created using that repository.
All processes in Pelias containers are run as non-root users. By default, the UID of the processes will be `1000`, which is the first user ID on _most_ Linux systems and is likely to be a good option. However, if restricting file permissions in your data directory to a different user or group is important, this can be overridden by setting the `DOCKER_USER` variable.
This variable can take just a UID or a UID:GID combination such as `1000:1000`. See the [docker-compose](https://docs.docker.com/compose/compose-file/#domainname-hostname-ipc-mac_address-privileged-read_only-shm_size-stdin_open-tty-user-working_dir) and [docker run](https://docs.docker.com/engine/reference/run/#user) documentation on controlling Docker container users for more information.
prepare all build all services which have a prepare step
system check ensure the system is correctly configured
system env display environment variables
system update update the pelias command by pulling the latest version
```
### Compose commands
The compose commands are available as a shortcut to running `docker-compose` directly, they will also ensure that your environment is correctly configured.
See the docker-compose documentation for more info: https://docs.docker.com/compose/overview/
```bash
pelias compose pull update all docker images
pelias compose logs display container logs
pelias compose ps list containers
pelias compose top display the running processes of a container
pelias compose exec execute an arbitrary docker-compose command
pelias compose run execute a docker-compose run command
pelias compose up start one or more docker-compose service(s)
pelias compose kill kill one or more docker-compose service(s)
pelias compose down stop all docker-compose service(s)
```
### Download commands
The download commands will fetch and update geographic data from source.
For example: `pelias download tiger` will fetch street data from the US Census Bureau and store it in the directory referenced by the `DATA_DIR` environment variable.
```bash
pelias download wof (re)download whosonfirst data
pelias download oa (re)download openaddresses data
pelias download osm (re)download openstreetmap data
pelias download tiger (re)download TIGER data
pelias download transit (re)download transit data
pelias download all (re)download all data
```
### Prepare commands
The prepare commands are used to run any commands which are required to setup/configure or build microservices.
For example: `pelias prepare interpolation` will build a street address interpolation index.
Note: the order of execution is important, the prepare commands require data, so they must be run *after* the download commands have fetched the data.
```bash
pelias prepare polylines export road network from openstreetmap into polylines format