Forked from johnbintz/simple-capistrano-docker-deploy.rb
Created
November 29, 2015 18:20
-
-
Save athaller/34be22c2486122566bf6 to your computer and use it in GitHub Desktop.
Simple Capistrano deploy for a Docker-managed app
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
# be sure to comment out the require 'capistrano/deploy' line in your Capfile! | |
# config valid only for Capistrano 3.1 | |
lock '3.2.1' | |
set :application, 'my-cool-application' | |
# the base docker repo reference | |
set :name, "johns-stuff/#{fetch(:application)}" | |
# i have a docker registry running on a remote machine. | |
set :remote_repo, "registry.from.dev.machine:5000/#{fetch(:name)}" | |
set :local_repo, "registry.from.install.machine:5000/#{fetch(:name)}" | |
desc 'Build Docker images' | |
task :build do | |
# do you app pre-deploy stuff here. i use gulp, so... | |
system "gulp build" | |
# build the actual docker image, tagging the push for the remote repo | |
system "docker build -t #{fetch(:remote_repo)} ." | |
end | |
desc 'Push Docker images' | |
task :push do | |
system "docker push #{fetch(:remote_repo)}" | |
end | |
desc 'go' | |
task :go => ['build', 'push', 'deploy'] | |
desc 'deploy' | |
task :deploy do | |
on roles(:app) do | |
execute "docker pull #{fetch(:local_repo)}" | |
Rake::Task['deploy:restart'].invoke | |
end | |
end | |
namespace :deploy do | |
task :restart do | |
on roles(:app) do | |
# in case the app isn't running on the other end | |
execute "docker stop #{fetch(:application)} ; true" | |
# have to remove it otherwise --restart=always will run it again on reboot! | |
execute "docker rm #{fetch(:application)} ; true" | |
# modify this to suit how you want to run your app | |
execute "docker run -d -p 3000:3000 --restart=always --name=#{fetch(:application)} #{fetch(:local_repo)}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment