Skip to content

Commit 885baf2

Browse files
author
Ben Visser
committed
init commit
0 parents  commit 885baf2

File tree

7 files changed

+226
-0
lines changed

7 files changed

+226
-0
lines changed

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM ruby:2.2.5
2+
MAINTAINER iron.io
3+
4+
ARG DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update \
7+
&& apt-get install -qq -y software-properties-common wget vim
8+
9+
# install nginx
10+
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
11+
&& echo "deb http://nginx.org/packages/debian/ jessie nginx" >> /etc/apt/sources.list \
12+
&& apt-get update \
13+
&& apt-get install -qq -y nginx=1.10.2-1~jessie
14+
15+
# install foreman
16+
RUN gem install foreman \
17+
&& gem install unicorn
18+
19+
# install the latest postgresql lib for pg gem
20+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
21+
apt-get update && \
22+
apt-get install -y --force-yes libpq-dev
23+
24+
# install MySQL(for mysql, mysql2 gem)
25+
RUN apt-get install -qq -y libmysqlclient-dev
26+
27+
# install dockerize
28+
RUN wget -q https://github.com/jwilder/dockerize/releases/download/v0.2.0/dockerize-linux-amd64-v0.2.0.tar.gz \
29+
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.2.0.tar.gz
30+
31+
RUN apt-get clean \
32+
&& cd /var/lib/apt/lists && rm -fr *Release* *Sources* *Packages* \
33+
&& truncate -s 0 /var/log/*log
34+
35+
# install Rails App
36+
WORKDIR /app
37+
ENV RAILS_ENV production
38+
ONBUILD ADD Gemfile /app/Gemfile
39+
ONBUILD ADD Gemfile.lock /app/Gemfile.lock
40+
ONBUILD RUN bundle install --without development test
41+
ONBUILD ADD . /app
42+
ONBUILD RUN bundle exec rake assets:precompile
43+
44+
ADD nginx-sites.conf /etc/nginx/sites-enabled/default
45+
ADD nginx.conf /etc/nginx/nginx.conf
46+
ADD unicorn.rb /app/config/unicorn.rb
47+
ADD Procfile /app/Procfile
48+
49+
CMD foreman start -f Procfile

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: bundle exec unicorn -c config/unicorn.rb
2+
nginx: /usr/sbin/nginx -c /etc/nginx/nginx.conf

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Rails(+ Nginx, Unicorn) Dockerfile
2+
3+
Forked from https://github.com/seapy/dockerfiles/tree/master/rails-nginx-unicorn
4+
5+
Easy useable docker for rails. less configuration, affordable production.
6+
7+
## What's include
8+
9+
* unicorn, nginx, foreman
10+
* mysql, postgresql lib
11+
12+
# Usage
13+
14+
* Create `Dockerfile` to your project and paste below code.
15+
16+
```
17+
# Dockerfile
18+
FROM iron/rails-nginx-unicorn
19+
MAINTAINER iron.io
20+
21+
EXPOSE 80 443
22+
```
23+
24+
To use ssl you will have to mount your SSL key/crt to `/etc/nginx/ssl/server{crt,key}`
25+
26+
*NOTE*: assets are precompiled at build time, not run time to save on start time. You should specify the RAILS_ENV you want to use in your Dockerfile as well.
27+
28+
## Build and run docker
29+
30+
```
31+
# build your dockerfile
32+
$ docker build -t your/project .
33+
34+
# run container
35+
$ docker run -d -p 80:80 -e SECRET_KEY_BASE=secretkey your/project
36+
```
37+
38+
# Customize Nginx, Unicorn, foreman config
39+
40+
## Nginx
41+
42+
```
43+
# your Dockerfile
44+
...
45+
ADD config/your-custom-nginx.conf /etc/nginx/sites-enabled/default
46+
...
47+
```
48+
49+
## Unicorn
50+
51+
place your unicorn config to `config/unicorn.rb`
52+
53+
## foreman
54+
55+
place your Procfile to app root
56+
57+
58+
# Use a specific version of Ruby, Nginx
59+
60+
TODO: automatically build different images here.
61+
62+
# TODO
63+
64+
* github connection setting(like bitbucket)

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TODO

nginx-sites.conf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
upstream unicorn_server {
2+
server unix:/app/unicorn.sock fail_timeout=0;
3+
}
4+
5+
server {
6+
listen 80;
7+
listen [::]:80;
8+
listen 443 ssl http2;
9+
listen [::]:443 ssl http2;
10+
root /app/public;
11+
12+
ssl_certificate /etc/nginx/ssl/server.crt;
13+
ssl_certificate_key /etc/nginx/ssl/server.key;
14+
ssl_session_timeout 1d;
15+
ssl_session_cache shared:SSL:50m;
16+
ssl_session_tickets off;
17+
18+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
19+
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
20+
ssl_prefer_server_ciphers on;
21+
22+
keepalive_timeout 5;
23+
24+
try_files $uri @unicorn_server;
25+
location @unicorn_server {
26+
expires 0d;
27+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
28+
proxy_set_header X-Forwarded-Ssl on;
29+
proxy_set_header Host $http_host;
30+
proxy_set_header X-Forwarded-Proto $scheme;
31+
proxy_redirect off;
32+
proxy_pass http://unicorn_server;
33+
}
34+
35+
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
36+
gzip_static on;
37+
expires max;
38+
add_header Cache-Control public;
39+
add_header Last-Modified "";
40+
add_header ETag "";
41+
42+
open_file_cache max=1000 inactive=500s;
43+
open_file_cache_valid 600s;
44+
open_file_cache_errors on;
45+
break;
46+
}
47+
48+
error_page 500 502 503 504 /500.html;
49+
location = /500.html {
50+
root /app/public;
51+
}
52+
}

nginx.conf

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
user nginx;
2+
worker_processes 1;
3+
daemon off;
4+
error_log /app/error.log;
5+
6+
pid /app/nginx.pid;
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
# performance tuning
15+
sendfile on;
16+
tcp_nopush on;
17+
tcp_nodelay on;
18+
keepalive_timeout 30;
19+
keepalive_requests 100;
20+
21+
# caches information about open file descriptors for freqently accessed files.
22+
open_file_cache max=1000 inactive=20s;
23+
open_file_cache_valid 30s;
24+
open_file_cache_min_uses 2;
25+
open_file_cache_errors on;
26+
27+
# attack mitigation
28+
reset_timedout_connection on;
29+
client_body_timeout 10;
30+
send_timeout 2;
31+
server_tokens off;
32+
33+
include /etc/nginx/mime.types;
34+
default_type application/octet-stream;
35+
36+
37+
log_format extended '$remote_addr - $remote_user [$time_iso8601] '
38+
'"$request" $status $bytes_sent '
39+
'"$http_referer" "$http_user_agent" '
40+
'| $request_time $pipe $connection_requests $gzip_ratio $ssl_protocol/$ssl_cipher';
41+
access_log off;
42+
gzip off;
43+
44+
include /etc/nginx/sites-enabled/*;
45+
}
46+

unicorn.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
app_dir = "/app"
2+
3+
working_directory app_dir
4+
5+
pid "#{app_dir}/unicorn.pid"
6+
7+
stderr_path "#{app_dir}/unicorn.stderr.log"
8+
stdout_path "#{app_dir}/unicorn.stdout.log"
9+
10+
worker_processes 1
11+
listen "#{app_dir}/unicorn.sock", :backlog => 64
12+
timeout 30

0 commit comments

Comments
 (0)