Last active
September 9, 2016 04:21
-
-
Save itsprdp/667b9fe04a4e85bdb64b to your computer and use it in GitHub Desktop.
RubyApp Dockerfile for staging
This file contains hidden or 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
# Building rails-base image for the rubyapp | |
FROM phusion/passenger-ruby22 | |
MAINTAINER Pradeep "[email protected]" | |
# Set correct environment variables. | |
ENV HOME /root | |
# Use baseimage-docker's init process. | |
CMD ["/sbin/my_init"] | |
# Enable nginx, add user `app` to group `www-data`, gemrc config | |
# open nginx log directory to the group so that `app` user process can write | |
RUN rm -f /etc/nginx/sites-enabled/default* \ | |
&& rm -f /etc/nginx/sites-available/default* \ | |
&& rm -f /etc/service/nginx/down \ | |
&& usermod -aG www-data app \ | |
&& chmod -R 0775 /var/log/nginx \ | |
&& echo "gem: --no-document" > /home/app/.gemrc | |
# docker-rubyapp.pub is added to github.com | |
ADD ./ssh/docker-rubyapp /root/.ssh/docker-rubyapp | |
# Up and running with git credentials | |
RUN chmod 600 /root/.ssh/docker-rubyapp \ | |
&& touch /root/.ssh/known_hosts \ | |
&& echo "IdentityFile /root/.ssh/docker-rubyapp" >> /etc/ssh/ssh_config \ | |
&& ssh-keyscan github.com >> /root/.ssh/known_hosts |
This file contains hidden or 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 rails-base | |
MAINTAINER Pradeep "[email protected]" | |
# Use baseimage-docker's init process. | |
CMD ["/sbin/my_init"] | |
# Staging | |
ENV RAILS_ENV staging | |
# Rails app directory | |
ENV APP_HOME /home/app/rubyapp | |
# Clone the app directory | |
RUN git clone [email protected]:xxxx/rubyapp.git $APP_HOME \ | |
&& cd $APP_HOME \ | |
&& git checkout tags/$(git tag -l | tail -1) \ | |
&& chown -R app:app $APP_HOME \ | |
&& rm -f $APP_HOME/config/database.yml | |
EXPOSE 80 | |
# Copy .env and other secret files | |
COPY ./config/.env.staging $APP_HOME/.env \ | |
&& ./config/secret-file $APP_HOME/config/ | |
### Run migrations and compile assets | |
RUN bundle check \ | |
|| bundle install --without development test deploy --path /home/app/.gem \ | |
&& bundle exec rake assets:precompile \ | |
&& bundle exec rake db:migrate \ | |
&& /usr/sbin/nginx -c $APP_HOME/config/nginx.conf |
This file contains hidden or 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
worker_processes 1; | |
pid /run/nginx.pid; | |
daemon on; | |
events { | |
worker_connections 768; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 2048; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
gzip on; | |
gzip_disable "msie6"; | |
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; | |
passenger_ruby /usr/bin/ruby; | |
server { | |
listen 80; | |
server_name localhost; | |
root /home/app/rubyapp/public; | |
passenger_enabled on; | |
passenger_app_env staging; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment