From 712a259bf122043b2087d36253d4ec4ec1f5d2af Mon Sep 17 00:00:00 2001 From: Ex Date: Fri, 16 Feb 2024 20:58:24 +0100 Subject: [PATCH] add docker support --- Dockerfile | 21 +++++++++++++++++++++ README.md | 21 +++++++++++++++++++++ config.ini | 37 +++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 26 ++++++++++++++++++++++++++ feeds/aachen.json | 15 +++++++++++++++ src/fetch.py | 14 ++++++++++++++ src/transitous | 19 +++++++++++++++++++ 7 files changed, 153 insertions(+) create mode 100644 Dockerfile create mode 100644 config.ini create mode 100644 docker-compose.yaml create mode 100644 feeds/aachen.json create mode 100755 src/transitous diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..48921235 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM ghcr.io/motis-project/motis:latest + +USER root +RUN mkdir -p /input/schedule && chown -R motis /input /system_config.ini +RUN apk add go python3 py3-pip + +USER motis + +RUN pip install requests +RUN go install github.com/patrickbr/gtfstidy@latest + +# demo data for Aachen +RUN wget https://github.com/motis-project/test-data/raw/aachen/aachen.osm.pbf -O /input/osm.pbf + +ADD --chown=motis src/ /tools/src +ADD --chown=motis feeds/ /tools/feeds +ADD --chown=motis transitland-atlas/ /tools/transitland-atlas +ADD config.ini /system_config.ini +ADD src/transitous /usr/local/bin/ + +RUN transitous fetch aachen.json diff --git a/README.md b/README.md index b5298f04..e99709fb 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,27 @@ routing service that: * does not stop at borders * aims at crowd-sourced maintenance of data feeds in the spirit of FOSS +## Docker development install +``` +git submodule update +docker-compose up -d +``` +### Import new feed +``` +docker-compose run --rm motis transitous fetch +``` + + +Note than docker volume "input" is filled within the first start. If you make changes you have to delete the volume. + +**Attention: Data lost!** +``` +docker-compose down -v +docker-compose up -d --build +``` + + + ## Contact * Matrix channel: [#opentransport:matrix.org](https://matrix.to/#/#opentransport:matrix.org) (for now) diff --git a/config.ini b/config.ini new file mode 100644 index 00000000..b9ebc328 --- /dev/null +++ b/config.ini @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2024 Jonah BrĂ¼chert +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +modules=intermodal +modules=address +modules=tiles +modules=osrm +modules=ppr +modules=parking +modules=nigiri +modules=target + +intermodal.router=nigiri +dataset.no_schedule=true + +[server] +static_path=/motis/web + +#[import] +#paths=osm:/input/osm.pbf +#paths=schedule-aachen-aachen:/input/schedule/aachen_aachen.gtfs.zip +#data_dir=/data + +[nigiri] +first_day=TODAY +num_days=365 + +[osrm] +profiles=/motis/osrm-profiles/car.lua +profiles=/motis/osrm-profiles/bike.lua + +[ppr] +profile=/motis/ppr-profiles/default.json + +[tiles] +profile=/motis/tiles-profiles/background.lua diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..53ee0960 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,26 @@ +version: "3.7" + +services: + motis: + build: . + # image: ghcr.io/motis-project/motis:latest + volumes: + - input:/input + - data:/data + - web:/motis/web + ports: + - 8080:8080 + + # web: + # image: nginx + # volumes: + # - web:/usr/share/nginx/html:ro + # ports: + # - 80:80 + # depends_on: + # - motis + +volumes: + input: + data: + web: \ No newline at end of file diff --git a/feeds/aachen.json b/feeds/aachen.json new file mode 100644 index 00000000..dd4d241c --- /dev/null +++ b/feeds/aachen.json @@ -0,0 +1,15 @@ +{ + "maintainers": [ + { + "name": "ex", + "github": "exmatrikulator" + } + ], + "sources": [ + { + "name": "aachen", + "type": "http", + "url": "http://opendata.avv.de/archive_GTFS/2024/2024-01/AVV_GTFS_Masten_mit_SPNV_20240113.zip" + } + ] +} diff --git a/src/fetch.py b/src/fetch.py index e29c5b37..4f3bed96 100644 --- a/src/fetch.py +++ b/src/fetch.py @@ -61,6 +61,20 @@ def postprocess(self, source: Source, path: Path): subprocess.call(command, cwd=tmpdir) shutil.rmtree(tmpdir) + + if os.path.exists("/input/schedule/"): + shutil.copy(output_file_path, "/input/schedule/") + + # TODO: write a motis ini class + if not os.path.exists("/input/config.ini"): + with open('/input/config.ini', 'a') as config_ini: + config_ini.write("[import]\n") + config_ini.write("data_dir=/data\n") + config_ini.write("paths=osm:/input/osm.pbf\n") + + + with open('/input/config.ini', 'a') as config_ini: + config_ini.write(f"paths=schedule-{path.name.split('.')[0].replace('_','-')}:/input/schedule/{path.name}\n") def fetch(self, metadata: Path): region = Region(json.load(open(metadata, "r"))) diff --git a/src/transitous b/src/transitous new file mode 100755 index 00000000..e4e7e4d8 --- /dev/null +++ b/src/transitous @@ -0,0 +1,19 @@ +#!/bin/sh + +fetch() { + cd /tools + PATH=$PATH:$HOME/go/bin + python src/fetch.py feeds/$1 +} + + +case $1 in + "fetch" ) + fetch $2 + ;; + *) + echo >&2 "use 'fetch '" + exit 1 + ;; +esac +