sharedstreets / sharedstreets-js

SharedStreets (Node.js & Javascript)
https://sharedstreets.io
MIT License
78 stars 25 forks source link

unable to locate OSRM module. #52

Closed josiekre closed 5 years ago

josiekre commented 5 years ago

Using the following Dockerfile with the fix from #50, points are matching from the tests but lines are not. There's a problem finding the OSRM module.

FROM node:10

ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin

USER node
RUN npm install -g sharedstreets@0.12.3
$ docker build -t shst .
$ docker run -it --rm -v ~/Downloads/:/usr/node/ shst:latest shst match /usr/node/line_2.in.geojson --out=/usr/node/out.geojson

  🌏  Loading geojson data...
       Matching using car routing rules on all streets
  ✨  Matching 1 lines...
     writing to cache: /home/node/.shst/cache/tiles/osm/planet-181224/12-1171-1566.geometry.8.pbf
     writing to cache: /home/node/.shst/cache/tiles/osm/planet-181224/12-1171-1566.reference.8.pbf
unable to locate OSRM module.
Unable to build graph: unable to locate OSRM module.
Try deleting existing cached graph: /home/node/.shst/cache/graphs/33d9f459-1a49-3aba-a144-bd7b8338c420

I looked into src/graph.ts. getOSRMDirectory() should be finding the path correctly given where I can find it inside the Docker.

https://github.com/sharedstreets/sharedstreets-js/blob/9b08e316381180cd5859002522e745fb2c955c13/src/graph.ts#L43-L46

Inside the Docker, OSRM gets installed at /home/node/.npm-global/lib/node_modules/sharedstreets/node_modules/osrm/.

$ head /home/node/.npm-global/lib/node_modules/sharedstreets/node_modules/osrm/package.json

{
  "_from": "osrm@^5.22.0",
  "_id": "osrm@5.22.0",
  "_inBundle": false,
  "_integrity": "sha512-+OTFX2XsvtBNY47hgkZfxqPhjdXB/wyz1iNqFpVrtNC16VHDvh7twrmOshMzHnRh/KCljJ5ogmRYix8d5
  "_location": "/sharedstreets/osrm",
  "_phantomChildren": {},
  "_requested": {
    "type": "range",
    "registry": true,
kpwebb commented 5 years ago

@josiekre I just pushed a fix for this, adding additional search steps to find the location of OSRM in node user directories. I tested this on docker and was able to get it to work:

Dockerfile:

FROM node:11

ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin

USER node
RUN git clone https://github.com/sharedstreets/sharedstreets-js.git /tmp/
RUN npm install -g sharedstreets

Docker image build: docker build --tag shst-image .

Run match on test data: docker run -it --rm shst-image shst match /tmp/test/geojson/line_2.in.geojson --out=/tmp/out.geojso

Thanks for investigating the docker steps -- I think that this will be useful of other users, especially those on Windows. The tricky part is making it easy to access data stored on the host computer from inside the docker container. I'm going to investigate if there are standardized approaches for dockerized CLI workflows and will push up this image once we can document the steps.

kpwebb commented 5 years ago

feature: #53 adding manual override for OSRM path

josiekre commented 5 years ago

Worked! Thanks for the quick fix.