capistrano-decompose 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 982e23a46591cd5584c87a1396f53a4ccd176d94
4
+ data.tar.gz: ba306eae0a21a5da1b05bc7e4021be83c1baea8a
5
+ SHA512:
6
+ metadata.gz: 5a3af8ccc36f021f2815b60bdf5dd01108ef44a34f3ebb229bf7b43018efe8a1809f5aeee2552b926dc077f5a1860a8323ff5a865ed05e55e54ec8bff5fa95a1
7
+ data.tar.gz: 6f8704eac3994023b425e50626d26b7d9382617fbdf66e79749ec4e29d090031efcf1f38d5e2625358531df052e67fd46ea32478d52e3d4ad49e5323b8838273
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/.sass-cache
9
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-decompose (0.1)
5
+ capistrano (~> 3.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ airbrussh (1.0.2)
11
+ sshkit (>= 1.6.1, != 1.7.0)
12
+ capistrano (3.5.0)
13
+ airbrussh (>= 1.0.0)
14
+ capistrano-harrow
15
+ i18n
16
+ rake (>= 10.0.0)
17
+ sshkit (>= 1.9.0)
18
+ capistrano-harrow (0.5.1)
19
+ i18n (0.7.0)
20
+ net-scp (1.2.1)
21
+ net-ssh (>= 2.6.5)
22
+ net-ssh (3.1.1)
23
+ rake (11.1.2)
24
+ sshkit (1.10.0)
25
+ net-scp (>= 1.1.2)
26
+ net-ssh (>= 2.8.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ capistrano-decompose!
33
+
34
+ BUNDLED WITH
35
+ 1.11.2
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Emad Elsaid
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # Capistrano::Decompose
2
+
3
+ Add tasks for capistrano to deploy with docker-compose.
4
+
5
+ ## How it works
6
+
7
+ after capistrano pull your repo and link it to the `current` directory, decompose will invoke `docker-compose build` to build your images and then run some rake tasks that you configured in your deployment with the key `decompose_rake_tasks`, you can add your rails tasks like `db:migration`, `assets:precompile`...etc here, then it will invoke `docker-compose up` or restart only the web service you specified in key `decompose_restart`, also you can use `cap <env> decompose:run` to run any command inside a service, so anytime you need to invoke `rails console` inside you docker image on your server you can use `cap production decompose:run rails console`.
8
+
9
+ at the end decompose will delete the older images from remote server to keep the server clean.
10
+
11
+ ## Installation
12
+
13
+ add this line to your Gemfile
14
+
15
+ ``` ruby
16
+ gem 'capistrano-decompose'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ``` bash
22
+ $ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ``` bash
28
+ $ gem install capistrano-decompose
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Add this line to your `Capfile`:
34
+
35
+ ``` ruby
36
+ require 'capistrano/decompose
37
+ ```
38
+
39
+ ## Options for deployment
40
+
41
+ you can specify the following options in you `deploy.rb` script or the environment specific deploy file:
42
+
43
+ ``` ruby
44
+ decompose_restart: an array of services that should be restarted each deployment, if not specified decompose will restart all services
45
+ decompose_web_service: the web service that will be used to execute commands inside like `rake` or any interactive command from `decompose:run`, default value: :web
46
+ decompose_rake_tasks: a set of rake tasks to execute after each deploy, default value is `nil`
47
+ ```
48
+
49
+ for a typical rails application the previous options should be as follows, given that the application container service name is `web`:
50
+
51
+ ```ruby
52
+ set :decompose_restart, [:web]
53
+ set :decompose_web_service, :web
54
+ set :docker_rake_tasks, ['db:migrate', 'assets:precompile']
55
+ ```
56
+
57
+ ## after the first deployment of a rails application
58
+
59
+ you would need to setup your database by invoking the `db:setup` task to create and seed your database, you can do that using 2 ways
60
+
61
+ * `cap production decompose:db_setup`
62
+ * `cap production decompose:run rake db:setup`
63
+
64
+ ## General note
65
+
66
+ * this gem doesn't provide a `dockerfile` or `docker-compose.yml` file, you have to create these files yourself
67
+ * the linked directories and files will not work and you should use docker data volumes anyway
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'capistrano/decompose/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'capistrano-decompose'
6
+ s.version = Capistrano::Decompose::VERSION
7
+ s.authors = ['Emad Elsaid']
8
+ s.email = ['blazeeboy@gmail.com']
9
+ s.homepage = 'https://github.com/blazeeboy/capistrano-decompose'
10
+ s.summary = 'Capistrano plugin to deploy your application inside docker containers using docker compose'
11
+ s.description = 'Capistrano plugin to deploy your application inside docker containers using docker compose'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
15
+ s.require_paths = ['lib']
16
+
17
+ s.add_dependency 'capistrano', '~> 3.5'
18
+ end
File without changes
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/decompose.rake', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Decompose
3
+ VERSION = '0.1'
4
+ end
5
+ end
@@ -0,0 +1,109 @@
1
+ namespace :decompose do
2
+
3
+ desc 'build docker-compose services'
4
+ task :build do
5
+ on roles(:app) do
6
+ within release_path do
7
+ docker_execute :build
8
+ end
9
+ end
10
+ end
11
+
12
+ desc 'shutdown all project services with docker-compose'
13
+ task :down do
14
+ on roles(:app) do
15
+ within release_path do
16
+ docker_execute :down
17
+ end
18
+ end
19
+ end
20
+
21
+ desc 'boot up all docker-compose services'
22
+ task :up do
23
+ on roles(:app) do
24
+ within release_path do
25
+ docker_execute :up, '-d'
26
+ end
27
+ end
28
+ end
29
+
30
+ desc 'restart services of docker-compose and if not services listed restart all services'
31
+ task :restart do
32
+ on roles(:app) do
33
+ within release_path do
34
+ services = Array(fetch(:decompose_restart))
35
+ if services.empty?
36
+ docker_execute :down
37
+ docker_execute :up
38
+ else
39
+ docker_execute :stop, *services
40
+ docker_execute :up, '-d', *services
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ desc 'delete docker images that are not related to current build'
47
+ task :clean do
48
+ on roles(:app) do
49
+ within release_path do
50
+ images_to_delete = capture('docker images -f "dangling=true" -q')
51
+ execute 'docker rmi $(docker images -f "dangling=true" -q)' unless images_to_delete.empty?
52
+ end
53
+ end
54
+ end
55
+
56
+ desc 'execute a set of rake tasts inside the web container'
57
+ task :rake_tasks do
58
+ on roles(:app) do
59
+ within release_path do
60
+ docker_rake(*fetch(:decompose_rake_tasks)) if fetch(:decompose_rake_tasks)
61
+ end
62
+ end
63
+ end
64
+
65
+ desc 'execute rake db:setup inside the web container'
66
+ task :db_setup do
67
+ on roles(:app) do
68
+ within release_path do
69
+ docker_rake('db:setup')
70
+ end
71
+ end
72
+ end
73
+
74
+ desc 'run an interactive command inside the web container'
75
+ task :run do
76
+ on roles(:app) do |host|
77
+ command = ARGV[2..-1].join(' ')
78
+ docker_execute_interactively host, command
79
+ end
80
+ end
81
+
82
+ namespace :load do
83
+ task :defaults do
84
+ set :decompose_restart, fetch(:decompose_restart, nil)
85
+ set :decompose_web_service, fetch(:decompose_web_service, :web)
86
+ set :decompose_rake_tasks, fetch(:decompose_rake_tasks, nil)
87
+ end
88
+ end
89
+
90
+ def docker_rake(*args)
91
+ docker_execute('run', '--rm', fetch(:decompose_web_service), 'rake', *args)
92
+ end
93
+
94
+ def docker_execute(*args)
95
+ execute('docker-compose', "--project-name #{fetch :application}", *args)
96
+ end
97
+
98
+ def docker_execute_interactively(host, command)
99
+ user = host.user
100
+ port = fetch(:port) || 22
101
+ docker_run = "docker-compose --project-name #{fetch :application} run --rm web #{command}"
102
+ exec "ssh -l #{user} #{host} -p #{port} -t 'cd #{deploy_to}/current && #{docker_run}'"
103
+ end
104
+
105
+ after 'deploy:updated', 'decompose:build'
106
+ after 'deploy:published', 'decompose:rake_tasks'
107
+ after 'deploy:published', 'decompose:restart'
108
+ after 'deploy:cleanup', 'decompose:clean'
109
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-decompose
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Emad Elsaid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
27
+ description: Capistrano plugin to deploy your application inside docker containers
28
+ using docker compose
29
+ email:
30
+ - blazeeboy@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - MIT-LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - capistrano-decompose.gemspec
42
+ - lib/capistrano-decompose.rb
43
+ - lib/capistrano/decompose.rb
44
+ - lib/capistrano/decompose/version.rb
45
+ - lib/capistrano/tasks/decompose.rake
46
+ homepage: https://github.com/blazeeboy/capistrano-decompose
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.6.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Capistrano plugin to deploy your application inside docker containers using
70
+ docker compose
71
+ test_files: []
72
+ has_rdoc: