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 +4 -4
- data/lib/itamae/backend.rb +13 -1
- data/lib/itamae/cli.rb +1 -0
- data/lib/itamae/logger.rb +2 -1
- data/lib/itamae/recipe.rb +2 -0
- data/lib/itamae/resource.rb +1 -0
- data/lib/itamae/resource/base.rb +7 -0
- data/lib/itamae/resource/git.rb +56 -0
- data/lib/itamae/version.txt +1 -1
- data/spec/integration/default_spec.rb +10 -0
- data/spec/integration/recipes/default.rb +15 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a6d9038e892afddaf4c8d5dceef61585c59c730
|
4
|
+
data.tar.gz: 3529f616034dca772b32d629cecf7211e2b489de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d9230854aa0bcfe65d173b2a0bdbb4a7a9aa9ea000447bbdca0c30d768453b6e83d64f102d23cb68cc27c13e544e5cd583ba7a2644c943039c260cd18bb7b8
|
7
|
+
data.tar.gz: f43d2bf1bc2d97d0cb7eab7130930f63d4edd1eba98ecbdeff8e62df071f4c95653fc0a3877a088cab8f3b2c3819681dcc44135e670a7cf616a5efbfadcecff7
|
data/lib/itamae/backend.rb
CHANGED
@@ -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 = "
|
54
|
+
message = " exited with #{exit_status}"
|
43
55
|
else
|
44
56
|
method = :error
|
45
57
|
message = " Command `#{command}` failed. (exit status: #{exit_status})"
|
data/lib/itamae/cli.rb
CHANGED
data/lib/itamae/logger.rb
CHANGED
@@ -6,7 +6,8 @@ module Itamae
|
|
6
6
|
module Logger
|
7
7
|
class Formatter
|
8
8
|
def call(severity, datetime, progname, msg)
|
9
|
-
|
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
|
data/lib/itamae/recipe.rb
CHANGED
data/lib/itamae/resource.rb
CHANGED
data/lib/itamae/resource/base.rb
CHANGED
@@ -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
|
+
|
data/lib/itamae/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.
|
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.
|
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
|