Skip to content

Commit

Permalink
Make dev easier
Browse files Browse the repository at this point in the history
  • Loading branch information
alain-andre committed Sep 26, 2022
1 parent 18855c5 commit 7cd8491
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 32 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ Running
=======

```
bundle exec rackup [-p 4899]
bundle exec rackup [-o 0.0.0.0] [-p 4899]
```

And in production mode:
```
APP_ENV=production bundle exec rackup [-p 4899]
APP_ENV=production bundle exec rackup [-o 0.0.0.0] [-p 4899]
```

Available production extra environment variables are:
```
REDIS_HOST=example.com
```

Testing
Docker runtime
=======

Create a `.env` file with HERE_APP_ID and HERE_APP_CODE values

Build docker images
```
cd docker/
Expand All @@ -51,6 +53,11 @@ Build and launch containers
docker-compose -p router up -d
```

Launch server
```
bundle exec rackup -o 0.0.0.0
```

Generate otp graph
```
cd otp
Expand Down
42 changes: 19 additions & 23 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
# along with Mapotempo. If not, see:
# <http://www.gnu.org/licenses/agpl.html>
#
require "redis"
require 'active_support'
require 'active_support/core_ext'
require 'byebug'
require 'dotenv'
require 'tmpdir'
require 'byebug'

require './wrappers/crow'
require './wrappers/here'
require './wrappers/osrm'
require './wrappers/otp'
require './wrappers/here'

require './lib/cache_manager'

Expand Down Expand Up @@ -58,16 +58,22 @@ module RouterWrapper
}
]

CACHE = CacheManager.new(ActiveSupport::Cache::FileStore.new(File.join(Dir.tmpdir, 'router'), namespace: 'router', expires_in: 60*60*24*1))

CACHE = CacheManager.new(ActiveSupport::Cache::NullStore.new)
CROW = Wrappers::Crow.new(CACHE)
OSRM = Wrappers::Osrm.new(CACHE, url_time: 'http://router.project-osrm.org', url_distance: 'http://router.project-osrm.org', url_isochrone: 'http://localhost:1723', url_isodistance: 'http://localhost:1723', area_mapping: area_mapping, whitelist_classes: whitelist_classes, with_summed_by_area: true, licence: 'ODbL', attribution: '© OpenStreetMap contributors')
OTP_BORDEAUX = Wrappers::Otp.new(CACHE, url: 'http://localhost:7001', router_id: 'bordeaux', licence: 'ODbL', attribution: 'Bordeaux Métropole', area: 'Bordeaux', crs: 'EPSG:2154')

url_time = 'http://router.project-osrm.org'
url_distance = url_time
OSRM = Wrappers::Osrm.new(CACHE, url_time: url_time, url_distance: url_distance, url_isochrone: 'http://localhost:1723', url_isodistance: 'http://localhost:1723', with_summed_by_area: true, licence: 'ODbL', attribution: '© OpenStreetMap contributors')

OTP_BORDEAUX = Wrappers::Otp.new(CACHE, url: 'http://localhost:7000', router_id: 'idf', licence: 'ODbL', attribution: 'Bordeaux Métropole', area: 'Bordeaux', crs: 'EPSG:2154')

HERE_TRUCK = Wrappers::Here.new(CACHE, app_id: ENV['HERE_APP_ID'], app_code: ENV['HERE_APP_CODE'], mode: 'truck')
HERE_CAR = Wrappers::Here.new(CACHE, app_id: ENV['HERE_APP_ID'], app_code: ENV['HERE_APP_CODE'], mode: 'car')

PARAMS_LIMIT = { locations: 1000 }.freeze
PARAMS_LIMIT = { locations: 1_000_000 }.freeze

REDIS_COUNT = ENV['REDIS_COUNT_HOST'] && Redis.new(host: ENV['REDIS_COUNT_HOST'])

QUOTAS = [{ daily: 100000, monthly: 1000000, yearly: 10000000 }].freeze # Only taken into account if REDIS_COUNT

@@c = {
Expand All @@ -78,20 +84,6 @@ module RouterWrapper
file: './config/access.rb'
},
profiles: {
light: {
route_default: :crow,
params_limit: PARAMS_LIMIT,
quotas: QUOTAS, # Only taken into account if REDIS_COUNT
route: {
crow: [CROW],
},
matrix: {
crow: [CROW],
},
isoline: {
crow: [CROW],
}
},
standard: {
route_default: :osrm,
params_limit: PARAMS_LIMIT,
Expand All @@ -100,18 +92,22 @@ module RouterWrapper
osrm: [OSRM],
crow: [CROW],
otp: [OTP_BORDEAUX],
here: [HERE_TRUCK],
truck: [HERE_TRUCK],
here_car: [HERE_CAR],
},
matrix: {
crow: [CROW],
osrm: [OSRM],
otp: [OTP_BORDEAUX],
here: [HERE_TRUCK],
truck: [HERE_TRUCK],
here_car: [HERE_CAR],
},
isoline: {
crow: [CROW],
osrm: [OSRM],
otp: [OTP_BORDEAUX],
truck: [HERE_TRUCK],
here_car: [HERE_CAR],
}
}
},
Expand Down
8 changes: 5 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ en:
crow:
name: Crow flie
osrm:
name: Open Source Routing Engine 5
name: VL OSRM
otp:
name: OpenTripPlanner
here:
name: HERE
here_truck:
name: PL HERE
here_car:
name: VL HERE
8 changes: 5 additions & 3 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ fr:
crow:
name: Vol d'oiseau
osrm:
name: Open Source Routing Engine 5
name: VL OSRM
otp:
name: OpenTripPlanner
here:
name: HERE
here_truck:
name: PL HERE
here_car:
name: VL HERE
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.7'

x-app-args: &app-args
APP_BASE: ${APP_BASE}
BUNDLE_VERSION: ${BUNDLE_VERSION}
RUBY_VERSION: ${RUBY_VERSION}
BUNDLE_WITHOUT: production

x-default-environment: &default-environment
HERE_APP_CODE: ${HERE_APP_CODE}
HERE_APP_ID: ${HERE_APP_ID}
RAVEN_DSN: localhost
REDIS_COUNT_HOST: redis-count
REDIS_HOST: redis-cache

services:
redis-cache:
image: redis:${REDIS_VERSION:-6.2.5-alpine}
volumes:
- ./redis:/data
hostname: redis-cache

redis-count:
image: redis:${REDIS_VERSION:-6.2.5-alpine}
volumes:
- ./redis-count:/data
hostname: redis-count
command: redis-server --appendonly yes

main:
build:
args:
<<: *app-args
context: .
dockerfile: docker/dev/Dockerfile
image: dev.example.com/mapotempo/mt-router
volumes:
- ./:/srv/app/
- app_cache_vendor:/srv/app/vendor
environment:
<<: *default-environment
ports:
- "4899:4899"
tty: true

volumes:
app_cache_vendor:
21 changes: 21 additions & 0 deletions docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Take car of the latest version containing bundler 1.17
FROM ruby:2.5

ARG BUNDLE_WITHOUT="production"

# Set correct environment variables.
ENV LANG C.UTF-8
ENV HOME /root


ENV REDIS_HOST redis-cache

ADD . /srv/app
WORKDIR /srv/app

# Install app
# because of Certificate verification failed
RUN apt update && apt upgrade -y
RUN apt-get install -y git build-essential zlib1g-dev zlib1g > /dev/null
RUN gem install bundler --version 1.17.3
RUN bundle install --path vendor/bundle --full-index --without ${BUNDLE_WITHOUT}

0 comments on commit 7cd8491

Please sign in to comment.