From 11c2d760bc33f0919ca346942f8d55171459c7cf Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Fri, 20 Jul 2018 21:02:46 +0100 Subject: [PATCH] Replace Unicorn with Puma --- Dockerfile | 2 +- Gemfile | 2 +- Gemfile.lock | 8 ++------ config/puma.rb | 11 +++++++++++ config/unicorn.rb | 11 ----------- docker-compose.override.yml | 2 +- docker-compose.yml | 4 ++-- 7 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 config/puma.rb delete mode 100644 config/unicorn.rb diff --git a/Dockerfile b/Dockerfile index a16829f..f17921f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,4 @@ ADD Gemfile /app/Gemfile ADD Gemfile.lock /app/Gemfile.lock RUN bundle install --jobs=8 --without development test ADD . /app -CMD ["unicorn", "-c", "./config/unicorn.rb"] +CMD ["puma", "-C", "config/puma.rb"] diff --git a/Gemfile b/Gemfile index 9beda69..eb13ba0 100644 --- a/Gemfile +++ b/Gemfile @@ -6,12 +6,12 @@ ruby '2.5.1' gem 'oj' gem 'ox' +gem 'puma' gem 'rack-cors' gem 'rake' gem 'rufus-scheduler' gem 'sequel_pg' gem 'sinatra' -gem 'unicorn' group :development do gem 'guard' diff --git a/Gemfile.lock b/Gemfile.lock index 915e954..744c16c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,7 +39,6 @@ GEM hashdiff (0.3.7) http_parser.rb (0.6.0) jaro_winkler (1.4.0) - kgio (2.11.2) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -66,6 +65,7 @@ GEM coderay (~> 1.1.0) method_source (~> 0.9.0) public_suffix (3.0.2) + puma (3.11.4) raabro (1.1.5) rack (2.0.5) rack-cors (1.0.2) @@ -76,7 +76,6 @@ GEM rack-test (1.0.0) rack (>= 1.0, < 3) rainbow (3.0.0) - raindrops (0.19.0) rake (12.3.1) rb-fsevent (0.10.3) rb-inotify (0.9.10) @@ -112,9 +111,6 @@ GEM tzinfo (1.2.5) thread_safe (~> 0.1) unicode-display_width (1.4.0) - unicorn (5.4.0) - kgio (~> 2.6) - raindrops (~> 0.7) vcr (4.0.0) webmock (3.4.2) addressable (>= 2.3.6) @@ -133,6 +129,7 @@ DEPENDENCIES oj ox pry + puma rack-cors rack-livereload rack-test @@ -142,7 +139,6 @@ DEPENDENCIES sequel_pg shotgun sinatra - unicorn vcr webmock diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..34ff185 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +workers Integer(ENV['WEB_CONCURRENCY'] || 2) +threads_count = Integer(ENV['MAX_THREADS'] || 5) +threads threads_count, threads_count + +preload_app! + +rackup DefaultRackup +port ENV['PORT'] || 3000 +environment ENV['APP_ENV'] || 'developments' diff --git a/config/unicorn.rb b/config/unicorn.rb deleted file mode 100644 index bb3101f..0000000 --- a/config/unicorn.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -worker_process_count = (ENV['WORKER_PROCESSES'] || 4).to_i - -preload_app true -worker_processes worker_process_count -timeout 10 - -before_fork do |_, _| - Sequel::DATABASES.each(&:disconnect) -end diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 254bf9f..5b2da16 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -6,7 +6,7 @@ services: APP_ENV: development VIRTUAL_HOST: localhost ports: - - "8080:8080" + - "3000:3000" scheduler: build: . environment: diff --git a/docker-compose.yml b/docker-compose.yml index 1d994b7..c0080de 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,12 +5,12 @@ services: volumes: - data:/var/lib/postgresql/data web: - command: unicorn -c config/unicorn.rb + command: puma -C config/puma.rb entrypoint: bin/wait-for-it.sh db:5432 -s -- environment: DATABASE_URL: postgres://postgres@db/postgres expose: - - '8080' + - '3000' links: - db scheduler: