rat_deployer 0.1.1 → 0.1.2
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 +4 -4
- data/lib/rat_deployer/cli/images.rb +69 -45
- data/lib/rat_deployer/cli.rb +13 -15
- data/lib/rat_deployer/command.rb +15 -2
- data/lib/rat_deployer/config.rb +9 -7
- data/lib/rat_deployer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06b1d076beea38ee47efb7915fdd163effbe94cb
|
|
4
|
+
data.tar.gz: d51100bfd44437364f06797353b0913f90ed508d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 148b9cc68a5e73b0d5a1d552243bc0be8e69a99a6216451534120b168a69c0f452f09f559e7fc3cd79a8262f205b0790c1f90646be2ba65dacc6d9c7b8b9abdd
|
|
7
|
+
data.tar.gz: 47b5d856552c5a895176d2fc170ec68d5f481f454465ade1ff25d453199376b03dddf53ccf14903a5bc55e4ffad7f87daefda30a391719aa7abac0f19b41cf42
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'thor'
|
|
2
|
+
require 'yaml'
|
|
2
3
|
|
|
3
4
|
require 'rat_deployer/config'
|
|
4
5
|
require 'rat_deployer/command'
|
|
@@ -8,81 +9,104 @@ module RatDeployer
|
|
|
8
9
|
class Images < Thor
|
|
9
10
|
include RatDeployer::Command
|
|
10
11
|
|
|
11
|
-
desc 'update [SERVICES...]', 'Update images
|
|
12
|
-
def update(*
|
|
13
|
-
|
|
14
|
-
put_heading "Updating image
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
desc 'update [SERVICES...]', 'Update images'
|
|
13
|
+
def update(*images)
|
|
14
|
+
get_images(images).each do |image|
|
|
15
|
+
put_heading "Updating image #{image}"
|
|
16
|
+
|
|
17
|
+
do_build(image)
|
|
18
|
+
do_push(image)
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
desc 'build [SERVICES...]', 'Build images
|
|
21
|
-
def build(*
|
|
22
|
-
|
|
22
|
+
desc 'build [SERVICES...]', 'Build images'
|
|
23
|
+
def build(*images)
|
|
24
|
+
get_images(images).each &method(:do_build)
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
desc 'push [SERVICES...]', 'Push images
|
|
26
|
-
def push(*
|
|
27
|
-
|
|
27
|
+
desc 'push [SERVICES...]', 'Push images'
|
|
28
|
+
def push(*images)
|
|
29
|
+
get_images(images).each &method(:do_push)
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
private
|
|
31
33
|
|
|
32
|
-
def
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
ensure_image_source(service)
|
|
34
|
+
def get_images(images)
|
|
35
|
+
images.any? ? images : all_images
|
|
36
|
+
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
def all_images
|
|
39
|
+
docker_conf = YAML.load(`RAT_PROMPT=false rat compose config`)
|
|
40
|
+
images = docker_conf.fetch("services").map { |_, c| c.fetch("image") }.uniq
|
|
38
41
|
end
|
|
39
42
|
|
|
40
|
-
def
|
|
41
|
-
put_heading "
|
|
43
|
+
def do_build(image)
|
|
44
|
+
put_heading "Building image #{image}"
|
|
45
|
+
return unless image_conf_is_present?(image)
|
|
46
|
+
ensure_image_source(image)
|
|
47
|
+
run "docker build #{source_path(image)} -t #{image}"
|
|
48
|
+
end
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
def do_push(image)
|
|
51
|
+
put_heading "Pusinhg image #{image}"
|
|
52
|
+
return unless image_conf_is_present?(image)
|
|
53
|
+
run "docker push #{image}"
|
|
44
54
|
end
|
|
45
55
|
|
|
46
|
-
def ensure_image_source(
|
|
47
|
-
if git_conf(
|
|
48
|
-
git_clone_repo(
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
def ensure_image_source(image)
|
|
57
|
+
if git_conf(image)
|
|
58
|
+
git_clone_repo(image) unless source_present?(image)
|
|
59
|
+
git_fetch(image)
|
|
60
|
+
git_checkout(image)
|
|
51
61
|
else
|
|
52
|
-
unless
|
|
53
|
-
put_error
|
|
54
|
-
No source found for service #{service}."
|
|
55
|
-
Either specify git[url] or provision the source for #{service} yourself.
|
|
56
|
-
ERROR
|
|
62
|
+
unless source_present?(image)
|
|
63
|
+
put_error "Source for image #{image} is not present and no git config was provided for it. Either provide git url and optionally branch or provision the source yourself at #{source_path(image)}"
|
|
57
64
|
end
|
|
58
65
|
end
|
|
59
66
|
end
|
|
60
67
|
|
|
61
|
-
def git_clone_repo(
|
|
62
|
-
url =
|
|
63
|
-
run "git clone #{url}
|
|
68
|
+
def git_clone_repo(image)
|
|
69
|
+
url = image_conf(image).fetch('git').fetch('url')
|
|
70
|
+
run "git clone #{url} #{source_path(image)}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def git_checkout(image)
|
|
74
|
+
run "git -C #{source_path(image)} checkout -f #{git_branch(image)}"
|
|
75
|
+
run "git -C #{source_path(image)} reset --hard origin/#{git_branch(image)}"
|
|
64
76
|
end
|
|
65
77
|
|
|
66
|
-
def
|
|
67
|
-
|
|
68
|
-
run "git -C #{source_path(service)} checkout -f #{branch}"
|
|
78
|
+
def git_fetch(image)
|
|
79
|
+
run "git -C #{source_path(image)} fetch origin #{git_branch(image)}"
|
|
69
80
|
end
|
|
70
81
|
|
|
71
|
-
def
|
|
72
|
-
|
|
73
|
-
run "git -C #{source_path(service)} pull origin #{branch}"
|
|
82
|
+
def git_branch(image)
|
|
83
|
+
git_conf(image).fetch('branch', 'master')
|
|
74
84
|
end
|
|
75
85
|
|
|
76
|
-
def
|
|
77
|
-
|
|
86
|
+
def git_conf(image)
|
|
87
|
+
image_conf(image)['git']
|
|
78
88
|
end
|
|
79
89
|
|
|
80
|
-
def
|
|
81
|
-
RatDeployer::Config.
|
|
90
|
+
def image_conf(image)
|
|
91
|
+
RatDeployer::Config.images[image]
|
|
82
92
|
end
|
|
83
93
|
|
|
84
|
-
def
|
|
85
|
-
|
|
94
|
+
def source_path(image)
|
|
95
|
+
folder = image_conf(image).fetch('source', image)
|
|
96
|
+
File.expand_path("./sources/#{folder}")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def source_present?(image)
|
|
100
|
+
File.exists? source_path(image)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def image_conf_is_present?(image)
|
|
104
|
+
if image_conf(image)
|
|
105
|
+
true
|
|
106
|
+
else
|
|
107
|
+
put_warning "No image config found for image #{image}. Skipping"
|
|
108
|
+
false
|
|
109
|
+
end
|
|
86
110
|
end
|
|
87
111
|
end
|
|
88
112
|
end
|
data/lib/rat_deployer/cli.rb
CHANGED
|
@@ -12,18 +12,13 @@ module RatDeployer
|
|
|
12
12
|
|
|
13
13
|
desc "deploy", "deploys current environment"
|
|
14
14
|
def deploy
|
|
15
|
-
|
|
15
|
+
unset_machine
|
|
16
|
+
run "rat images update"
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
unset_machine
|
|
19
|
-
run "rat images update #{images.keys.join(' ')}"
|
|
20
|
-
set_machine
|
|
18
|
+
within_machine do
|
|
21
19
|
run "rat compose pull"
|
|
20
|
+
run "rat compose up -d"
|
|
22
21
|
end
|
|
23
|
-
|
|
24
|
-
set_machine
|
|
25
|
-
run "rat compose up -d"
|
|
26
|
-
unset_machine
|
|
27
22
|
end
|
|
28
23
|
|
|
29
24
|
desc "compose ARGS...", "runs docker-compose command with default flags"
|
|
@@ -42,23 +37,26 @@ module RatDeployer
|
|
|
42
37
|
run "docker-compose #{flags} #{cmd} #{cmd_flags.join(" ")}"
|
|
43
38
|
end
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
private
|
|
41
|
+
|
|
46
42
|
def set_machine
|
|
47
43
|
machine = RatDeployer::Config.for_env.fetch("machine")
|
|
48
44
|
run "eval $(docker-machine env #{machine})"
|
|
49
45
|
end
|
|
50
46
|
|
|
51
|
-
desc "unset_machine", "unsets machine"
|
|
52
47
|
def unset_machine
|
|
53
48
|
run "eval $(docker-machine env --unset)"
|
|
54
49
|
end
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
def within_machine(&block)
|
|
52
|
+
run "rat set_machine"
|
|
53
|
+
yield
|
|
54
|
+
ensure
|
|
55
|
+
run "rat unset_machine"
|
|
56
|
+
end
|
|
57
57
|
|
|
58
58
|
def warn_if_running_on_remote_host
|
|
59
|
-
machine = ENV["DOCKER_MACHINE"]
|
|
60
|
-
|
|
61
|
-
if machine
|
|
59
|
+
if machine = ENV["DOCKER_MACHINE"]
|
|
62
60
|
put_warning "Your docker client is pointing to the remote machine #{machine}"
|
|
63
61
|
ask_for_confirmation
|
|
64
62
|
end
|
data/lib/rat_deployer/command.rb
CHANGED
|
@@ -4,24 +4,31 @@ require 'highline/import'
|
|
|
4
4
|
module RatDeployer
|
|
5
5
|
module Command
|
|
6
6
|
def run(cmd)
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
if prompt_enabled?
|
|
8
|
+
msg = "||=> Running command ".colorize(:blue) + "`#{cmd.colorize(:white)}`"
|
|
9
|
+
puts msg
|
|
10
|
+
end
|
|
11
|
+
|
|
9
12
|
system cmd
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def put_heading(str)
|
|
16
|
+
return unless prompt_enabled?
|
|
13
17
|
puts "|| #{str}".colorize(:blue)
|
|
14
18
|
end
|
|
15
19
|
|
|
16
20
|
def put_error(str)
|
|
21
|
+
return unless prompt_enabled?
|
|
17
22
|
puts "// #{str}".colorize(:red)
|
|
18
23
|
end
|
|
19
24
|
|
|
20
25
|
def put_warning(str)
|
|
26
|
+
return unless prompt_enabled?
|
|
21
27
|
puts colorize_warning(str)
|
|
22
28
|
end
|
|
23
29
|
|
|
24
30
|
def ask_for_confirmation
|
|
31
|
+
return unless prompt_enabled?
|
|
25
32
|
prompt = "Are you sure you want to continue?"
|
|
26
33
|
|
|
27
34
|
a = ''
|
|
@@ -39,5 +46,11 @@ module RatDeployer
|
|
|
39
46
|
def colorize_warning(str)
|
|
40
47
|
"\\\\ #{str}".colorize(:yellow)
|
|
41
48
|
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def prompt_enabled?
|
|
53
|
+
ENV['RAT_PROMPT'] != "false"
|
|
54
|
+
end
|
|
42
55
|
end
|
|
43
56
|
end
|
data/lib/rat_deployer/config.rb
CHANGED
|
@@ -11,16 +11,18 @@ module RatDeployer
|
|
|
11
11
|
ENV.fetch('RAT_ENV')
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def self.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
env_conf = confs.fetch(e)
|
|
14
|
+
def self.images
|
|
15
|
+
all.fetch('images', {})
|
|
16
|
+
end
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
def self.environmental
|
|
19
|
+
all.fetch('environments', {})
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def self.
|
|
23
|
-
|
|
22
|
+
def self.for_env(e = env)
|
|
23
|
+
default_conf = environmental.fetch('default', {})
|
|
24
|
+
env_conf = environmental.fetch(e)
|
|
25
|
+
default_conf.deep_merge(env_conf)
|
|
24
26
|
end
|
|
25
27
|
end
|
|
26
28
|
end
|
data/lib/rat_deployer/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rat_deployer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nicolas Oga
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-10-
|
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|