itamae 1.10.0 → 1.12.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +203 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +144 -1
  5. data/README.md +2 -3
  6. data/Rakefile +50 -42
  7. data/bin/itamae +0 -1
  8. data/itamae.gemspec +2 -2
  9. data/lib/itamae/backend.rb +20 -5
  10. data/lib/itamae/cli.rb +14 -9
  11. data/lib/itamae/definition.rb +0 -2
  12. data/lib/itamae/logger.rb +5 -1
  13. data/lib/itamae/mash.rb +7 -0
  14. data/lib/itamae/node.rb +4 -4
  15. data/lib/itamae/notification.rb +0 -2
  16. data/lib/itamae/recipe.rb +20 -3
  17. data/lib/itamae/resource/base.rb +3 -3
  18. data/lib/itamae/resource/directory.rb +0 -2
  19. data/lib/itamae/resource/execute.rb +0 -2
  20. data/lib/itamae/resource/file.rb +43 -6
  21. data/lib/itamae/resource/gem_package.rb +0 -2
  22. data/lib/itamae/resource/git.rb +5 -7
  23. data/lib/itamae/resource/group.rb +0 -2
  24. data/lib/itamae/resource/http_request.rb +12 -3
  25. data/lib/itamae/resource/link.rb +0 -2
  26. data/lib/itamae/resource/local_ruby_block.rb +0 -2
  27. data/lib/itamae/resource/package.rb +3 -3
  28. data/lib/itamae/resource/remote_directory.rb +1 -3
  29. data/lib/itamae/resource/remote_file.rb +0 -2
  30. data/lib/itamae/resource/service.rb +0 -2
  31. data/lib/itamae/resource/template.rb +8 -4
  32. data/lib/itamae/resource/user.rb +0 -2
  33. data/lib/itamae/resource.rb +0 -1
  34. data/lib/itamae/runner.rb +3 -4
  35. data/lib/itamae/version.rb +1 -1
  36. data/lib/itamae.rb +1 -1
  37. data/spec/integration/default_spec.rb +26 -32
  38. data/spec/integration/docker_spec.rb +29 -0
  39. data/spec/integration/local_spec.rb +6 -0
  40. data/spec/integration/ordinary_user_spec.rb +108 -0
  41. data/spec/integration/recipes/default.rb +10 -48
  42. data/spec/integration/recipes/docker.rb +44 -0
  43. data/spec/integration/recipes/local.rb +19 -0
  44. data/spec/integration/recipes/ordinary_user.rb +109 -0
  45. data/spec/integration/recipes/toplevel_module.rb +6 -0
  46. data/spec/integration/recipes/variables.rb +14 -0
  47. data/spec/unit/lib/itamae/backend_spec.rb +10 -10
  48. data/tasks/integration_local_spec.rb +117 -0
  49. metadata +26 -9
  50. data/.travis.yml +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c8a12f995297dabd31b3252f40b6dd38f0cc9238ca9653a7884d4d0e821824d
4
- data.tar.gz: caf697caf3d0f628b6dc1beffe697c6b97b247cfbb1a711674e44f14c8830dab
3
+ metadata.gz: e47ead5c51f39486dc78c265eb1d7ac31ccb1d3597597c73043513c50f755fc7
4
+ data.tar.gz: fb29caac7b950f41e0d24f034a8aec9bac1205263ce1556dbcf6df139f555f6c
5
5
  SHA512:
6
- metadata.gz: 34c6c6d4b83792d9fbe733c8d0ba82ca770d9b194340800ad9afcd9cd33682313458c814f80c80bac3f25389e3dce60132f23da21b8b66032ee08ab850b6dd9e
7
- data.tar.gz: 69bce9ffc7feb0528027d3af15a9127799dffd775a4f9c07dc72a0a98ed6d04fbbd8a8eb13d9fb0d4fbc6b55d4f032d7be51fee365ddb70cfb71de459010f1fc
6
+ metadata.gz: d0fc18bd902d82bd812fd0a6f65f2e3788c538c22f2141a07201c01e58c0c0c943aa449fc20e5cc3d4f203514595d5f0573ad84bf89c06fe60e6eab7c2f6dcd1
7
+ data.tar.gz: b0f179fcaa5de472f01afcc716d9407e332ace2e11d897318205e2630440b866f1802e3dc52800e106110668aa64b2954e39be0f997404bf03ad73aa9d1a4671
@@ -0,0 +1,203 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ types:
9
+ - opened
10
+ - synchronize
11
+ - reopened
12
+ schedule:
13
+ - cron: "0 0 * * 5" # JST 9:00 (Fri)
14
+
15
+ jobs:
16
+ unit:
17
+ runs-on: ubuntu-latest
18
+
19
+ strategy:
20
+ fail-fast: false
21
+
22
+ matrix:
23
+ ruby:
24
+ - "2.3"
25
+ - "2.4"
26
+ - "2.5"
27
+ - "2.6"
28
+ - "2.7"
29
+ - "3.0"
30
+ - "3.1"
31
+ rubyopt:
32
+ - ""
33
+ - "--jit"
34
+ exclude:
35
+ # --jit is available since MRI 2.6
36
+ - ruby: "2.3"
37
+ rubyopt: "--jit"
38
+ - ruby: "2.4"
39
+ rubyopt: "--jit"
40
+ - ruby: "2.5"
41
+ rubyopt: "--jit"
42
+
43
+ env:
44
+ RUBYOPT: ${{ matrix.rubyopt }}
45
+
46
+ steps:
47
+ - uses: actions/checkout@v2
48
+
49
+ - uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: ${{ matrix.ruby }}
52
+ bundler-cache: true
53
+
54
+ - run: bundle update
55
+
56
+ - run: bundle exec rake spec:unit
57
+
58
+ - name: Slack Notification (not success)
59
+ uses: lazy-actions/slatify@master
60
+ if: "! success()"
61
+ continue-on-error: true
62
+ with:
63
+ job_name: ${{ format('*unit* ({0},{1})', matrix.ruby, matrix.rubyopt) }}
64
+ type: ${{ job.status }}
65
+ icon_emoji: ":octocat:"
66
+ url: ${{ secrets.SLACK_WEBHOOK }}
67
+ token: ${{ secrets.GITHUB_TOKEN }}
68
+
69
+ integration-docker:
70
+ runs-on: ubuntu-latest
71
+
72
+ strategy:
73
+ fail-fast: false
74
+
75
+ matrix:
76
+ ruby:
77
+ - "2.3"
78
+ - "2.4"
79
+ - "2.5"
80
+ - "2.6"
81
+ - "2.7"
82
+ - "3.0"
83
+ rubyopt:
84
+ - ""
85
+ - "--jit"
86
+ image:
87
+ - ubuntu:trusty
88
+ exclude:
89
+ # --jit is available since MRI 2.6
90
+ - ruby: "2.3"
91
+ rubyopt: "--jit"
92
+ - ruby: "2.4"
93
+ rubyopt: "--jit"
94
+ - ruby: "2.5"
95
+ rubyopt: "--jit"
96
+
97
+ env:
98
+ RUBYOPT: ${{ matrix.rubyopt }}
99
+ TEST_IMAGE: ${{ matrix.image }}
100
+
101
+ steps:
102
+ - uses: actions/checkout@v2
103
+
104
+ - uses: ruby/setup-ruby@v1
105
+ with:
106
+ ruby-version: ${{ matrix.ruby }}
107
+ bundler-cache: true
108
+
109
+ - run: bundle update
110
+
111
+ - run: bundle exec rake spec:integration:docker:boot
112
+
113
+ - run: bundle exec rake spec:integration:docker:provision
114
+ env:
115
+ # FIXME: avoid error for "Command `chmod 777 /tmp/itamae_tmp` failed. (exit status: 1)"
116
+ ITAMAE_TMP_DIR: /var/tmp/itamae_tmp
117
+
118
+ - run: bundle exec rake spec:integration:docker:serverspec
119
+ - run: bundle exec rake spec:integration:docker:clean_docker_container
120
+
121
+ - name: Slack Notification (not success)
122
+ uses: lazy-actions/slatify@master
123
+ if: "! success()"
124
+ continue-on-error: true
125
+ with:
126
+ job_name: ${{ format('*integration-docker* ({0},{1},{2})', matrix.ruby, matrix.rubyopt, matrix.image) }}
127
+ type: ${{ job.status }}
128
+ icon_emoji: ":octocat:"
129
+ url: ${{ secrets.SLACK_WEBHOOK }}
130
+ token: ${{ secrets.GITHUB_TOKEN }}
131
+
132
+ integration-local:
133
+ runs-on: ubuntu-latest
134
+
135
+ strategy:
136
+ fail-fast: false
137
+
138
+ matrix:
139
+ ruby:
140
+ - "2.3"
141
+ - "2.4"
142
+ - "2.5"
143
+ - "2.6"
144
+ - "2.7"
145
+ - "3.0"
146
+ rubyopt:
147
+ - ""
148
+ - "--jit"
149
+ exclude:
150
+ # --jit is available since MRI 2.6
151
+ - ruby: "2.3"
152
+ rubyopt: "--jit"
153
+ - ruby: "2.4"
154
+ rubyopt: "--jit"
155
+ - ruby: "2.5"
156
+ rubyopt: "--jit"
157
+
158
+ env:
159
+ RUBYOPT: ${{ matrix.rubyopt }}
160
+
161
+ steps:
162
+ - uses: actions/checkout@v2
163
+
164
+ - uses: ruby/setup-ruby@v1
165
+ with:
166
+ ruby-version: ${{ matrix.ruby }}
167
+ bundler-cache: true
168
+
169
+ - run: bundle update
170
+
171
+ - run: bundle exec rake spec:integration:local:main
172
+ - run: bundle exec rake spec:integration:local:ordinary_user
173
+
174
+ - name: Slack Notification (not success)
175
+ uses: lazy-actions/slatify@master
176
+ if: "! success()"
177
+ continue-on-error: true
178
+ with:
179
+ job_name: ${{ format('*integration-local* ({0},{1})', matrix.ruby, matrix.rubyopt) }}
180
+ type: ${{ job.status }}
181
+ icon_emoji: ":octocat:"
182
+ url: ${{ secrets.SLACK_WEBHOOK }}
183
+ token: ${{ secrets.GITHUB_TOKEN }}
184
+
185
+ notify:
186
+ needs:
187
+ - unit
188
+ - integration-docker
189
+ - integration-local
190
+
191
+ runs-on: ubuntu-latest
192
+
193
+ steps:
194
+ - name: Slack Notification (success)
195
+ uses: lazy-actions/slatify@master
196
+ if: always()
197
+ continue-on-error: true
198
+ with:
199
+ job_name: '*notify*'
200
+ type: ${{ job.status }}
201
+ icon_emoji: ":octocat:"
202
+ url: ${{ secrets.SLACK_WEBHOOK }}
203
+ token: ${{ secrets.GITHUB_TOKEN }}
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  .vagrant
19
19
  Gemfile.local
