itamae 1.0.0.beta13 → 1.0.0.beta14

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: cc9e5387ea9471a6357ec8d1d2fec041fd70bb2c
4
- data.tar.gz: 250fa56a23f0d5450f1d9f24c733c4b52b570707
3
+ metadata.gz: 8a6d9038e892afddaf4c8d5dceef61585c59c730
4
+ data.tar.gz: 3529f616034dca772b32d629cecf7211e2b489de
5
5
  SHA512:
6
- metadata.gz: d98ca86c23813146e2bcd9eaf3b519da859caf914fb61d9ce79c179b61c7144cac99c05957b948ceecac6c1942626b6455e8702c39b935c17b2f41fec7d47dbb
7
- data.tar.gz: c48f5785e62f131cfe7509a811bb0ed256086f2bee6224412cf0a732f372acc9492e1d1758b9fa6a73112fb6eca5497fb0d3623ba1962867b54424ef664eeb14
6
+ metadata.gz: 73d9230854aa0bcfe65d173b2a0bdbb4a7a9aa9ea000447bbdca0c30d768453b6e83d64f102d23cb68cc27c13e544e5cd583ba7a2644c943039c260cd18bb7b8
7
+ data.tar.gz: f43d2bf1bc2d97d0cb7eab7130930f63d4edd1eba98ecbdeff8e62df071f4c95653fc0a3877a088cab8f3b2c3819681dcc44135e670a7cf616a5efbfadcecff7
@@ -34,12 +34,24 @@ module Itamae
34
34
  command = commands
35
35
  end
36
36
 
37
+ cwd = options[:cwd]
38
+ if cwd
39
+ command = "cd #{Shellwords.escape(cwd)} && #{command}"
40
+ end
41
+
42
+ user = options[:user]
43
+ if user
44
+ command = "sudo -u #{Shellwords.escape(user)} -- /bin/sh -c #{Shellwords.escape(command)}"
45
+ end
46
+
47
+ Logger.debug " Executing `#{command}`..."
48
+
37
49
  result = Specinfra::Runner.run_command(command)
38
50
  exit_status = result.exit_status
39
51
 
40
52
  if exit_status == 0 || !options[:error]
41
53
  method = :debug
42
- message = " Command `#{command}` exited with #{exit_status}"
54
+ message = " exited with #{exit_status}"
43
55
  else
44
56
  method = :error
45
57
  message = " Command `#{command}` failed. (exit status: #{exit_status})"
@@ -4,6 +4,7 @@ require 'thor'
4
4
  module Itamae
5
5
  class CLI < Thor
6
6
  class_option :log_level, type: :string, aliases: ['-l'], default: 'info'
7
+ class_option :color, type: :boolean, default: true
7
8
 
8
9
  def initialize(*args)
9
10
  super
@@ -6,7 +6,8 @@ module Itamae
6
6
  module Logger
7
7
  class Formatter
8
8
  def call(severity, datetime, progname, msg)
9
- "[%s] %s : %s\n" % [format_datetime(datetime), color("%5s" % severity, severity), msg2str(msg)]
9
+ severity = color("%5s" % severity, severity)
10
+ "[%s] %s : %s\n" % [format_datetime(datetime), severity, msg2str(msg)]
10
11
  end
11
12
 
12
13
  private
@@ -45,6 +45,8 @@ module Itamae
45
45
  klass = Resource.get_resource_class(method)
46
46
  resource = klass.new(self, name, &block)
47
47
  @dependencies << resource
48
+ rescue NameError
49
+ super
48
50
  end
49
51
 
50
52
  def include_recipe(target)
@@ -10,6 +10,7 @@ require 'itamae/resource/mail_alias'
10
10
  require 'itamae/resource/service'
11
11
  require 'itamae/resource/link'
12
12
  require 'itamae/resource/local_ruby_block'
13
+ require 'itamae/resource/git'
13
14
 
14
15
  module Itamae
15
16
  module Resource
@@ -24,6 +24,7 @@ module Itamae
24
24
  end
25
25
 
