From 091cfa3bc500250ceb82c1b5e4140c0931e44336 Mon Sep 17 00:00:00 2001 From: Scott Miller Date: Tue, 5 Oct 2021 14:02:20 -0600 Subject: [PATCH] Switch compose to use puma, nginx --- Dockerfile | 2 ++ Gemfile | 3 +- Gemfile.lock | 10 +++++-- config/puma.rb | 9 ++++++ docker-compose.yml | 16 +++++------ docker/nginx.conf | 70 ++++++++++++++++++++++++++++++++++++++++++++++ docker/run.sh | 4 +-- 7 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 config/puma.rb create mode 100644 docker/nginx.conf diff --git a/Dockerfile b/Dockerfile index 943be02b2..fd3cf972f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,4 +46,6 @@ USER $HELPY_USER COPY docker/database.yml $HELPY_HOME/config/database.yml +EXPOSE 3000 + CMD ["/bin/bash", "/helpy/docker/run.sh"] diff --git a/Gemfile b/Gemfile index 9a998415a..1aeb8c0ec 100644 --- a/Gemfile +++ b/Gemfile @@ -211,7 +211,8 @@ end group :production do # Uncomment this gem for Heroku: # gem 'rails_12factor' - gem 'unicorn' + gem 'unicorn' #kept for backwards compatibility + gem 'puma' end ruby '>= 2.2', '< 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 08c1f93b3..40f69656e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -339,7 +339,7 @@ GEM kaminari-i18n (0.5.0) kaminari rails - kgio (2.11.3) + kgio (2.11.4) launchy (2.5.0) addressable (~> 2.7) less (2.6.0) @@ -388,6 +388,7 @@ GEM mustermann-grape (1.0.1) mustermann (>= 1.0.0) netrc (0.11.0) + nio4r (2.5.8) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) oauth (0.5.4) @@ -448,6 +449,8 @@ GEM byebug (~> 10.0) pry (~> 0.10) public_suffix (4.0.6) + puma (5.5.0) + nio4r (~> 2.0) rack (1.6.13) rack-accept (0.4.5) rack (>= 0.4) @@ -489,7 +492,7 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (2.2.2) rake - raindrops (0.19.1) + raindrops (0.19.2) rake (13.0.1) ranked-model (0.4.1) activerecord (>= 3.1.12) @@ -605,7 +608,7 @@ GEM unf_ext unf_ext (0.0.7.7) unicode-display_width (1.7.0) - unicorn (5.7.0) + unicorn (6.0.0) kgio (~> 2.6) raindrops (~> 0.7) warden (1.2.7) @@ -714,6 +717,7 @@ DEPENDENCIES premailer-rails pry pry-byebug + puma rack-cors rails (= 4.2.11.1) rails-i18n (~> 4.0.9) diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 000000000..0ab77ab84 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,9 @@ +environment ENV.fetch 'RAILS_ENV', 'production' + +threads 0, 16 + +bind 'tcp://0.0.0.0:3000' + +on_worker_boot do + ActiveRecord::Base.establish_connection +end \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8e84aa4a8..370c51cf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,20 +2,16 @@ version: '2' services: frontend: - image: webwurst/caddy + image: nginx:1.15 + container_name: nginx volumes: - - ./docker/Caddyfile:/etc/caddy/Caddyfile - - ./certs:/etc/caddy/certs - volumes_from: - - helpy:ro + - ./docker/nginx.conf:/etc/nginx/nginx.conf ports: - - "80:80" - - "443:443" + - 80:80 + - 443:443 networks: - front restart: always - depends_on: - - helpy helpy: build: . restart: always @@ -27,6 +23,8 @@ services: env_file: docker/.env depends_on: - postgres + ports: + - "3000:3000" postgres: image: postgres:9.4 restart: always diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 000000000..eedcf69d0 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,70 @@ + user www-data; + worker_processes 4; + pid /run/nginx.pid; + + events { + worker_connections 768; + # multi_accept on; + } + + http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + #include /etc/nginx/mime.types; + #default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + gzip_disable "msie6"; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + + server { + listen 80; + + location / { + proxy_pass http://helpy:3000/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + } + } diff --git a/docker/run.sh b/docker/run.sh index a2ebcccc2..63d154b01 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -29,8 +29,8 @@ if [[ "$RUN_PREPARE" = "false" ]] bundle exec rake db:seed || echo "db is already seeded" fi -echo "starting unicorn" +echo "starting puma" mkdir -p log touch log/production.log -exec bundle exec unicorn -E production -c config/unicorn.rb +exec bundle exec puma -C config/puma.rb \ No newline at end of file