conjur-debify 0.4.1 → 0.6.0

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: 24d8fe10e0486db7bb2507eb4437011c7b604553
4
- data.tar.gz: 74d13c5b2998e96664c704b1f3e25e4d913c776d
3
+ metadata.gz: 237173296d36243ddc8ad529b34b370aa2be9d0a
4
+ data.tar.gz: e0282d3f9c0ae54e2ce1ecd2a96e82cd1f3770a8
5
5
  SHA512:
6
- metadata.gz: 8cc53a5458f5dc85665a6a58b5fe15b0b373834645504fe2e9bc1a80caafddbbd8987f0939e45e111e14565bd00d9839307e7716d9f53c5cb3db30a4ce0d363b
7
- data.tar.gz: 4d651e1ba3026f937ce23474e4710df624415416860cc814d4e272447fd3e33b063abf8cc998995e4c1cf22623d7cca3fbe6c5eeb898e991e08c563836dc0fcb
6
+ metadata.gz: 8b3aa38f2accc5fcf7e57a98d5a4c13461f420f7b66c2e546e9d84091ecf410d75d990d0507c652283417f811e3f970e902006359be97557e68c12da1a2a48bc
7
+ data.tar.gz: 2284cabc731e5e73c4fe50014e51e5d96663ab8a3f9cd896687efb385bd77d20ca77f600bd29f7eb320f821efd320a7be4ec9db602b4c4e80ed7ee654d8ee8fe
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # 0.5.0
2
+
3
+ * `package` : Add `--dockerfile` option
4
+ * `package` : Ensure that `Gemfile.lock` is in the container
5
+ * `test` : Propagate `SSH_AUTH_SOCK` to the container
data/lib/conjur/debify.rb CHANGED
@@ -10,7 +10,7 @@ Docker.options[:read_timeout] = 300
10
10
  # This is used to turn on DEBUG notices for the test case operation. For instance,
11
11
  # messages from "evoke configure"
12
12
  module DebugMixin
13
- DEBUG = ENV['DEBUG']
13
+ DEBUG = ENV['DEBUG'].nil? ? true : ENV['DEBUG'].downcase == 'true'
14
14
 
15
15
  def debug *a
16
16
  DebugMixin.debug *a
@@ -86,6 +86,9 @@ command "package" do |c|
86
86
 
87
87
  c.desc "Specify the deb version; by default, it's computed from the Git tag"
88
88
  c.flag [ :v, :version ]
89
+
90
+ c.desc "Specify a custom Dockerfile.fpm"
91
+ c.flag [ :dockerfile]
89
92
 
90
93
  c.action do |global_options,cmd_options,args|
91
94
  raise "project-name is required" unless project_name = args.shift
@@ -105,16 +108,18 @@ command "package" do |c|
105
108
  dir = File.expand_path(dir)
106
109
  Dir.chdir dir do
107
110
  version = cmd_options[:version] || detect_version
111
+ dockerfile_path = cmd_options[:dockerfile] || File.expand_path("debify/Dockerfile.fpm", pwd)
112
+ dockerfile = File.read(dockerfile_path)
108
113
 
109
114
  package_name = "conjur-#{project_name}_#{version}_amd64.deb"
110
115
 
111
116
  output = StringIO.new
112
117
  Gem::Package::TarWriter.new(output) do |tar|
113
- `git ls-files -z`.split("\x0").each do |fname|
118
+ (`git ls-files -z`.split("\x0") + ['Gemfile.lock']).uniq.each do |fname|
114
119
  stat = File.stat(fname)
115
120
  tar.add_file(fname, stat.mode) { |tar_file| tar_file.write(File.read(fname)) }
116
121
  end
117
- tar.add_file('Dockerfile', 0640) { |tar_file| tar_file.write File.read(File.expand_path("debify/Dockerfile.fpm", pwd)).gsub("@@image@@", fpm_image.id) }
122
+ tar.add_file('Dockerfile', 0640) { |tar_file| tar_file.write dockerfile.gsub("@@image@@", fpm_image.id) }
118
123
  end
119
124
  output.rewind
120
125
 
@@ -167,9 +172,6 @@ Then the evoke "test-install" command is used to install the test code in the
167
172
  /src/<project-name>. Basically, the development bundle is installed and the database
168
173
  configuration (if any) is setup.
169
174
 
170
- Next, an optional "configure-script" from the project source tree is run, with the
171
- container id as the program argument. This command waits for Conjur to be healthy again.
172
-
173
175
  Finally, a test script from the project source tree is run, again with the container
174
176
  id as the program argument.
175
177
 
@@ -195,9 +197,6 @@ command "test" do |c|
195
197
  c.default_value true
196
198
  c.switch [ :pull ]
197
199
 
198
- c.desc "Shell script to configure the appliance before testing"
199
- c.flag [ :c, "configure-script" ]
200
-
201
200
  c.action do |global_options,cmd_options,args|
202
201
  raise "project-name is required" unless project_name = args.shift
203
202
  raise "test-script is required" unless test_script = args.shift
@@ -212,27 +211,59 @@ command "test" do |c|
212
211
  Dir.chdir dir do
213
212
  image_tag = cmd_options["image-tag"] or raise "image-tag is required"
214
213
  appliance_image_id = [ cmd_options[:image], image_tag ].join(":")
215
- configure_script = cmd_options["configure-script"]
216
214
 
217
- raise "#{configure_script} does not exist or is not a file" unless configure_script.nil? || File.file?(configure_script)
218
215
  raise "#{test_script} does not exist or is not a file" unless File.file?(test_script)
219
-
220
- appliance_image = if cmd_options[:pull]
221
- Docker::Image.create 'fromImage' => appliance_image_id, &DebugMixin::DOCKER
222
- else
223
- Docker::Image.get(appliance_image_id)
216
+
217
+ Docker::Image.create 'fromImage' => appliance_image_id, &DebugMixin::DOCKER if cmd_options[:pull]
218
+
219
+ def build_test_image(appliance_image_id, project_name)
220
+ deb = "conjur-#{project_name}_latest_amd64.deb"
221
+ dockerfile = <<-DOCKERFILE
222
+ FROM #{appliance_image_id}
223
+
224
+ COPY #{deb} /tmp/
225
+
226
+ RUN rm -rf /opt/conjur/#{project_name}
227
+ RUN rm -f /opt/conjur/etc/#{project_name}.conf
228
+ RUN rm -f /usr/local/bin/conjur-#{project_name}
229
+
230
+ RUN dpkg --force all --purge conjur-#{project_name} || true
231
+ RUN dpkg --install /tmp/#{deb}
232
+
233
+ RUN touch /etc/service/conjur/down
234
+ DOCKERFILE
235
+ Dir.mktmpdir do |tmpdir|
236
+ tmpfile = Tempfile.new('Dockerfile', tmpdir)
237
+ File.write(tmpfile, dockerfile)
238
+ dockerfile_name = File.basename(tmpfile.path)
239
+ tar_cmd = "tar -cvzh -C #{tmpdir} #{dockerfile_name} -C #{Dir.pwd} #{deb}"
240
+ tar = open("| #{tar_cmd}")
241
+ begin
242
+ Docker::Image.build_from_tar(tar, :dockerfile => dockerfile_name, &DebugMixin::DOCKER)
243
+ ensure
244
+ tar.close
245
+ end
246
+ end
224
247
  end
248
+
249
+ appliance_image = build_test_image(appliance_image_id, project_name)
225
250
 
251
+ vendor_dir = File.expand_path("tmp/debify/#{project_name}/vendor", ENV['HOME'])
252
+ dot_bundle_dir = File.expand_path("tmp/debify/#{project_name}/.bundle", ENV['HOME'])
253
+ FileUtils.mkdir_p vendor_dir
254
+ FileUtils.mkdir_p dot_bundle_dir
226
255
  options = {
227
256
  'Image' => appliance_image.id,
228
257
  'Env' => [
229
258
  "CONJUR_AUTHN_LOGIN=admin",
230
- "CONJUR_ENV=production",
259
+ "CONJUR_ENV=appliance",
231
260
  "CONJUR_AUTHN_API_KEY=secret",
232
261
  "CONJUR_ADMIN_PASSWORD=secret",
233
262
  ],
234
263
  'Binds' => [
235
- [ dir, "/src/#{project_name}" ].join(':')
264
+ [ dir, "/src/#{project_name}" ].join(':'),
265
+ [ vendor_dir, "/src/#{project_name}/vendor" ].join(':'),
266
+ [ dot_bundle_dir, "/src/#{project_name}/.bundle" ].join(':')
236
267
  ]
237
268
  }
238
269
 
@@ -265,6 +296,7 @@ command "test" do |c|
265
296
  def command container, *args
266
297
  stdout, stderr, exitcode = container.exec args, &DebugMixin::DOCKER
267
298
  exit_now! "Command failed : #{args.join(' ')}", exitcode unless exitcode == 0
299
+ stdout
268
300
  end
269
301
 
270
302
  begin
@@ -275,33 +307,22 @@ command "test" do |c|
275
307
  end
276
308
  container.start
277
309
 
278
- DebugMixin.debug_write "Stopping conjur\n"
279
-
280
- container.exec [ "sv", "stop", "conjur" ], &DebugMixin::DOCKER
281
-
282
- DebugMixin.debug_write "Purging source install of #{project_name}\n"
283
-
284
- command container, "rm", "-rf", "/opt/conjur/#{project_name}"
285
- command container, "rm", "-f", "/opt/conjur/etc/#{project_name}.conf"
286
- command container, "rm", "-f", "/usr/local/bin/conjur-#{project_name}"
287
- container.exec [ "dpkg", "-P", "conjur-#{project_name}" ], &DebugMixin::DOCKER
288
-
289
- DebugMixin.debug_write "Installing #{project_name}\n"
310
+ # Wait for pg/main so that migrations can run
311
+ 30.times do
312
+ stdout, stderr, exitcode = container.exec %w(sv status pg/main), &DebugMixin::DOCKER
313
+ status = stdout.join
314
+ break if exitcode == 0 && status =~ /^run\:/
315
+ sleep 1
316
+ end
290
317
 
291
- command container, "dpkg", "-i", "/src/#{project_name}/conjur-#{project_name}_latest_amd64.deb"
292
318
  command container, "/opt/conjur/evoke/bin/test-install", project_name
293
319
 
294
320
  DebugMixin.debug_write "Starting conjur\n"
295
321
 
322
+ command container, "rm", "/etc/service/conjur/down"
296
323
  command container, "sv", "start", "conjur"
297
324
  wait_for_conjur appliance_image, container
298
325
 
299
- if configure_script
300
- system "./#{configure_script} #{container.id}"
301
- exit_now! "#{configure_script} failed with exit code #{$?.exitstatus}", $?.exitstatus unless $?.exitstatus == 0
302
- wait_for_conjur appliance_image, container
303
- end
304
-
305
326
  system "./#{test_script} #{container.id}"
306
327
  exit_now! "#{test_script} failed with exit code #{$?.exitstatus}", $?.exitstatus unless $?.exitstatus == 0
307
328
  ensure
@@ -1,5 +1,5 @@
1
1
  module Conjur
2
2
  module Debify
3
- VERSION = "0.4.1"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-debify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Gilpin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-13 00:00:00.000000000 Z
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -104,6 +104,7 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - .gitignore
106
106
  - .project
107
+ - CHANGELOG.md
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md