26
26
  define_attribute :action, type: [Symbol, Array], required: true
27
+ define_attribute :user, type: String
27
28
 
28
29
  attr_reader :recipe
29
30
  attr_reader :resource_name
@@ -219,6 +220,12 @@ module Itamae
219
220
  end
220
221
 
221
222
  def run_command(*args)
223
+ unless args.last.is_a?(Hash)
224
+ args << {}
225
+ end
226
+
227
+ args.last[:user] ||= user
228
+
222
229
  backend.run_command(*args)
223
230
  end
224
231
 
@@ -0,0 +1,56 @@
1
+ require 'itamae'
2
+
3
+ module Itamae
4
+ module Resource
5
+ class Git < Base
6
+ DEPLOY_BRANCH = "deploy"
7
+
8
+ define_attribute :action, default: :sync
9
+ define_attribute :destination, type: String, default_name: true
10
+ define_attribute :repository, type: String, required: true
11
+ define_attribute :revision, type: String
12
+
13
+ def sync_action
14
+ ensure_git_available
15
+
16
+ if run_specinfra(:check_file_is_directory, destination)
17
+ run_command_in_repo(['git', 'fetch', 'origin'])
18
+ else
19
+ run_command(['git', 'clone', repository, destination])
20
+ end
21
+
22
+ target_revision =
23
+ revision ||
24
+ run_command_in_repo("git ls-remote origin HEAD | cut -f1").stdout.strip
25
+
26
+ deploy_old_created = false
27
+ if current_branch == DEPLOY_BRANCH
28
+ run_command_in_repo("git branch -m deploy-old")
29
+ deploy_old_created = true
30
+ end
31
+
32
+ run_command_in_repo(["git", "checkout", target_revision, "-b", DEPLOY_BRANCH])
33
+
34
+ if deploy_old_created
35
+ run_command_in_repo("git branch -d deploy-old")
36
+ end
37
+ end
38
+
39
+ private
40
+ def ensure_git_available
41
+ unless run_command("which git", error: false).exit_status == 0
42
+ raise "`git` command is not available. Please install git."
43
+ end
44
+ end
45
+
46
+ def run_command_in_repo(*args)
47
+ run_command(*args, cwd: destination)
48
+ end
49
+
50
+ def current_branch
51
+ run_command_in_repo("git rev-parse --abbrev-ref HEAD").stdout.strip
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -1 +1 @@
1
- 1.0.0.beta13
1
+ 1.0.0.beta14
@@ -78,3 +78,13 @@ describe file('/tmp-link') do
78
78
  expect(subject.content.lines.size).to eq 0
79
79
  end
80
80
  end
81
+
82
+ describe command('cd /tmp/git_repo && git rev-parse HEAD') do
83
+ its(:stdout) { should match(/3116e170b89dc0f7315b69c1c1e1fd7fab23ac0d/) }
84
+ end
85
+
86
+ describe file('/tmp/created_by_itamae_user') do
87
+ it { should be_file }
88
+ it { should be_owned_by 'itamae' }
89
+ end
90
+
@@ -128,3 +128,18 @@ local_ruby_block "greeting" do
128
128
  end
129
129
  end
130
130
 
131
+ #####
132
+
133
+ package "git"
134
+
135
+ git "/tmp/git_repo" do
136
+ repository "https://github.com/ryotarai/infrataster.git"
137
+ revision "v0.1.0"
138
+ end
139
+
140
+ #####
141
+
142
+ execute "echo Hello > /tmp/created_by_itamae_user" do
143
+ user "itamae"
144
+ end
145
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta13
4
+ version: 1.0.0.beta14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
@@ -164,6 +164,7 @@ files:
164
164
  - lib/itamae/resource/directory.rb
165
165
  - lib/itamae/resource/execute.rb
166
166
  - lib/itamae/resource/file.rb
167
+ - lib/itamae/resource/git.rb
167
168
  - lib/itamae/resource/link.rb
168
169
  - lib/itamae/resource/local_ruby_block.rb
169
170
  - lib/itamae/resource/mail_alias.rb