Last active
April 10, 2019 14:47
-
-
Save fuxx/91cdad2afd9f81189f9bdca5155660a5 to your computer and use it in GitHub Desktop.
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
#~/D/r/rcf RCF-45-inventory * lib/tasks cat deploy.rake Wed Apr 10 16:45:22 2019 | |
# use SSHKit directly instead of Capistrano | |
require 'sshkit' | |
include SSHKit::DSL | |
SSHKit.config.command_map[:rake] = "./bin/rake" | |
# set the location on the server of where we want files copied to and commands executed from | |
deploy_path = ENV['DEPLOY_PATH'] | |
# connect to server | |
server = SSHKit::Host.new hostname: ENV['SERVER_HOST'], port: ENV['SERVER_PORT'], user: ENV['SERVER_USER'] | |
namespace :docker do | |
desc 'stops all Docker containers via Docker Compose' | |
task :stop => :environment do | |
on server do | |
within deploy_path do | |
execute 'docker-compose', '-f', 'docker-compose_production.yml', 'stop' | |
end | |
end | |
end | |
desc 'starts all Docker containers via Docker Compose' | |
task :start => :environment do | |
on server do | |
within deploy_path do | |
execute 'docker-compose', '-f', 'docker-compose_production.yml', 'up', '-d' | |
end | |
end | |
end | |
desc 'builds the Docker containers via Docker Compose' | |
task :build => :environment do | |
on server do | |
within deploy_path do | |
execute 'docker-compose', '-f', 'docker-compose_production.yml', 'build' | |
end | |
end | |
end | |
desc 'pulls latest code from bitbucket' | |
task :pull => :environment do | |
on server do | |
within deploy_path do | |
execute 'git', 'pull' | |
end | |
end | |
end | |
desc 'runs database migrations in application container via Docker Compose' | |
task :migrate => :environment do | |
on server do | |
within deploy_path do | |
execute 'docker-compose', '-f', 'docker-compose_production.yml', 'run', 'web', 'bundle', 'exec', 'rake', 'db:migrate' | |
end | |
end | |
end | |
desc 'pulls images, stops old containers, updates the database, and starts new containers' | |
task deploy: %w{docker:pull docker:build docker:stop docker:migrate docker:start} # pull images manually to reduce down time | |
end⏎ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment