-
-
Save noma4i/aabdccd003a9099b1f631a5ee3383d4d to your computer and use it in GitHub Desktop.
Deploy com Mina, Docker e Docker Compose
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
require 'mina/bundler' | |
require 'mina/rails' | |
require 'mina/git' | |
require 'mina/rbenv' # for rbenv support. (http://rbenv.org) | |
# require 'mina/rvm' # for rvm support. (http://rvm.io) | |
set :domain, 'mydomain.com' | |
set :deploy_to, '/var/www/mysite' | |
set :repository, '[email protected]:mysite/mysite.git' | |
set :branch, 'master' | |
set :user, 'user' | |
set :forward_agent, true | |
set :term_mode, nil | |
# For system-wide RVM install. | |
# set :rvm_path, '/usr/local/rvm/bin/rvm' | |
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server. | |
# They will be linked in the 'deploy:link_shared_paths' step. | |
# Optional settings: | |
# This task is the environment that is loaded for most commands, such as | |
# `mina deploy` or `mina rake`. | |
task :environment do | |
# If you're using rbenv, use this to load the rbenv environment. | |
# Be sure to commit your .ruby-version or .rbenv-version to your repository. | |
# invoke :'rbenv:load' | |
# For those using RVM, use this to load an RVM version@gemset. | |
# invoke :'rvm:use[ruby-1.9.3-p125@default]' | |
end | |
# Put any custom mkdir's in here for when `mina setup` is ran. | |
# For Rails apps, we'll make some of the shared paths that are shared between | |
# all releases. | |
task :setup => :environment do | |
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"] | |
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"] | |
queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"] | |
queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"] | |
queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."] | |
# Docker dotenv files | |
queue! %[mkdir -p "#{deploy_to}/#{shared_path}/vendor"] | |
queue! %[touch "#{deploy_to}/#{shared_path}/vendor/env.web"] | |
queue! %[touch "#{deploy_to}/#{shared_path}/vendor/env.db"] | |
end | |
desc "Deploys the current version to the server." | |
task :deploy => :environment do | |
set :volumes, %Q{VOLUMES_FROM="#{deploy_to}/#{shared_path}/config:/config" } | |
to :before_hook do | |
end | |
deploy do | |
invoke :'git:clone' | |
to :launch do | |
queue %[echo "-----> Building docker container."] | |
queue! %[docker-compose build] | |
queue %[echo "-----> Stopping docker container."] | |
queue! %[docker stop $(docker ps -qa)] | |
queue! %[docker rm $(docker ps -qa)] | |
queue! %[#{volumes} docker-compose stop] | |
queue %[echo "-----> Migrate data."] | |
queue! %[#{volumes} docker-compose run --rm web rake db:create db:migrate db:seed] | |
queue %[echo "-----> Starting containers."] | |
queue! %[#{volumes} docker-compose up -d] | |
end | |
end | |
end | |
namespace :docker do | |
desc "Start docker container" | |
task start: :environment do | |
queue "cd #{deploy_to}/#{current_path}" | |
queue %[echo "-----------------> #{volumes}"] | |
end | |
task migrate: :environment do | |
queue "cd #{deploy_to}/#{current_path}" | |
queue "#{volumes} docker-compose run --rm web rake db:migrate db:seed" | |
end | |
task precompile: :environment do | |
queue "cd #{deploy_to}/#{current_path}" | |
queue "#{volumes} docker-compose run --rm web rake assets:precompile" | |
end | |
desc "Stop docker container" | |
task stop: :environment do | |
queue "cd #{deploy_to}/#{current_path}" | |
queue "#{volumes} docker-compose stop web" | |
end | |
desc "Restart docker container web" | |
task restart: :environment do | |
queue "#{volumes} docker-compose restart web" | |
end | |
desc "Remove all stop container" | |
task clean_containers: :environment do | |
queue "#{volumes} docker rm $(sudo docker ps -a -q)" | |
end | |
task status: :environment do | |
queue "cd #{deploy_to}/#{current_path}" | |
queue "docker-compose ps" | |
end | |
end | |
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
db: | |
image: mysql | |
container_name: database_app | |
expose: | |
- "3306" | |
ports: | |
- "3306:3306" | |
environment: | |
MYSQL_ROOT_PASSWORD: password | |
# env_file: | |
# - 'vendor/env.db' | |
web: | |
build: . | |
container_name: web_app | |
command: rails s -b 0.0.0.0 | |
volumes: | |
- '$VOLUMES_FROM' | |
ports: | |
- 3000:3000 | |
links: | |
- db:db | |
- es:es | |
- redis:redis | |
environment: | |
ELASTICSEARCH_URL: http://es:9200/ | |
REDIS_URL: redis://redis:6379/ | |
SECRET_KEY_BASE: c32ec72d93f7d036ff7671e19b486f963ac843d633e875c71ee86b6280287392f45e33887850c4aab8ed29755fc4ba788be7f2cffb97d2f68225df027797f344 | |
APP_DATABASE_PASSWORD: root | |
# env_file: | |
# - 'vendor/env.web' | |
nginx: | |
build: ./lib/nginx | |
container_name: nginx_app | |
restart: always | |
volumes: | |
- /www/public | |
volumes_from: | |
- web | |
ports: | |
- 80:80 | |
links: | |
- web:web | |
es: | |
build: ./lib/elasticsearch | |
container_name: es | |
ports: | |
- 9200:9200 | |
- 9300:9300 | |
redis: | |
image: redis | |
container_name: redis | |
ports: | |
- 6379:6379 |
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 rails:4.2.3 | |
MAINTAINER Renato Filho <[email protected]> | |
ENV HOME /home/app | |
ENV RAILS_ENV development | |
RUN useradd -m -s /bin/bash app | |
RUN gem install -N bundler | |
ADD . /home/app/ | |
WORKDIR /home/app | |
RUN bundle install --jobs=50 | |
RUN ln -sf /config/database.yml $HOME/config/database.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment