Skip to content

Commit

Permalink
generate config from env
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocudini committed Jan 25, 2021
1 parent cd6e681 commit 790170d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ cd odh-mentor-otp

```otp-unofficial.sh``` a script to run otp unofficial version by command line

```otp-app``` static javascript client side react/redux UI component to interact with Opentriplanner instance.
```router-config.json``` define OTP updaters(GTFS-RT) and router settings from environment vars

```gbfs``` service that fetch bikesharing data from ODH and provide them as GBFS for otp.
```build-config.json``` default OTP build config from environment vars

```osm.url``` a pregenerated urls list of downloadable Openstreetmap data for SouthTyrol area.

```gtfs2bbox``` nodejs tool to calculate bounding boxes of Openstreetmap intersects GTFS data for downloading, create a list of overpass downloadable urls
```otp-app/``` static javascript client side react/redux UI component to interact with Opentriplanner instance.

```gbfs/``` service that fetch bikesharing data from ODH and provide them as GBFS for otp.

```gtfs2bbox/``` nodejs tool to calculate bounding boxes of Openstreetmap intersects GTFS data for downloading, create a list of overpass downloadable urls

### Docker Environment

Expand Down
30 changes: 30 additions & 0 deletions envconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

const fs = require('fs');

const ENV = process.env,
infile = process.argv[2];

function tmpl(str, data) {
//const tmplReg = /\$\{(.+?)\}/g
const tmplReg = /\$\{([\w_\-]+)\}/g
//const tmplReg = /\{ *([\w_\-]+) *\}/g

return str.replace(tmplReg, function (str, key) {
var value = data[key];
if (value === undefined)
value = "${"+key+"}";
return value;
});
}

try {
const configFile = fs.readFileSync(infile, 'utf8');

const configEnv = tmpl(configFile, ENV);

console.log(configEnv);
}
catch (e) {
console.log('Error: ',e.message);
process.exit(1);
}
5 changes: 5 additions & 0 deletions infrastructure/docker/otp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN apk add --no-cache \

RUN mkdir -p /usr/local/share/java
RUN mkdir -p /var/otp
RUN mkdir -p /conf

RUN curl -o /usr/local/share/java/otp.jar https://repo1.maven.org/maven2/org/opentripplanner/otp/$OTP_VERSION/otp-$OTP_VERSION-shaded.jar
COPY otp-unofficial.jar /usr/local/share/java/otp-unofficial.jar
Expand All @@ -25,6 +26,10 @@ COPY otp-unofficial.sh /usr/local/bin/

COPY infrastructure/docker/otp/docker-entrypoint.sh /docker-entrypoint.sh

COPY build-config.json /conf/
COPY router-config.json /conf/
COPY envconfig.js /conf/

COPY ./gtfs2bbox /gtfs2bbox

RUN cd /gtfs2bbox && \
Expand Down
10 changes: 8 additions & 2 deletions infrastructure/docker/otp/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ fi
if [ "${BUILD_GRAPH}" = "True" ]; then
#TODO check gtfs data
#TODO useTransfersTxt true if GTFS have it and we want to use it.
echo '{"useTransfersTxt": false}' > /data/build-config.json

#echo '{"useTransfersTxt": false}' > /data/build-config.json
node /conf/envconfig.js /conf/build-config.json > /data/build-config.json

if [ "${UPDATERS}" = "True" ]; then
echo '{"updaters":[{"type":"stop-time-updater","frequencySec":60,"sourceType":"gtfs-http","url":"'${GTFS_RT_URL}'", "feedId": "'${GTFS_FEED_ID}'"},{"type":"bike-rental","frequencySec":900,"sourceType":"gbfs","url":"'${GBFS_HOST}':'${GBFS_PORT}'/bz/'${GBFS_VERSION}'/"},{"type":"bike-rental","frequencySec":900,"sourceType":"gbfs","url":"'${GBFS_HOST}':'${GBFS_PORT}'/me/'${GBFS_VERSION}'/"}]}' > /data/router-config.json
node /conf/envconfig.js /conf/router-config.json > /data/router-config.json
fi

#TODO support /data/walk-config.json

echo "Building graph file... /data/Graph.obj"

#BUILD GRAPH
Expand Down

0 comments on commit 790170d

Please sign in to comment.