20
+ .ruby-version
data/CHANGELOG.md CHANGED
@@ -1,5 +1,148 @@
1
1
  ## Unreleased
2
- [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.0...master)
2
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.12.5...master)
3
+
4
+ ## v1.12.5
5
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.12.4...v1.12.5)
6
+
7
+ Bugfixes
8
+
9
+ - [Define exit_on_failure? to suppress thor's warning](https://github.com/itamae-kitchen/itamae/pull/344)
10
+
11
+ ## v1.12.4
12
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.12.3...v1.12.4)
13
+
14
+ Improvements
15
+
16
+ - [Initialize tmp_dir if no tmpdir option was specified.](https://github.com/itamae-kitchen/itamae/pull/341)
17
+
18
+ ## v1.12.3
19
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.12.2...v1.12.3)
20
+
21
+ Bugfixes
22
+
23
+ - [Fix Chef install script URL (by @NPoi)](https://github.com/itamae-kitchen/itamae/pull/339)
24
+
25
+ ## v1.12.2
26
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.12.1...v1.12.2)
27
+
28
+ Improvements
29
+
30
+ - [remote_directory: add diff -r option](https://github.com/itamae-kitchen/itamae/pull/338)
31
+
32
+ ## v1.12.1
33
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.12.0...v1.12.1)
34
+
35
+ Improvements
36
+
37
+ - [Allow defining top-level modules without `::`](https://github.com/itamae-kitchen/itamae/pull/332)
38
+
39
+ ## v1.12.0
40
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.11.2...v1.12.0)
41
+
42
+ Improvements
43
+
44
+ - [Add `--tmp-dir` to cli options](https://github.com/itamae-kitchen/itamae/pull/331)
45
+
46
+ ## v1.11.2
47
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.11.1...v1.11.2)
48
+
49
+ Bugfixes
50
+
51
+ - [Support thor-1.1.0 (by @chaaaaarlotte)](https://github.com/itamae-kitchen/itamae/pull/329)
52
+
53
+ ## v1.11.1
54
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.11.0...v1.11.1)
55
+
56
+ Improvements
57
+
58
+ - [Support Ruby 3.0.0](https://github.com/itamae-kitchen/itamae/pull/326)
59
+ - [file: improve diff output (by @terceiro)](https://github.com/itamae-kitchen/itamae/pull/327)
60
+
61
+ ## v1.11.0
62
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.10...v1.11.0)
63
+
64
+ Improvements
65
+
66
+ - [file: add support for sensitive files (by @terceiro)](https://github.com/itamae-kitchen/itamae/pull/325)
67
+
68
+ ## v1.10.10
69
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.9...v1.10.10)
70
+
71
+ Improvements
72
+
73
+ - [Make output unbuffered](https://github.com/itamae-kitchen/itamae/pull/317)
74
+
75
+ ## v1.10.9
76
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.8...v1.10.9)
77
+
78
+ Improvements
79
+
80
+ - [Fix CRLF problem in windows](https://github.com/itamae-kitchen/itamae/pull/316)
81
+
82
+ ## v1.10.8
83
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.7...v1.10.8)
84
+
85
+ Improvements
86
+
87
+ - [Print "(in action_XXX)" as a debug log](https://github.com/itamae-kitchen/itamae/pull/315)
88
+ - [Reduce `check_package_is_installed` calling when package version is not specified](https://github.com/itamae-kitchen/itamae/pull/314)
89
+ - [Simplify Git resource's get_revision method](https://github.com/itamae-kitchen/itamae/pull/313)
90
+
91
+ ## v1.10.7
92
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.6...v1.10.7)
93
+
94
+ Improvements
95
+
96
+ - [Improve `file` resource performance](https://github.com/itamae-kitchen/itamae/pull/310)
97
+
98
+ ## v1.10.6
99
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.5...v1.10.6)
100
+
101
+ Improvements
102
+
103
+ - [Don't use `sudo` when `--no-sudo` is passed](https://github.com/itamae-kitchen/itamae/pull/302)
104
+
105
+ ## v1.10.5
106
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.4...v1.10.5)
107
+
108
+ Improvements
109
+
110
+ - [Check http status code in `http_request` resource (by @takumin)](https://github.com/itamae-kitchen/itamae/pull/296)
111
+
112
+ ## v1.10.4
113
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.3...v1.10.4)
114
+
115
+ Bugfixes
116
+
117
+ - [Suppress Ruby warnings (by @pocke)](https://github.com/itamae-kitchen/itamae/pull/284)
118
+ - [Suppress Ruby warning (by @pocke)](https://github.com/itamae-kitchen/itamae/pull/287)
119
+ - [Run test cases correctly (by @pocke)](https://github.com/itamae-kitchen/itamae/pull/289)
120
+
121
+ Improvements
122
+
123
+ - [Add description to --tag option of docker subcommand (by @pocke)](https://github.com/itamae-kitchen/itamae/pull/286)
124
+ - [Refine `itamae docker`'s created message (by @pocke)](https://github.com/itamae-kitchen/itamae/pull/288)
125
+
126
+ ## v1.10.3
127
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.2...v1.10.3)
128
+
129
+ Bugfixes
130
+
131
+ - [Make `send_file` aware of `user` option](https://github.com/itamae-kitchen/itamae/pull/277)
132
+
133
+ ## v1.10.2
134
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.1...v1.10.2)
135
+
136
+ Bugfixes
137
+
138
+ - [Disable mash warnings (review catch up)](https://github.com/itamae-kitchen/itamae/pull/273)
139
+
140
+ ## v1.10.1
141
+ [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.10.0...v1.10.1)
142
+
143
+ Bugfixes
144
+
145
+ - [fail `--ohai` option when using ohai v13.0.1 or higher](https://github.com/itamae-kitchen/itamae/pull/251)
3
146
 
4
147
  ## v1.10.0
5
148
  [full changelog](https://github.com/itamae-kitchen/itamae/compare/v1.9.13...v1.10.0)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # [![](https://raw.githubusercontent.com/itamae-kitchen/itamae-logos/master/small/FA-Itamae-horizontal-01-180x72.png)](https://github.com/itamae-kitchen/itamae)
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/itamae.svg)](http://badge.fury.io/rb/itamae) [![Code Climate](https://codeclimate.com/github/ryotarai/itamae/badges/gpa.svg)](https://codeclimate.com/github/ryotarai/itamae) [![Build Status](https://travis-ci.org/itamae-kitchen/itamae.svg?branch=master)](https://travis-ci.org/itamae-kitchen/itamae) [![Slack](https://img.shields.io/badge/slack-join-blue.svg)](https://itamae-slackin.herokuapp.com/)
3
+ [![Gem Version](https://badge.fury.io/rb/itamae.svg)](http://badge.fury.io/rb/itamae) [![Code Climate](https://codeclimate.com/github/ryotarai/itamae/badges/gpa.svg)](https://codeclimate.com/github/ryotarai/itamae) [![Build Status](https://github.com/itamae-kitchen/itamae/workflows/test/badge.svg?branch=master)](https://github.com/itamae-kitchen/itamae/actions?query=workflow%3Atest) [![Slack](https://img.shields.io/badge/slack-join-blue.svg)](https://join.slack.com/t/itamae/shared_invite/enQtNTExNTI3ODM1NTY5LTM5MWJlZTgwODE0YTUwMThiNzZjN2I1MGNlZjE2NjlmNzg5NTNlOTliMDhkNDNmNTQ2ZTgwMzZjNjI5NDJiZGI)
4
4
 
5
5
  Simple and lightweight configuration management tool inspired by Chef.
6
6
 
@@ -77,7 +77,7 @@ $ bundle exec rake spec
77
77
 
78
78
  ## Get Involved
79
79
 
80
- - [Join Slack team](https://itamae-slackin.herokuapp.com/)
80
+ - [Join Slack team](https://itamae-slackin.herokuapp.com)
81
81
 
82
82
  ## Presentations / Articles
83
83
 
@@ -97,4 +97,3 @@ If you have a problem, please [create an issue](https://github.com/itamae-kitche
97
97
  3. Commit your changes (`git commit -am 'Add some feature'`)
98
98
  4. Push to the branch (`git push origin my-new-feature`)
99
99
  5. Create new Pull Request
100
-
data/Rakefile CHANGED
@@ -3,9 +3,15 @@ require 'rspec/core/rake_task'
3
3
  require 'tempfile'
4
4
  require 'net/ssh'
5
5
 
6
+ Dir['tasks/*.rb'].each do |file|
7
+ require_relative file
8
+ end
9
+
6
10
  desc 'Run unit and integration specs.'
7
11
  task :spec => ['spec:unit', 'spec:integration:all']
8
12
 
13
+ TEST_IMAGE = ENV["TEST_IMAGE"] || "ubuntu:trusty"
14
+
9
15
  namespace :spec do
10
16
  RSpec::Core::RakeTask.new("unit") do |task|
11
17
  task.ruby_opts = '-I ./spec/unit'
@@ -13,60 +19,62 @@ namespace :spec do
13
19
  end
14
20
 
15
21
  namespace :integration do
16
- targets = ["ubuntu:trusty"]
22
+ container_name = 'itamae'
17
23
 
18
- task :all => targets
24
+ task :all => ['spec:integration:docker' 'spec:integration:local']
19
25
 
20
- targets.each do |target|
21
- desc "Run provision and specs to #{target}"
22
- task target => ["docker:#{target}", "provision:#{target}", "serverspec:#{target}"]
26
+ desc "Run provision and specs"
27
+ task :docker => ["docker:boot", "docker:provision", "docker:serverspec", 'docker:clean_docker_container']
23
28
 
24
- namespace :docker do
25
- desc "Run docker for #{target}"
26
- task target do
27
- sh "docker run --privileged -d --name itamae #{target} /sbin/init"
28
- end
29
+ namespace :docker do
30
+ desc "Run docker"
31
+ task :boot do
32
+ sh "docker run --privileged -d --name #{container_name} #{TEST_IMAGE} /sbin/init"
29
33
  end
30
34
 
31
- namespace :provision do
32
- desc "Run itamae to #{target}"
33
- task target do
34
- suites = [
35
- [
36
- "spec/integration/recipes/default.rb",
37
- "spec/integration/recipes/default2.rb",
38
- "spec/integration/recipes/redefine.rb",
39
- ],
40
- [
41
- "--dry-run",
42
- "spec/integration/recipes/dry_run.rb",
43
- ],
44
- ]
45
- suites.each do |suite|
46
- cmd = %w!bundle exec bin/itamae docker!
47
- cmd << "-l" << (ENV['LOG_LEVEL'] || 'debug')
48
- cmd << "-j" << "spec/integration/recipes/node.json"
49
- cmd << "--container" << "itamae"
50
- cmd << "--tag" << "itamae:latest"
51
- cmd += suite
35
+ desc "Run itamae"
36
+ task :provision do
37
+ suites = [
38
+ [
39
+ "spec/integration/recipes/default.rb",
40
+ "spec/integration/recipes/default2.rb",
41
+ "spec/integration/recipes/redefine.rb",
42
+ "spec/integration/recipes/docker.rb",
43
+ ],
44
+ [
45
+ "--dry-run",
46
+ "spec/integration/recipes/dry_run.rb",
47
+ ],
48
+ ]
49
+ suites.each do |suite|
50
+ cmd = %w!bundle exec ruby -w bin/itamae docker!
51
+ cmd << "-l" << (ENV['LOG_LEVEL'] || 'debug')
52
+ cmd << "-j" << "spec/integration/recipes/node.json"
53
+ cmd << "--container" << container_name
54
+ cmd << "--tag" << "itamae:latest"
55
+ cmd << "--tmp-dir" << (ENV['ITAMAE_TMP_DIR'] || '/tmp/itamae_tmp')
56
+ cmd += suite
52
57
 
53
- p cmd
54
- unless system(*cmd)
55
- raise "#{cmd} failed"
56
- end
58
+ p cmd
59
+ unless system(*cmd)
60
+ raise "#{cmd} failed"
57
61
  end
58
62
  end
59
63
  end
60
64
 
61
- namespace :serverspec do
62
- desc "Run serverspec tests to #{target}"
63
- RSpec::Core::RakeTask.new(target.to_sym) do |t|
64
- ENV['DOCKER_CONTAINER'] = "itamae"
65
- t.ruby_opts = '-I ./spec/integration'
66
- t.pattern = "spec/integration/*_spec.rb"
67
- end
65
+ desc "Run serverspec tests"
66
+ RSpec::Core::RakeTask.new(:serverspec) do |t|
67
+ ENV['DOCKER_CONTAINER'] = container_name
68
+ t.ruby_opts = '-I ./spec/integration'
69
+ t.pattern = "spec/integration/{default,docker}_spec.rb"
70
+ end
71
+
72
+ desc 'Clean a docker container for test'
73
+ task :clean_docker_container do
74
+ sh('docker', 'rm', '-f', container_name)
68
75
  end
69
76
  end
70
77
  end
71
78
  end
72
79
 
80
+ task :default => :spec
data/bin/itamae CHANGED
@@ -2,4 +2,3 @@
2
2
 
3
3
  require 'itamae/cli'
4
4
  Itamae::CLI.start
5
-
data/itamae.gemspec CHANGED
@@ -32,12 +32,12 @@ Gem::Specification.new do |spec|
32
32
  spec.add_runtime_dependency "ansi"
33
33
  spec.add_runtime_dependency "schash", "~> 0.1.0"
34
34
 
35
- spec.add_development_dependency "bundler", "~> 1.3"
35
+ spec.add_development_dependency "bundler", ">= 1.3"
36
36
  spec.add_development_dependency "rake"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
  spec.add_development_dependency "serverspec", "~> 2.1"
39
39
  spec.add_development_dependency "pry-byebug"
40
- spec.add_development_dependency "docker-api", "~> 1.20"
40
+ spec.add_development_dependency "docker-api", "~> 2"
41
41
  spec.add_development_dependency "fakefs"
42
42
  spec.add_development_dependency "fluent-logger"
43
43
  end
@@ -9,7 +9,7 @@ module Specinfra
9
9
  module Configuration
10
10
  def self.sudo_password
11
11
  return ENV['SUDO_PASSWORD'] if ENV['SUDO_PASSWORD']
12
- return @sudo_password if @sudo_password
12
+ return @sudo_password if defined?(@sudo_password)
13
13
 
14
14
  # TODO: Fix this dirty hack
15
15
  return nil unless caller.any? {|call| call.include?('channel_data') }
@@ -98,7 +98,7 @@ module Itamae
98
98
  @backend.receive_file(src, dst)
99
99
  end
100
100
 
101
- def send_file(src, dst)
101
+ def send_file(src, dst, user: nil)
102
102
  Itamae.logger.debug "Sending a file from '#{src}' to '#{dst}'..."
103
103
  unless ::File.exist?(src)
104
104
  raise SourceNotExistError, "The file '#{src}' doesn't exist."
@@ -106,7 +106,15 @@ module Itamae
106
106
  unless ::File.file?(src)
107
107
  raise SourceNotExistError, "'#{src}' is not a file."
108
108
  end
109
- @backend.send_file(src, dst)
109
+
110
+ if self.instance_of?(Backend::Local)
111
+ read_command = build_command("cat #{src.shellescape}", {})
112
+ write_command = build_command("cat > #{dst.shellescape}", user: user)
113
+ command = [read_command, write_command].join(' | ')
114
+ run_command(command)
115
+ else
116
+ @backend.send_file(src, dst)
117
+ end
110
118
  end
111
119
 
112
120
  def send_directory(src, dst)
@@ -180,7 +188,7 @@ module Itamae
180
188
  end
181
189
 
182
190
  user = options[:user]
183
- if user
191
+ if user && use_sudo?
184
192
  command = "cd ~#{user.shellescape} ; #{command}"
185
193
  command = "sudo -H -u #{user.shellescape} -- #{shell.shellescape} -c #{command.shellescape}"
186
194
  end
@@ -188,6 +196,11 @@ module Itamae
188
196
  command
189
197
  end
190
198
 
199
+ def use_sudo?
200
+ return true unless @options.key?(:sudo)
201
+ !!@options[:sudo]
202
+ end
203
+
191
204
  def shell
192
205
  @options[:shell] || '/bin/sh'
193
206
  end
@@ -284,7 +297,9 @@ module Itamae
284
297
  /\A(?<repo>.+?)(?:|:(?<tag>[^:]+))\z/.match(@options[:tag]) do |m|
285
298
  image.tag(repo: m[:repo], tag: m[:tag])
286
299
  end
287
- Itamae.logger.info "Image created: #{image.id}"
300
+ log_message = "Image created: #{image.id}"
301
+ log_message << ", and tagged as #{@options[:tag]}" if @options[:tag]
302
+ Itamae.logger.info log_message
288
303
  end
289
304
 
290
305
  private
data/lib/itamae/cli.rb CHANGED
@@ -25,6 +25,19 @@ module Itamae
25
25
  option :log_level, type: :string, aliases: ['-l'], default: 'info'
26
26
  option :color, type: :boolean, default: true
27
27
  option :config, type: :string, aliases: ['-c']
28
+ option :tmp_dir, type: :string, aliases: ['-t'], default: "/tmp/itamae_tmp"
29
+ end
30
+
31
+ def self.options
32
+ @itamae_options ||= super.dup.tap do |options|
33
+ if config = options[:config]
34
+ options.merge!(YAML.load_file(config))
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.exit_on_failure?
40
+ true
28
41
  end
29
42
 
30
43
  desc "local RECIPE [RECIPE...]", "Run Itamae locally"
@@ -64,7 +77,7 @@ module Itamae
64
77
  option :image, type: :string, desc: "This option or 'container' option is required."
65
78
  option :container, type: :string, desc: "This option or 'image' option is required."
66
79
  option :tls_verify_peer, type: :boolean, default: true
67
- option :tag, type: :string
80
+ option :tag, type: :string, desc: 'Tag name of created docker image.'
68
81
  def docker(*recipe_files)
69
82
  if recipe_files.empty?
70
83
  raise "Please specify recipe files."
@@ -117,14 +130,6 @@ module Itamae
117
130
  end
118
131
 
119
132
  private
120
- def options
121
- @itamae_options ||= super.dup.tap do |options|
122
- if config = options[:config]
123
- options.merge!(YAML.load_file(config))
124
- end
125
- end
126
- end
127
-
128
133
  def validate_generate_target!(command, target)
129
134
  unless GENERATE_TARGETS.include?(target)
130
135
  msg = %Q!ERROR: "itamae #{command}" was called with "#{target}" !
@@ -1,5 +1,3 @@
1
- require 'itamae'
2
-
3
1
  module Itamae
4
2
  class Definition < Resource::Base
5
3
  class << self
data/lib/itamae/logger.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'itamae'
2
1
  require 'logger'
3
2
  require 'ansi/code'
4
3
 
@@ -72,6 +71,10 @@ module Itamae
72
71
  class Formatter
73
72
  attr_accessor :colored
74
73
 
74
+ def initialize
75
+ @color = nil
76
+ end
77
+
75
78
  def call(severity, datetime, progname, msg)
76
79
  log = "%s : %s" % ["%5s" % severity, msg2str(msg)]
77
80
 
@@ -123,6 +126,7 @@ module Itamae
123
126
  @logger = ::Logger.new($stdout).tap do |l|
124
127
  l.formatter = Itamae::Logger::Formatter.new
125
128
  end.extend(Itamae::Logger::Helper)
129
+ $stdout.sync = true
126
130
 
127
131
  class << self
128
132
  def logger