diff --git a/.env b/.env new file mode 100644 index 00000000..2ae96b2a --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +ARCHITECTURE=arm64v8/ +RUBY_VERSION=2.6 +ORTOOLS_VERSION=v7.8 # select from https://github.com/google/or-tools/releases diff --git a/.github/actions/build.sh b/.github/actions/build.sh index a51a4c67..5e7dce22 100755 --- a/.github/actions/build.sh +++ b/.github/actions/build.sh @@ -13,25 +13,7 @@ fi IMAGE_NAME=${REGISTRY}/mapotempo-ce/optimizer-ortools:${TAG} -case $ORTOOLS_VERSION in - 'v7.1') - export ORTOOLS_URL="https://github.com/google/or-tools/releases/download/v7.1/or-tools_debian-9_v7.1.6720.tar.gz" - ;; - 'v7.4') - export ORTOOLS_URL="https://github.com/google/or-tools/releases/download/v7.4/or-tools_debian-9_v7.4.7247.tar.gz" - ;; - 'v7.5') - export ORTOOLS_URL="https://github.com/google/or-tools/releases/download/v7.5/or-tools_debian-10_v7.5.7466.tar.gz" - ;; - 'v7.8') - export ORTOOLS_URL="https://github.com/google/or-tools/releases/download/v7.8/or-tools_debian-10_v7.8.7959.tar.gz" - ;; - *) - echo "Unknown OR-Tools version" -esac - -echo "Download asset at ${ORTOOLS_URL}" -docker build --build-arg ORTOOLS_URL=${ORTOOLS_URL} -f ./Dockerfile -t "${IMAGE_NAME}" . +docker build --build-arg RUBY_VERSION=="2.6" --build-arg ORTOOLS_VERSION="${ORTOOLS_VERSION}" -f ./Dockerfile -t "${IMAGE_NAME}" . docker run -d --name optimizer -t "${IMAGE_NAME}" docker exec -i optimizer bash -c "LD_LIBRARY_PATH=/srv/or-tools/lib/ /srv/optimizer-ortools/tsp_simple -time_limit_in_ms 500 -intermediate_solutions -instance_file '/srv/optimizer-ortools/data/test_ortools_single_route_with_route_order' -solution_file '/tmp/optimize-or-tools-output'" diff --git a/Dockerfile b/Dockerfile index 7a00957a..1d05519e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,24 @@ -# 1.0.13 is the latest version containing bundler 2 required for optimizer-api -FROM phusion/passenger-ruby25:1.0.13 +ARG RUBY_VERSION +ARG ARCHITECTURE -ARG ORTOOLS_URL=${ORTOOLS_URL} +FROM ${ARCHITECTURE}ruby:${RUBY_VERSION} -LABEL maintainer="Mapotempo " +ARG ORTOOLS_VERSION=${ORTOOLS_VERSION} -WORKDIR /srv/ - -# 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. +LABEL maintainer="Mapotempo " RUN apt-get update > /dev/null && \ - apt-get -y install git wget pkg-config build-essential cmake autoconf libtool zlib1g-dev lsb-release > /dev/null + apt install -y git build-essential cmake swig lsb-release python3-pip autoconf libtool zlib1g-dev > /dev/null && \ + git clone -b ${ORTOOLS_VERSION} https://github.com/google/or-tools /srv/or-tools ADD . /srv/or-tools +WORKDIR /srv/or-tools -RUN wget -qO- $ORTOOLS_URL | tar xz --strip-components=1 -C /srv/or-tools +RUN cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_PYTHON=ON && \ + # Create code + cmake --build build --config Release --target all -j -v && \ + # build + cmake --build build --config Release --target install -v ADD . /srv/optimizer-ortools diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..2b16737a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3.7' +x-app-args: &app-args + ARCHITECTURE: ${ARCHITECTURE} + RUBY_VERSION: ${RUBY_VERSION} + ORTOOLS_VERSION: ${ORTOOLS_VERSION} + +x-app: &default-app + volumes: + - ./:/srv/app/ + env_file: + - ./.env + +services: + main: + <<: *default-app + build: + args: + <<: *app-args + context: . + dockerfile: Dockerfile + image: dev.example.com/mapotempo/optimizer-ortools + tty: true