rat_deployer 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19683d62cba337d7a36e0d19ba5500c8a78eebb5
4
- data.tar.gz: c1a9186d1108d5377d02e882dca1482725e319d8
3
+ metadata.gz: 62f3865952fcdfe384e29675e293cf14c366cd0c
4
+ data.tar.gz: ef8f40dfa437099645704bdeaceb3b35c2ab278e
5
5
  SHA512:
6
- metadata.gz: 034cdad0bb5d9c1c4585cf62f8523d237dc780d6d6313d4dafa09bbc9ef5b6780c034bd937149abeb82bb03df74eca687b9453c911b4b458d5b2748f6cd6d750
7
- data.tar.gz: a3d8eba9c96ffe4a63814bef407576fe60e1a56c81edbd8b4bbdcf3d0c294e38e26d7e8be68b1892d5a0063abda4ca2f13d70f8421cbaa5f4c18699e776d9d5e
6
+ metadata.gz: c91cfb7161d0c22b9e07f7c70e00e486e5ae068f31118d659184962c2a1196ca052930391b5014c586e1a9ddab36af827f2e92624683b2c7bba91e3e1e4907fa
7
+ data.tar.gz: 919ff30c8c9a36e5580a6db8fb76f2dd40fba2071744673031f46847b6f555e6d4a18607c09787a01d5b230d0f19c4128becd8469ab75bb183504606c6dea1be
@@ -1,6 +1,5 @@
1
1
  require 'thor'
2
2
 
3
- require 'rat_deployer/cli/images'
4
3
  require 'rat_deployer/command'
5
4
  require 'rat_deployer/notifier'
6
5
 
@@ -8,18 +7,20 @@ module RatDeployer
8
7
  class Cli < Thor
9
8
  include RatDeployer::Command
10
9
 
11
- desc 'images SUBCOMMAND ...ARGS', 'manage images'
12
- subcommand 'images', RatDeployer::Cli::Images
13
-
14
10
  desc "deploy", "deploys current environment"
15
11
  def deploy
16
- RatDeployer::Notifier.notify "Starting deploy on #{ENV.fetch('RAT_ENV')}"
12
+ RatDeployer::Notifier.notify_deploy_start
17
13
 
18
- RatDeployer::Cli::Images.new.update
19
14
  RatDeployer::Cli.new.compose('pull')
20
15
  RatDeployer::Cli.new.compose('up -d')
21
16
 
22
- RatDeployer::Notifier.notify "Ended deploy on #{ENV.fetch('RAT_ENV')}"
17
+ RatDeployer::Notifier.notify_deploy_end
18
+ rescue Exception => e
19
+ RatDeployer::Notifier.notify <<-STR
20
+ Failed deploy on #{ENV.fetch('RAT_ENV')}"
21
+ Reason:
22
+ #{e.message}
23
+ STR
23
24
  end
24
25
 
25
26
  desc "compose ARGS...", "runs docker-compose command with default flags"
@@ -1,5 +1,6 @@
1
1
  require "colorize"
2
2
  require 'highline/import'
3
+ require 'rat_deployer/config'
3
4
 
4
5
  module RatDeployer
5
6
  module Command
@@ -4,7 +4,7 @@ require 'deep_merge'
4
4
  module RatDeployer
5
5
  module Config
6
6
  def self.all
7
- @all ||= YAML.load_file File.expand_path('./rat_config.yml')
7
+ @all ||= YAML.load_file(File.expand_path('./rat_config.yml')) || {}
8
8
  end
9
9
 
10
10
  def self.env
@@ -1,16 +1,40 @@
1
+ require 'rat_deployer/config'
2
+ require 'active_support/core_ext/string'
1
3
  require 'slack-notifier'
2
4
 
3
5
  module RatDeployer
4
6
  module Notifier
7
+ def self.notify_deploy_start
8
+ notify_deploy "Starting deploy on #{ENV.fetch('RAT_ENV')}"
9
+ end
10
+
11
+ def self.notify_deploy_end
12
+ notify_deploy "Ended deploy on #{ENV.fetch('RAT_ENV')}"
13
+ end
14
+
15
+ def self.notify_deploy(title)
16
+ props = get_deploy_properties
17
+
18
+ slack_notifier.post(
19
+ attachments: [{
20
+ title: title,
21
+ fields: get_deploy_properties.map do |k,v|
22
+ {title: k.to_s.titleize, value: v, short: true}
23
+ end
24
+ }]
25
+ )
26
+ end
27
+
5
28
  def self.notify(msg)
29
+ return unless webhook_url
6
30
  self.slack_notifier.ping msg
7
31
  end
8
32
 
33
+ private
34
+
9
35
  def self.slack_notifier
10
36
  @slack_notifier ||=
11
37
  begin
12
- webhook_url = RatDeployer::Config.all.fetch("slack_webhook_url")
13
-
14
38
  Slack::Notifier.new(
15
39
  webhook_url,
16
40
  channel: '#general',
@@ -18,5 +42,20 @@ module RatDeployer
18
42
  )
19
43
  end
20
44
  end
45
+
46
+ def self.webhook_url
47
+ @webhook_url ||= RatDeployer::Config.all["slack_webhook_url"]
48
+ end
49
+
50
+ def self.get_deploy_properties
51
+ require 'socket'
52
+
53
+ {
54
+ env: ENV.fetch('RAT_ENV'),
55
+ user: ENV.fetch('USER'),
56
+ hostname: Socket.gethostname,
57
+ started_at: Time.now.to_s
58
+ }
59
+ end
21
60
  end
22
61
  end
@@ -1,3 +1,3 @@
1
1
  module RatDeployer
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
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.10
4
+ version: 0.1.11
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-12-27 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -68,6 +68,20 @@ dependencies:
68
68
  version: 1.7.8
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: slack-notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -119,7 +133,6 @@ files:
119
133
  - bin/rat
120
134
  - lib/rat_deployer.rb
121
135
  - lib/rat_deployer/cli.rb
122
- - lib/rat_deployer/cli/images.rb
123
136
  - lib/rat_deployer/command.rb
124
137
  - lib/rat_deployer/config.rb
125
138
  - lib/rat_deployer/notifier.rb
@@ -150,4 +163,3 @@ signing_key:
150
163
  specification_version: 4
151
164
  summary: A micro-framework to deploy dockerized apps
152
165
  test_files: []
153
- has_rdoc:
@@ -1,112 +0,0 @@
1
- require 'thor'
2
- require 'yaml'
3
-
4
- require 'rat_deployer/config'
5
- require 'rat_deployer/command'
6
-
7
- module RatDeployer
8
- class Cli < Thor
9
- class Images < Thor
10
- include RatDeployer::Command
11
-
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) if RatDeployer::Config.remote
19
- end
20
- end
21
-
22
- desc 'build [SERVICES...]', 'Build images'
23
- def build(*images)
24
- get_images(images).each &method(:do_build)
25
- end
26
-
27
- desc 'push [SERVICES...]', 'Push images'
28
- def push(*images)
29
- get_images(images).each &method(:do_push)
30
- end
31
-
32
- private
33
-
34
- def get_images(images)
35
- images.any? ? images : all_images
36
- end
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
41
- end
42
-
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
49
-
50
- def do_push(image)
51
- put_heading "Pusinhg image #{image}"
52
- return unless image_conf_is_present?(image)
53
- run "docker push #{image}"
54
- end
55
-
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)
61
- else
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)}"
64
- end
65
- end
66
- end
67
-
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
- end
76
-
77
- def git_fetch(image)
78
- run "git -C #{source_path(image)} fetch --tags --all --prune"
79
- end
80
-
81
- def git_branch(image)
82
- git_conf(image).fetch('branch', 'origin/master')
83
- end
84
-
85
- def git_conf(image)
86
- image_conf(image)['git']
87
- end
88
-
89
- def image_conf(image)
90
- RatDeployer::Config.images[image]
91
- end
92
-
93
- def source_path(image)
94
- folder = image_conf(image).fetch('source', image)
95
- File.expand_path("./sources/#{folder}")
96
- end
97
-
98
- def source_present?(image)
99
- File.exists? source_path(image)
100
- end
101
-
102
- def image_conf_is_present?(image)
103
- if image_conf(image)
104
- true
105
- else
106
- put_warning "No image config found for image #{image}. Skipping"
107
- false
108
- end
109
- end
110
- end
111
- end
112
- end