capistrano-dockercompose-interactive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b833de26496b0e466f5c83d7f2b0f923e5531e9
4
+ data.tar.gz: 9faaca5cfa517c0abc3483611798ef4b0f8a18aa
5
+ SHA512:
6
+ metadata.gz: 5132dce2dd51224179068dfc56df1c5097e011f5b60d3d7cb3d8e5bc3ba9b798071f2ad69466435028bb5089a4449878376305bd11791e598e83357745c44e2f
7
+ data.tar.gz: 726080d9da09de26eb62071e5dc99d7bdfbd682fdc254d20c14ebbe36151e104afd88a8196e66396a97c5889a65a7740bb1c7afff11794813635cbf2ee329fc8
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-bundler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 creative-workflow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Capistrano::DockerCompose::Interactive [![Gem Version](https://badge.fury.io/rb/capistrano-dockercompose-interactive.svg)](https://badge.fury.io/rb/capistrano-dockercompose-interactive)
2
+
3
+ Helps managing docker compose excution on local or remote with inetractive shell support.
4
+
5
+ This project is in an early stage but helps me alot dealing with my container deployments and keeps my code clean. Feel free to contribute =)
6
+
7
+ This gem depends on [sshkit-interactive](https://github.com/afeld/sshkit-interactive).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's `Gemfile` (make sure you have installed ruby and bundler ;):
12
+
13
+ ```ruby
14
+ gem 'capistrano-dockercompose-interactive'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install capistrano-dockercompose-interactive
24
+
25
+ Dont forget to require the module in your Capfile:
26
+
27
+ ```ruby
28
+ require 'capistrano/dockercompose/interactive'
29
+ ```
30
+
31
+ ### Usage
32
+ #TODO
33
+
34
+ ## Changes
35
+
36
+ ### Version 0.0.1
37
+ * initial release
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'capistrano-dockercompose-interactive'
7
+ spec.version = '0.0.1'
8
+ spec.date = '2018-02-01'
9
+ spec.summary = 'Helps managing docker compose excution on local or remote with inetractive shell support'
10
+ spec.description = spec.summary
11
+ spec.authors = ['Tom Hanoldt']
12
+ spec.email = ['tom@creative-workflow.berlin']
13
+ spec.homepage = 'https://github.com/creative-workflow/capistrano-dockercompose-interactive'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'capistrano', '>= 3.0.0'
22
+ spec.add_dependency 'sshkit-interactive', '>= 0.2.3'
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.1'
25
+ end
@@ -0,0 +1 @@
1
+ require_relative 'capistrano/dockercompose/interactive.rb'
@@ -0,0 +1,96 @@
1
+ require 'yaml'
2
+
3
+ module DockerCompose::Interactive
4
+ def DockerCompose.instance(file='', project='')
5
+ Instance.new(file, project)
6
+ end
7
+
8
+ def DockerCompose.local_stage?
9
+ fetch(:local_stage_name, 'local').to_sym == fetch(:stage).to_sym
10
+ end
11
+
12
+ def DockerCompose.capture_local_or_remote(cmd)
13
+ puts "runnig: docker-compose #{cmd}"
14
+ result = ''
15
+ if local_stage?
16
+ run_locally do
17
+ result = capture "docker-compose #{cmd}"
18
+ end
19
+ else
20
+ on roles :container_host do |_host|
21
+ within current_path do
22
+ result = capture "cd #{current_path} && docker-compose #{cmd}"
23
+ end
24
+ end
25
+ end
26
+ result
27
+ end
28
+
29
+ def DockerCompose.execute_local_or_remote_interactive(cmd)
30
+ puts "runnig: docker-compose #{cmd}"
31
+ if local_stage?
32
+ run_locally do
33
+ execute "docker-compose #{cmd}"
34
+ end
35
+ else
36
+ on roles :container_host do |_host|
37
+ run_interactively _host do
38
+ within current_path do
39
+ execute "cd #{current_path} && docker-compose #{cmd}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ class Instance
47
+ def initialize(file='', project=nil)
48
+ @file = file
49
+ @project = project
50
+ end
51
+
52
+ def config
53
+ return @config if @config
54
+ raw_config = execute('config', true)
55
+ @config = YAML.load(raw_config)
56
+ end
57
+
58
+ def execute_compose_command(cmd, capture = false)
59
+ project = @project.empty? ? "" : "-p #{@project}"
60
+ file = @file.empty? ? "" : "--file #{@file}"
61
+ cmd = "#{file} #{project} #{cmd}"
62
+
63
+ if capture
64
+ return DockerCompose.capture_local_or_remote cmd
65
+ else
66
+ DockerCompose.execute_local_or_remote_interactive cmd
67
+ end
68
+ end
69
+
70
+ def service(name)
71
+ Service.new(self, name, config()['services'][name])
72
+ end
73
+ end
74
+
75
+ class Service
76
+ def initialize(compose, name, config)
77
+ @compose, @name, @config = compose, name, config
78
+ end
79
+
80
+ def id
81
+ result = @compose.execute_compose_command("ps -q #{@name}", true)
82
+ result.split(';').shift.strip
83
+ end
84
+
85
+ def exec(cmd, capture=false)
86
+ cmd = "exec #{@name} #{cmd}"
87
+ @compose.execute_compose_command(cmd, capture)
88
+ end
89
+
90
+ def run(cmd, capture=false, args="--rm")
91
+ cmd = "run #{args} #{@name} #{cmd}"
92
+ @compose.execute_compose_command(cmd, capture)
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,14 @@
1
+
2
+ namespace :dockercompose do
3
+ namespace :interactive do
4
+
5
+ end
6
+ end
7
+
8
+ namespace :load do
9
+ task :defaults do
10
+ set :local_stage_name, :local
11
+ set :docker_compose_interactive_file, ''
12
+ set :docker_compose_interactive_project, ''
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-dockercompose-interactive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom Hanoldt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-01 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.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sshkit-interactive
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ description: Helps managing docker compose excution on local or remote with inetractive
70
+ shell support
71
+ email:
72
+ - tom@creative-workflow.berlin
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - capistrano-dockercompose-interactive.gemspec
83
+ - lib/capistrano-dockercompose-interactive.rb
84
+ - lib/capistrano/dockercompose/interactive.rb
85
+ - lib/capistrano/tasks/docker-compose-interactive.rb
86
+ homepage: https://github.com/creative-workflow/capistrano-dockercompose-interactive
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.12
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Helps managing docker compose excution on local or remote with inetractive
110
+ shell support
111
+ test_files: []