Created
January 7, 2014 01:52
-
-
Save yoshiso/8293464 to your computer and use it in GitHub Desktop.
Unicorn+RailsアプリをDockerコンテナで起動する ref: http://qiita.com/yss44@github/items/5d6834348f53910e63d2
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
# DOCKER-RAILS-UNICORN | |
# | |
# VERSION 1 | |
FROM yoshiso/rails_base | |
MAINTAINER yoshiso | |
ADD supervisor/supervisord.conf /etc/supervisord.conf | |
####################################### Rails ############################################# | |
ENV PATH /usr/local/rbenv/bin:$PATH | |
ENV RAILS_ENV production | |
# Git pull latest Rails App | |
RUN mkdir /var/www; cd /var/www; | |
RUN git clone https://github.com/yss44/unicorn_sample.git /var/www/app; | |
# Resolve dependencies | |
RUN yum -y install sqlite-devel | |
RUN source /etc/profile.d/rbenv.sh;gem install sqlite3 -v '1.3.8' # Have to be installed | |
RUN source /etc/profile.d/rbenv.sh;cd /var/www/app;bundle install -j4; | |
# Setup rails(db:migrate,assets precompile) | |
RUN source /etc/profile.d/rbenv.sh;source /etc/profile.d/nvm.sh;cd /var/www/app;RAILS_ENV=production bundle exec rake deploy:prepare; | |
# Add execution file used by supervisor | |
ADD rails/start.sh rails_start.sh | |
RUN chmod +x rails_start.sh | |
###################################### Docker config ######################################### | |
# Environment valiables | |
ENV WEB_CONCURRENCY 4 | |
ENV RAILS_ENV production | |
# expose for sshd,rails | |
EXPOSE 2222 3000 | |
CMD ["/usr/bin/supervisord"] |
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
#!/bin/bash | |
#Install Ruby by rubyenv | |
if [ ! -d /usr/local/rbenv ];then | |
cd /usr/local | |
git clone git://github.com/sstephenson/rbenv.git rbenv | |
mkdir rbenv/shims rbenv/versions rbenv/plugins | |
git clone git://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build | |
# Setup rbenv for all user | |
echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile.d/rbenv.sh | |
echo 'PATH=/usr/local/rbenv/bin:$PATH' >> /etc/profile.d/rbenv.sh | |
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh | |
source /etc/profile.d/rbenv.sh | |
# Install ruby | |
rbenv install 2.0.0-p353 | |
rbenv rehash | |
rbenv global 2.0.0-p353 # default ruby version | |
#rbenv(add user to rbenv group if you want to use rbenv) | |
useradd rbenv | |
chown -R rbenv:rbenv rbenv | |
chmod -R 775 rbenv | |
# install withou ri,rdoc | |
echo 'install: --no-ri --no-rdoc' >> /etc/.gemrc | |
echo 'update: --no-ri --no-rdoc' >> /etc/.gemrc | |
echo 'install: --no-ri --no-rdoc' >> /.gemrc | |
echo 'update: --no-ri --no-rdoc' >> /.gemrc | |
# install bundler | |
gem install bundler | |
fi | |
#Install Node.js for Rails javascript runtime | |
if [ ! -d /usr/local/nvm ];then | |
# install nvm | |
git clone https://github.com/creationix/nvm.git /usr/local/nvm | |
source /usr/local/nvm/nvm.sh | |
# nvm(add user to nvm group if you want to use nvm) | |
useradd nvm | |
chown -R nvm:nvm /usr/local/nvm | |
chmod -R 755 /usr/local/nvm | |
nvm install 0.10.24 | |
# Setup rbenv for all user | |
echo 'source /usr/local/nvm/nvm.sh' >> /etc/profile.d/nvm.sh | |
echo 'nvm use v0.10.24' >> /etc/profile.d/nvm.sh | |
fi |
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
#!/bin/bash | |
source /etc/profile.d/nvm.sh; | |
cd /var/www/app; | |
/usr/local/rbenv/shims/bundle exec unicorn_rails -c /var/www/app/config/unicorn.rb -E production |
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
[supervisord] | |
nodaemon=true | |
[program:sshd] | |
command=/usr/sbin/sshd -D | |
[program:rails_app] | |
command=/rails_start.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment