-
-
Save andersoncarubelli/c9754594cb1d36a99649c4c65fb66be5 to your computer and use it in GitHub Desktop.
Docker + Rails + Puma + Postgres + Nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.git | |
.gitignore | |
doc | |
.yardoc | |
coverage | |
jsdoc | |
tmp | |
log | |
README.md | |
public/uploads/ | |
spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app: | |
env_file: .env | |
build: . | |
entrypoint: bundle exec | |
command: rails server -p 3000 | |
volumes: | |
- .:/app | |
ports: | |
- "3000" | |
links: | |
- postgres | |
postgres: | |
env_file: .env | |
image: postgres:9.4 | |
ports: | |
- "5432" | |
nginx: | |
image: nginx | |
links: | |
- app | |
volumes_from: | |
- app | |
volumes: | |
- ./nginx.conf:/etc/nginx/conf.d/my_app.conf:ro | |
ports: | |
- "80:80" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:2.3.1-slim | |
RUN apt-get update && apt-get install -qq -y build-essential | |
RUN apt-get install -y libpq-dev | |
RUN apt-get install -y --fix-missing libxml2-dev libxslt1-dev | |
RUN apt-get install -y nodejs | |
ENV INSTALL_PATH /app | |
ENV RAILS_ENV production | |
ENV RACK_ENV production | |
RUN mkdir $INSTALL_PATH | |
WORKDIR $INSTALL_PATH | |
COPY Gemfile* $INSTALL_PATH/ | |
RUN bundle install --jobs 20 --retry 5 --without development test | |
COPY . $INSTALL_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://chrisstump.online/2016/02/20/docker-existing-rails-application/ | |
upstream puma { | |
server app:3000; | |
} | |
server { | |
# define your domain | |
server_name my_app.com; | |
# define the public application root | |
root /app/public; | |
index index.html; | |
# define where Nginx should write its logs | |
access_log /app/log/nginx.access.log; | |
error_log /app/log/nginx.error.log; | |
# deny requests for files that should never be accessed | |
location ~ /\. { | |
deny all; | |
} | |
location ~* ^.+\.(rb|log)$ { | |
deny all; | |
} | |
# serve static (compiled) assets directly if they exist (for rails production) | |
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ { | |
try_files $uri @rails; | |
access_log off; | |
gzip_static on; # to serve pre-gzipped version | |
expires max; | |
add_header Cache-Control public; | |
# Some browsers still send conditional-GET requests if there's a | |
# Last-Modified header or an ETag header even if they haven't | |
# reached the expiry date sent in the Expires header. | |
add_header Last-Modified ""; | |
add_header ETag ""; | |
break; | |
} | |
# send non-static file requests to the app server | |
location / { | |
try_files $uri @rails; | |
} | |
location @rails { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_pass http://puma; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment