Skip to content

Commit

Permalink
Merge pull request #304 from alain-andre/docker-compose-use-anchor
Browse files Browse the repository at this point in the history
Docker: use anchor in docker-compose file
  • Loading branch information
fab-girard authored Dec 2, 2021
2 parents 1294630 + f687c48 commit 843abf2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/actions/launch_stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
docker swarm init
mkdir -p ./redis
mkdir -p ./redis-count
docker stack deploy -c ./docker/docker-compose.yml "${PROJECT}"
REGISTRY=registry.test.com docker stack deploy -c ./docker/docker-compose.yml "${PROJECT}"

# Wait until all services are up
max_time=60 # Time in secondes
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO use anchor when supported https://github.community/t/support-for-yaml-anchors/16128/81
name: Docker Image CI

on:
Expand Down Expand Up @@ -39,7 +40,7 @@ jobs:
BUNDLE_WITHOUT=production
OPTIMIZER_ORTOOLS_VERSION=${{ secrets.OPTIMIZER_ORTOOLS_VERSION }}
VROOM_VERSION=${{ secrets.VROOM_VERSION }}
tags: registry.test.com/mapotempo/optimizer-api:latest
tags: registry.test.com/mapotempo-ce/optimizer-api:latest
outputs: type=docker,dest=/tmp/optimizer-api.tar
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
Expand All @@ -52,7 +53,7 @@ jobs:
rm -rf vendor/bundle
mkdir -p vendor/bundle
docker load --input /tmp/optimizer-api.tar
docker cp "$(docker create --rm registry.test.com/mapotempo/optimizer-api:latest)":/srv/app/vendor/bundle/. vendor/bundle
docker cp "$(docker create --rm registry.test.com/mapotempo-ce/optimizer-api:latest)":/srv/app/vendor/bundle/. vendor/bundle
echo $(ls -lh vendor/bundle)
- name: Upload artifact
uses: actions/upload-artifact@v2
Expand Down
45 changes: 25 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ARG BRANCH=${BRANCH:-ce}
ARG OPTIMIZER_ORTOOLS_VERSION=${OPTIMIZER_ORTOOLS_VERSION}
ARG REGISTRY=${REGISTRY:-registry.mapotempo.com/}
ARG VROOM_VERSION=${VROOM_VERSION}
ARG BRANCH
ARG BUNDLE_WITHOUT="development test"
ARG OPTIMIZER_ORTOOLS_VERSION
ARG REGISTRY
ARG VROOM_VERSION

# Install Vroom
FROM vroomvrp/vroom-docker:${VROOM_VERSION:-v1.8.0} as vroom

# Rake
FROM ${REGISTRY}mapotempo-${BRANCH}/optimizer-ortools:${OPTIMIZER_ORTOOLS_VERSION:-v1.9.0}
FROM ${REGISTRY:-registry.mapotempo.com/}mapotempo-${BRANCH:-ce}/optimizer-ortools:${OPTIMIZER_ORTOOLS_VERSION:-v1.9.0}
ARG BUNDLE_WITHOUT

ENV LANG C.UTF-8
Expand All @@ -29,15 +29,19 @@ 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.

RUN apt-get update > /dev/null
RUN libgeos=$(apt-cache search 'libgeos-' | grep -P 'libgeos-\d.*' | awk '{print $1}')
RUN apt-get install -y git libgeos-dev ${libgeos} libicu-dev nano > /dev/null
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 nano > /dev/null

COPY . /srv/app
COPY --chown=app . /srv/app/
RUN install -d --owner app /srv/app/archives

USER app
WORKDIR /srv/app
RUN gem install bundler --version 2.2.24
RUN bundle --version
RUN bundle install --path vendor/bundle --full-index --without ${BUNDLE_WITHOUT} -j $(nproc)

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>"

Expand All @@ -46,17 +50,18 @@ ENV LANG C.UTF-8

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

RUN apt-get remove -y git build-essential && \
apt-get autoremove -y && \
apt-get clean && \
echo -n > /var/lib/apt/extended_states && \
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*

USER root
# Enable Nginx and Passenger
RUN rm -f /etc/service/nginx/down
RUN rm /etc/nginx/sites-enabled/default
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

RUN apt-get remove -y git build-essential && \
apt-get autoremove -y && \
apt-get clean && \
echo -n > /var/lib/apt/extended_states && \
rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*
62 changes: 38 additions & 24 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,74 @@
version: '3.7'

# keep command outside anchor because of performance problems
x-default-redis: &default-redis
image: redis:${REDIS_VERSION:-6.2.5-alpine}
deploy:
restart_policy:
condition: any
volumes:
- ${APP_HOME:-..}/redis:/data

x-default-environment: &default-environment
PASSENGER_APP_ENV: test
REDIS_COUNT_HOST: redis-count
REDIS_HOST: redis-cache
REDIS_RESQUE_HOST: redis

x-environment-resque: &environment-resque
<<: *default-environment
APP_ENV: test
ROUTER_API_KEY: ${ROUTER_API_KEY:-demo}
ROUTER_URL: ${ROUTER_URL:-http://localhost:4899/0.1}

x-default-service: &default-service
image: ${REGISTRY:-registry.mapotempo.com}/mapotempo-${EDT:-ce}/optimizer-api:${OPTIMIZER_VERSION:-latest}
environment:
<<: *default-environment
networks:
- redis_cache
- redis_count
- resque

services:
redis:
image: redis:${REDIS_VERSION:-6.2.5-alpine}
<<: *default-redis
hostname: redis
volumes:
- ${APP_HOME:-..}/redis:/data
command: redis-server --appendonly yes
networks:
- resque

redis-cache:
image: redis:${REDIS_VERSION:-6.2.5-alpine}
<<: *default-redis
hostname: redis-cache
volumes:
- ${APP_HOME:-..}/redis:/data
command: redis-server --save ""
networks:
- redis_cache

redis-count:
image: redis:${REDIS_VERSION:-6.2.5-alpine}
<<: *default-redis
volumes:
- ${APP_HOME:-..}/redis-count:/data
hostname: redis-count
command: redis-server --appendonly yes
deploy:
restart_policy:
condition: any
networks:
- redis_count

api:
image: registry.test.com/mapotempo/optimizer-api:latest
environment:
PASSENGER_APP_ENV: test
REDIS_COUNT_HOST: redis-count
REDIS_HOST: redis-cache
REDIS_RESQUE_HOST: redis
<<: *default-service
hostname: api
networks:
- base
- redis_cache
- redis_count
- resque

resque-default:
image: registry.test.com/mapotempo/optimizer-api:latest
working_dir: /srv/app
<<: *default-service
environment:
APP_ENV: test
<<: *environment-resque
COUNT: 5
QUEUES: DEFAULT
REDIS_COUNT_HOST: redis-count
REDIS_HOST: redis-cache
REDIS_RESQUE_HOST: redis
ROUTER_API_KEY: ${ROUTER_API_KEY:-demo}
ROUTER_URL: ${ROUTER_URL:-http://localhost:4899/0.1}
command: bundle exec rake resque:workers
networks:
- redis_cache
Expand Down
2 changes: 1 addition & 1 deletion docker/webapp.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Log format with timings.
log_format vhost_timed_combined '$host:$server_port $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time $upstream_response_time $msec';
log_format timed_combined '$host:$server_port $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time $upstream_response_time $msec';

# Asynchronous IO threads.
aio threads;
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
DichotomiousTest#test_dichotomious_approach
RealCasesTest#test_ortools_open_timewindows
SplitClusteringTest#test_avoid_capacities_overlap
SplitClusteringTest#test_instance_same_point_day
SplitClusteringTest#test_no_doubles_3000
WrapperTest#test_detecting_unfeasible_services_can_not_take_too_long
]
Expand Down

0 comments on commit 843abf2

Please sign in to comment.