From 7cd84916a48046c478a9f8605e1c05fd7b5bbb66 Mon Sep 17 00:00:00 2001 From: Alain ANDRE Date: Mon, 26 Sep 2022 16:04:49 +0200 Subject: [PATCH] Make dev easier --- README.md | 13 +++++++-- config/environments/development.rb | 42 ++++++++++++-------------- config/locales/en.yml | 8 +++-- config/locales/fr.yml | 8 +++-- docker-compose.yml | 47 ++++++++++++++++++++++++++++++ docker/dev/Dockerfile | 21 +++++++++++++ 6 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 docker-compose.yml create mode 100644 docker/dev/Dockerfile diff --git a/README.md b/README.md index 229e908..d6e5d32 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,12 @@ 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: @@ -37,9 +37,11 @@ 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/ @@ -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 diff --git a/config/environments/development.rb b/config/environments/development.rb index d4bda54..4223fdd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -15,17 +15,17 @@ # along with Mapotempo. If not, see: # # +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' @@ -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 = { @@ -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, @@ -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], } } }, diff --git a/config/locales/en.yml b/config/locales/en.yml index 2c96f24..d4c317a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b61d012..f911223 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8e5feca --- /dev/null +++ b/docker-compose.yml @@ -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: diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile new file mode 100644 index 0000000..9b2ad49 --- /dev/null +++ b/docker/dev/Dockerfile @@ -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}