Skip to content

Instantly share code, notes, and snippets.

@kitwalker12
Last active September 14, 2016 17:58
Show Gist options
  • Save kitwalker12/2e5ae0e2b715b00a30a8 to your computer and use it in GitHub Desktop.
Save kitwalker12/2e5ae0e2b715b00a30a8 to your computer and use it in GitHub Desktop.
Dockerized Rails on Tutum (Passenger + HAProxy)

How to deploy rails in tutum as a production server behing HAproxy on Passenger

docker build -t 'my_image_name:latest' . && tutum image push my_image_name:latest
AWS_ACCESS_KEY_ID=ABCXYZ
AWS_SECRET_ACCESS_KEY=ABCXYZ
RACK_ENV=production
RAILS_ENV=production
DATABASE_URL=postgres://myuser:mypass@localhost:5432/web
FROM phusion/passenger-ruby20:0.9.17
# Set correct environment variables.
ENV HOME /root
# Expose Nginx HTTP service
EXPOSE 80
EXPOSE 443
# Start Nginx / Passenger
RUN rm -f /etc/service/nginx/down
# Remove the default site
RUN rm /etc/nginx/sites-enabled/default
# Add the nginx site and config
ADD nginx.conf /etc/nginx/sites-enabled/web.conf
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
# Install bundle of gems
WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
# Add the Rails app
ADD . /home/app/web
RUN chown -R app:app /home/app/web
WORKDIR /home/app/web
RUN set -a && . /home/app/web/.env && bundle exec rake assets:precompile --trace
server {
listen 80;
server_name localhost;
root /home/app/web/public;
passenger_enabled on;
passenger_user app;
passenger_app_env <my environment, Ex: staging, production>;
passenger_ruby /usr/bin/ruby2.0;
}
#All Environment Variables you need preserved because passenger deletes them all by default
env AWS_ACCESS_KEY_ID;
env AWS_SECRET_ACCESS_KEY;
env RAILS_ENV;
env RACK_ENV;
env DATABASE_URL;
env REDIS_URL;
redis:
image: 'tutum/redis:latest'
environment:
- REDIS_PASS=mypass
ports:
- '6379:6379'
restart: always
roles:
- global
db:
image: 'postgres:9.4'
environment:
- POSTGRES_PASSWORD=mypass
- POSTGRES_USER=myuser
ports:
- '5432:5432'
restart: always
roles:
- global
lb:
image: 'tutum/haproxy:latest'
environment:
- 'DEFAULT_SSL_CERT=<paste cert here. Method here: https://github.com/tutumcloud/haproxy#user-content-ssl-termination>'
links:
- web
ports:
- '80:80'
- '443:443'
restart: always
roles:
- global
web:
image: 'my_image_name'
command: '/sbin/my_init'
environment:
#All my env vars
- AWS_ACCESS_KEY_ID=ABCXYZ
- AWS_SECRET_ACCESS_KEY=ABCXYZ
- 'DATABASE_URL=postgres://myuser:mypass@db:5432/web'
- RACK_ENV=<my environment>
- RAILS_ENV=<my environment>
- 'REDIS_URL=redis://:mypass@redis:6379/0'
- 'VIRTUAL_HOST=http://mydomain.com,https://mydomain.com'
expose:
- '80'
- '443'
links:
- db
- redis
restart: on-failure
roles:
- global
target_num_containers: 2
sidekiq:
image: 'my_image_name'
command: 'bundle exec sidekiq'
environment:
#All my env vars
- AWS_ACCESS_KEY_ID=ABCXYZ
- AWS_SECRET_ACCESS_KEY=ABCXYZ
- 'DATABASE_URL=postgres://myuser:mypass@db:5432/web'
- RACK_ENV=<my environment>
- RAILS_ENV=<my environment>
- 'REDIS_URL=redis://:mypass@redis:6379/0'
links:
- db
- redis
restart: on-failure
roles:
- global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment