Skip to content

Commit

Permalink
Merge pull request #2060 from scott/update-compose
Browse files Browse the repository at this point in the history
Switch compose to use puma, nginx closes #1926 closes #1909 closes #1702
  • Loading branch information
scott committed Oct 20, 2021
2 parents 6ca8178 + 091cfa3 commit 26aff0e
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
10 changes: 7 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -714,6 +717,7 @@ DEPENDENCIES
premailer-rails
pry
pry-byebug
puma
rack-cors
rails (= 4.2.11.1)
rails-i18n (~> 4.0.9)
Expand Down
9 changes: 9 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 7 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +23,8 @@ services:
env_file: docker/.env
depends_on:
- postgres
ports:
- "3000:3000"
postgres:
image: postgres:9.4
restart: always
Expand Down
70 changes: 70 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
4 changes: 2 additions & 2 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 26aff0e

Please sign in to comment.