rdeis 0.0.14 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cf228ee970c63ef81770f956e515ecbc7ef974f
4
- data.tar.gz: 0595ac9f67d7c0440af14ac8d0697acb70ffa86e
3
+ metadata.gz: ecd8d6226e57d39b4cc0b1b73656edeb4b7bb83b
4
+ data.tar.gz: 7e51c9cbde84a3fb06eea99ec20b847209f33818
5
5
  SHA512:
6
- metadata.gz: d2feacfb5603b98075b4583b7b048ee48f8603ec84092b73b64989c1c7372de58bf5e1895a50b0b1103a997fb6f5ef37bfaf588b699ac9ea270b1e998d57b044
7
- data.tar.gz: 164176c089980e17aa49dc55d896e8e7622bc71a386f3dff197520ff57fecdd008cdb3f8465dd0f3b4593d8837838258e42679ce214a85152d67f080d2646535
6
+ metadata.gz: 59fe10a00aa1455b4e20b5cdef497db7f9e0fdd1572f051be8780ef6908be70365271c4ba601b43dbc6f8f854c656d684027671e3525be9a509f87cbe413b427
7
+ data.tar.gz: ee6cfed6365a5e0fd16d297f27aafeddf0ae2f060309a1b61fb4bba1d62ba3153bf332c9bb585d1c81a4d665836b685635ca0c314f29ec744340306aa52a75bb
data/README.md CHANGED
@@ -19,11 +19,14 @@ Mirrors the `deis` binary as closely as possible, so the base commands are:
19
19
  - `rdeis config set`
20
20
  - `rdeis config unset`
21
21
  - `rdeis config list`
22
+ - `rdeis config import $file`
23
+ - `rdeis config export $file`
22
24
  - `rdeis domains`
23
25
  - `rdeis domains add`
24
26
  - `rdeis domains remove`
25
27
  - `rdeis domains list`
26
28
  - `rdeis deploy`
29
+ - `rdeis destroy`
27
30
  - `rdeis help`
28
31
  - `rdeis scale`
29
32
 
data/lib/rdeis/base.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module DEIS
2
2
  class Base
3
3
  include Thor::Shell
4
- attr_accessor :verbose, :environment, :proxy, :cluster, :path, :output
4
+ attr_accessor :verbose, :environment, :proxy, :cluster, :path, :output, :ssh
5
5
  YES = "\u2713"
6
6
  NO = "\u274C"
7
7
 
8
+
8
9
  def log(cmd)
9
10
  say "[#{@proxy} #{Time.now}] #{cmd}", :black if @verbose
10
11
  end
data/lib/rdeis/config.rb CHANGED
@@ -12,7 +12,7 @@ module DEIS
12
12
  end
13
13
 
14
14
  # output data using thors print_table & say
15
- def list(vars)
15
+ def list(vars=nil, show=true)
16
16
  data = DEIS::Storage.get(@repo, @environment, @set_selector)
17
17
  # if vars have been set then we filter the config data to matching keys
18
18
  if ! vars.nil? && vars.length > 0
@@ -21,9 +21,11 @@ module DEIS
21
21
  data = data.select!{ |k,v| keys.include? (k) }
22
22
  end
23
23
 
24
- self.results("#{@set_selector} for #{@repo} -> #{@environment}", "No data found" ,data, :green)
24
+ self.results("#{@set_selector} for #{@repo} -> #{@environment}", "No data found" ,data, :green) if ! show.nil?
25
25
  to_remove = DEIS::Storage.get(@repo, @environment, @remove_selector)
26
- self.results("\n\n#{@set_selector} to be removed", nil, to_remove, :blue)
26
+ self.results("\n\n#{@set_selector} to be removed", nil, to_remove, :blue) if ! show.nil?
27
+ # return the data set
28
+ return data
27
29
  end
28
30
 
29
31
  # set config vars for the repo
data/lib/rdeis/deis.rb CHANGED
@@ -174,5 +174,11 @@ module DEIS
174
174
  say "rdeis #{DEIS::VERSION}"
175
175
  end
176
176
 
177
+ desc "destroy", "Destroy the application"
178
+ def destroy
179
+ run = DEIS::Destroy.new(options)
180
+ run.all
181
+ end
182
+
177
183
  end
178
184
  end
data/lib/rdeis/deploy.rb CHANGED
@@ -40,29 +40,34 @@ module DEIS
40
40
  end
41
41
 
42
42
  # deis config:set / unset wrapper
43
- def config
44
- self.setter("config")
43
+ def config(mode="rm,add")
44
+ self.setter("config", "unset", "set", mode)
45
45
  end
46
46
 
47
47
  # deis domains:add / remote wrapper
48
- def domains
49
- self.setter("domains", "remove", "add")
48
+ def domains(mode="rm,add")
49
+ self.setter("domains", "remove", "add", mode)
50
50
  end
51
51
 
52
52
  # generalised setter for config &
53
- def setter(name="config", rm="unset", add="set")
53
+ def setter(name="config", rm="unset", add="set", mode="rm,add")
54
54
  output = {"#{name.upcase}" => ""}
55
+ if ! mode.index("rm").nil?
56
+ removed = DEIS::Storage.get(@repo, @environment, "removed_#{name}")
57
+ remove =DEIS::Parse.JSON_to_unset(removed) if removed.length > 0
58
+ remove_res = run("cd #{@deploy_to} && deis #{name}:#{rm} #{remove} | grep 'not found\\\|400' | wc -l").to_i if !remove.nil? && remove.length > 0
59
+ # remove the removal flagged data, as its now deleted
60
+ DEIS::Storage.removal_complete(@repo, @environment, "removed_#{name}") if remove_res == 0
61
+ output[" unset"] = if remove_res == 0 then DEIS::Deploy::YES else DEIS::Deploy::NO end
62
+ end
55
63
 
56
- removed = DEIS::Storage.get(@repo, @environment, "removed_#{name}")
57
- remove =DEIS::Parse.JSON_to_unset(removed) if removed.length > 0
58
- remove_res = run("cd #{@deploy_to} && deis #{name}:#{rm} #{remove} | grep 'not found\\\|400' | wc -l").to_i if !remove.nil? && remove.length > 0
59
- output[" unset"] = if remove_res == 0 then DEIS::Deploy::YES else DEIS::Deploy::NO end
60
-
61
- to_add = DEIS::Storage.get(@repo, @environment, name)
62
- set = DEIS::Parse.JSON_to_set(to_add) if to_add.length > 0
63
- set_res = run("cd #{@deploy_to} && deis #{name}:#{add} #{set} | grep 'not found\\\|400' | wc -l").to_i if !set.nil? && set.length > 0
64
+ if ! mode.index("add").nil?
65
+ to_add = DEIS::Storage.get(@repo, @environment, name)
66
+ set = DEIS::Parse.JSON_to_set(to_add) if to_add.length > 0
67
+ set_res = run("cd #{@deploy_to} && deis #{name}:#{add} #{set} | grep 'not found\\\|400' | wc -l").to_i if !set.nil? && set.length > 0
64
68
 
65
- output[" set"] = if set_res == 0 then DEIS::Deploy::YES else DEIS::Deploy::NO end
69
+ output[" set"] = if set_res == 0 then DEIS::Deploy::YES else DEIS::Deploy::NO end
70
+ end
66
71
  print_table output
67
72
  # if there were things to set, that ran, but failed, throw
68
73
  if !set.nil? && ! set_res.nil? && set_res > 0
@@ -183,7 +188,7 @@ module DEIS
183
188
  output = {"SCALE" => ""}
184
189
  if ! vars.nil? && vars.length > 0
185
190
  procs = DEIS::Parse.var_array(vars) if ! vars.nil? && vars.length > 0
186
- procs.each{ |r| output[" #{r[:k]}=#{r[:v]}"] = if run("cd #{@deploy_to} 2>&1 /dev/null && deis scale #{r[:k]}=#{r[:v]} 2>&1 | grep 'done in\\\|#{r[:k]}.*up ' | wc -l").to_i == 2 then DEIS::Deploy::YES else DEIS::Deploy::NO end } if ! procs.nil? && procs.length > 0
191
+ procs.each{ |r| output[" #{r[:k]}=#{r[:v]}"] = if run("cd #{@deploy_to} 2>&1 /dev/null && deis scale #{r[:k]}=#{r[:v]} 2>&1 | grep 'done in' | wc -l").to_i > 0 then DEIS::Deploy::YES else DEIS::Deploy::NO end } if ! procs.nil? && procs.length > 0
187
192
  end
188
193
  print_table output
189
194
  end
@@ -0,0 +1,58 @@
1
+ module DEIS
2
+ require 'shellwords'
3
+ class Destroy < Storage
4
+ include Thor::Shell
5
+ attr_accessor :verbose, :environment, :proxy, :cluster, :path, :output, :options
6
+
7
+ def initialize(options)
8
+ @options = options
9
+ @repo = DEIS::Git.name
10
+ @verbose = options["verbose"]
11
+ @environment = options["environment"]
12
+ @cluster = options["cluster"]
13
+ # location data that fetch from env as well as options from thor
14
+ @proxy = if ! options["proxy"].nil? then options["proxy"] elsif ! ENV['RDEIS_PROXY'].nil? then ENV['RDEIS_PROXY'] else nil end
15
+ @base_path = if ! options["path"].nil? then options["path"] elsif ! ENV['RDEIS_PATH'].nil? then ENV['RDEIS_PATH'] else ENV['HOME'] end
16
+ # git data
17
+ @ref = DEIS::Git.ref
18
+ @branch = DEIS::Git.branch
19
+ @remote = DEIS::Git.remote
20
+
21
+ @name = @repo.gsub("_", "-")+"-"+@environment
22
+ @deploy_to = @base_path.to_s + "/"+ @name + "/"
23
+ @ssh = SSH.new({:host => @proxy, :user => nil}) if ! @proxy.nil?
24
+ end
25
+
26
+
27
+ def domains
28
+ dom = DEIS::Domains.new(@options)
29
+ list = DEIS::Parse.list_array_to_var_string_array(dom.list(nil, nil))
30
+ dom.unset(list) if ! list.nil? && list.length > 0
31
+ # now deploy the change
32
+ deploy = DEIS::Deploy.new(@options)
33
+ deploy.domains("rm")
34
+ end
35
+
36
+ def scale
37
+ procs = []
38
+ DEIS::Parse.procs.each{|name| procs.push("#{name}=0") }
39
+ deploy = DEIS::Deploy.new(@options)
40
+ deploy.scale(procs) if ! procs.nil? && procs.length > 0
41
+ end
42
+
43
+ def remove
44
+ base = DEIS::Deploy.new(options)
45
+ base.run("deis destroy -a #{@name} --confirm=#{@name}")
46
+ end
47
+
48
+ # runs everyhing in order
49
+ def all
50
+ self.domains
51
+ self.scale
52
+ self.remove
53
+ say "Complete", :blue
54
+ end
55
+
56
+
57
+ end
58
+ end
data/lib/rdeis/parse.rb CHANGED
@@ -35,6 +35,13 @@ module DEIS
35
35
  end
36
36
  end
37
37
 
38
+ # takes the array of [ [k, v], [k, v] ] and converts back to string K=V
39
+ def self.list_array_to_var_string_array(data)
40
+ out = []
41
+ data.each{|sub| out.push("#{sub.first}"+ if !sub[1].nil? then "=#{sub[1]}" else "" end) }
42
+ out
43
+ end
44
+
38
45
  def self.JSON_to_set(json)
39
46
  cmd = ""
40
47
  json.each{|k,v| cmd += if v.to_s.length > 0 && v.to_s != "null" then "#{k}=\"#{v}\" " else "#{k} " end}
@@ -47,14 +54,20 @@ module DEIS
47
54
  cmd + " 2>&1"
48
55
  end
49
56
 
50
- def self.first_proc
51
- file = Dir.pwd+"/Procfile"
57
+ def self.procs
52
58
  procs = []
59
+ file = Dir.pwd+"/Procfile"
53
60
  if File.exists?(file)
54
61
  File.open(file, "r") {|f| f.read}.split("\n").each do |r|
55
62
  key = r.split(":").first
56
63
  procs.push(key)
57
64
  end
65
+ end
66
+ procs
67
+ end
68
+
69
+ def self.first_proc
70
+ if (procs=DEIS::Parse.procs) && ! procs.nil? && procs.length > 0
58
71
  return "#{procs.first}=1"
59
72
  end
60
73
  nil
data/lib/rdeis/storage.rb CHANGED
@@ -34,6 +34,11 @@ module DEIS
34
34
  end
35
35
  end
36
36
 
37
+ # remove the removed flag for this key by just setting it to an empty hash
38
+ def self.removal_complete(repo, env, key)
39
+ DEIS::Storage.set(repo, env, key, {})
40
+ end
41
+
37
42
  # only handles top level, not sub levels
38
43
  def self.set(repo, env, key, value)
39
44
  current = DEIS::Storage.load(repo, env)
data/lib/rdeis/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module DEIS
2
- VERSION='0.0.14'
3
- LAST_VERSION='0.0.13'
2
+ VERSION='0.1.0'
3
+ LAST_VERSION='0.0.14'
4
4
  end
data/lib/rdeis.rb CHANGED
@@ -12,5 +12,6 @@ module DEIS
12
12
  require "rdeis/config"
13
13
  require "rdeis/domains"
14
14
  require "rdeis/deploy"
15
+ require "rdeis/destroy"
15
16
  require "rdeis/deis"
16
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdeis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-06 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - lib/rdeis/config.rb
72
72
  - lib/rdeis/deis.rb
73
73
  - lib/rdeis/deploy.rb
74
+ - lib/rdeis/destroy.rb
74
75
  - lib/rdeis/domains.rb
75
76
  - lib/rdeis/git.rb
76
77
  - lib/rdeis/parse.rb
@@ -79,7 +80,7 @@ files:
79
80
  - lib/rdeis/version.rb
80
81
  - lib/ssh.rb
81
82
  - rdeis.gemspec
82
- homepage: https://github.com/charlesmarshall/deis_deploy/tree/0.0.14
83
+ homepage: https://github.com/charlesmarshall/deis_deploy/tree/0.1.0
83
84
  licenses:
84
85
  - MIT
85
86
  metadata: {}