Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruby as base instead of the monolithic passenger #476

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# remember to modify .gitlab-ci.yml
APP_BASE="${REGISTRY_URL}/mapotempo/optimizer_base:ruby${RUBY_VERSION}_bundle${BUNDLE_VERSION}"
BUNDLE_VERSION=2.2.19
REGISTRY_URL=dev.example.com
REGISTRY_URL=dev.example.com/
ROUTER_API_KEY=demo
ROUTER_URL=router.mapotempo.com/0.1
RUBY_VERSION=2.5-slim-bullseye
11 changes: 5 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version: '3.7'

x-app-args: &app-args
APP_BASE: ${APP_BASE}
ARCHITECTURE: ${ARCHITECTURE}
BUNDLE_VERSION: ${BUNDLE_VERSION}
RUBY_VERSION: ${RUBY_VERSION}
BUNDLE_WITHOUT: production
OPTIMIZER_ORTOOLS_VERSION: latest
REGISTRY_URL: ${REGISTRY_URL}

# keep command outside anchor because of performance problems
x-default-redis: &default-redis
Expand All @@ -21,8 +22,8 @@ x-default-environment: &default-environment
REDIS_HOST: redis-cache
REDIS_RESQUE_HOST: redis
REDIS_RESULT_TTL_DAYS: ${REDIS_RESULT_TTL_DAYS}
ROUTER_API_KEY: ${ROUTER_API_KEY:-demo}
ROUTER_URL: ${ROUTER_URL:-http://localhost:4899/0.1}
ROUTER_API_KEY: ${ROUTER_API_KEY}
ROUTER_URL: ${ROUTER_URL}
SENTRY_DSN: ${SENTRY_DSN}

x-environment-resque: &environment-resque
Expand All @@ -35,8 +36,6 @@ x-default-service: &default-service
context: .
dockerfile: docker/Dockerfile
image: dev.example.com/mapotempo/mt-optimizer
depends_on:
- base
volumes:
- ./:/srv/app/
- ./archives/dump:/tmp/optimizer-api/dump
Expand Down
53 changes: 17 additions & 36 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ARG ARCHITECTURE
ARG BRANCH
ARG BUNDLE_WITHOUT="development test"
ARG OPTIMIZER_ORTOOLS_VERSION
ARG REGISTRY
ARG REGISTRY_URL
ARG VROOM_VERSION

# Install Vroom
Expand All @@ -12,55 +13,35 @@ FROM vroomvrp/vroom-docker:${VROOM_VERSION:-v1.12.0} as vroom
# optimizer-api repo to force the CI to use a specific mapotempo/optimizer-ortools image.
# Mapotempo devs can also set this variable to their github username on their own optimizer-api repo
# to force the CI to use the last succesful username/optimizer-ortools image.
FROM ${REGISTRY:-registry.mapotempo.com/}mapotempo-${BRANCH:-ce}/optimizer-ortools:${OPTIMIZER_ORTOOLS_VERSION:-v1.17.1}
FROM ${REGISTRY_URL:-registry.mapotempo.com/}mapotempo-${BRANCH:-ce}/${ARCHITECTURE}optimizer-ortools:${OPTIMIZER_ORTOOLS_VERSION:-v1.17.1}
ARG BUNDLE_WITHOUT

ENV LANG C.UTF-8
LABEL maintainer="Mapotempo <tech@mapotempo.com>"

# Set correct environment variables.
ENV HOME /root

# Trick to install passenger-docker on Ruby 2.5. Othwerwise `apt-get update` fails with a
# certificate error. See following links for explanantion:
# https://issueexplorer.com/issue/phusion/passenger-docker/325
# and
# https://issueexplorer.com/issue/phusion/passenger-docker/322
# Basically, DST Root CA X3 certificates are expired on Setember 2021 and apt-get cannot validate
# with the old certificates and the certification correction is only done for Ruby 2.6+ on the
# passenger-docker repo because Ruby 2.5 is EOL.
RUN mv /etc/apt/sources.list.d /etc/apt/sources.list.d.bak
RUN apt update && apt install -y ca-certificates
RUN mv /etc/apt/sources.list.d.bak /etc/apt/sources.list.d
# The above trick can be removed after Ruby version is increased.
ENV LANG C.UTF-8
ENV REDIS_HOST redis-cache

RUN apt-get update > /dev/null && \
libgeos=$(apt-cache search 'libgeos-' | grep -P 'libgeos-\d.*' | awk '{print $1}') && \
apt-get install -y git libgeos-dev ${libgeos} libicu-dev libglpk-dev nano > /dev/null
apt-get install -y git libgeos-dev ${libgeos} libicu-dev libglpk-dev nano gawk bison > /dev/null

COPY --chown=app . /srv/app/
RUN install -d --owner app /srv/app/archives
# remove when ruby in optimizer-ortools is > 2.5
RUN wget -c https://ftp.gnu.org/gnu/glibc/glibc-2.29.tar.gz && \
tar -zxvf glibc-2.29.tar.gz && \
mkdir glibc-build && \
cd glibc-build && \
../glibc-2.29/configure --prefix=/opt/glibc && \
make && \
make install

USER app
WORKDIR /srv/app
COPY . /srv/app/
RUN mkdir -p /srv/app/archives

RUN gem install bundler --version 2.2.24 && \
bundle --version && \
bundle install --path vendor/bundle --full-index --without ${BUNDLE_WITHOUT} -j $(nproc)

LABEL maintainer="Mapotempo <tech@mapotempo.com>"

ENV REDIS_HOST redis-cache
ENV LANG C.UTF-8

USER root
COPY --from=vroom /usr/local/bin /srv/vroom/bin

USER root
# Enable Nginx and Passenger
RUN rm -f /etc/service/nginx/down && \
rm /etc/nginx/sites-enabled/default

# Enable app
ADD docker/env.d/* /etc/nginx/main.d/
ADD docker/snippets/* /etc/nginx/snippets/
ADD docker/webapp.conf /etc/nginx/sites-enabled/webapp.conf