conjur-debify 0.2.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 +7 -0
- data/.gitignore +17 -0
- data/.project +18 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +108 -0
- data/Rakefile +49 -0
- data/bin/debify +5 -0
- data/debify.gemspec +27 -0
- data/example/Gemfile +1 -0
- data/example/Gemfile.lock +8 -0
- data/example/debify.sh +3 -0
- data/example/distrib/postinstall.sh +8 -0
- data/example/test.sh +3 -0
- data/features/debify.feature +15 -0
- data/features/step_definitions/debify_steps.rb +6 -0
- data/features/support/env.rb +19 -0
- data/jenkins.sh +6 -0
- data/lib/conjur/debify.rb +323 -0
- data/lib/conjur/debify/Dockerfile.fpm +17 -0
- data/lib/conjur/debify/version.rb +5 -0
- data/lib/conjur/fpm/Dockerfile +12 -0
- data/lib/conjur/fpm/debify_utils.sh +12 -0
- data/lib/conjur/fpm/package.sh +51 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d727bf95156d23c5fdcc395e95fc6308f459632
|
4
|
+
data.tar.gz: 5783389c1eb795cf8c6ee675ce2d2695867f795c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 536d4fe0a144a7b88f29fe9d8ac5c437bc934cd1a4db2b5cabbf030a6a54185b451e266b3a98bae203651bb9d27561ecb92d161690adc6477902dbe5a339fc51
|
7
|
+
data.tar.gz: 7b0c04adb847da5ab1ad69463ae5c8027059f9c765bf04896160d661e92b4f42e47fe16189e181e38c2d5a36520be9c25e67094e9c9edc9687e77512d7917d62
|
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>debify</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
<nature>com.aptana.projects.webnature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Kevin Gilpin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Debify
|
2
|
+
|
3
|
+
## Build a package
|
4
|
+
|
5
|
+
Builds a Conjur Debian package from a Ruby gem.
|
6
|
+
|
7
|
+
```
|
8
|
+
$ debify help package
|
9
|
+
NAME
|
10
|
+
package - Build a debian package for a project
|
11
|
+
|
12
|
+
SYNOPSIS
|
13
|
+
debify [global options] package [command options] project_name -- <fpm-arguments>
|
14
|
+
|
15
|
+
DESCRIPTION
|
16
|
+
The package is built using fpm (https://github.com/jordansissel/fpm).
|
17
|
+
|
18
|
+
The project directory is required to contain:
|
19
|
+
|
20
|
+
* A Gemfile and Gemfile.lock * A shell script called debify.sh
|
21
|
+
|
22
|
+
debify.sh is invoked by the package build process to create any custom files, other than the project source tree. For example, config files can be
|
23
|
+
created in /opt/conjur/etc.
|
24
|
+
|
25
|
+
The distrib folder in the project source tree is intended to create scripts for package pre-install, post-install etc. The distrib folder is not
|
26
|
+
included in the deb package, so its contents should be copied to the file system or packaged using fpm arguments.
|
27
|
+
|
28
|
+
All arguments to this command which follow the double-dash are propagated to the fpm command.
|
29
|
+
|
30
|
+
COMMAND OPTIONS
|
31
|
+
-d, --dir=arg - Set the current working directory (default: none)
|
32
|
+
-v, --version=arg - Specify the deb version; by default, it's computed from the Git tag (default: none)
|
33
|
+
```
|
34
|
+
|
35
|
+
### Example usage
|
36
|
+
|
37
|
+
```sh-session
|
38
|
+
$ package_name=$(debify package -d example -v 0.0.1 example -- --post-install /distrib/postinstall.sh)
|
39
|
+
$ echo $package_name
|
40
|
+
conjur-example_0.0.1_amd64.deb
|
41
|
+
```
|
42
|
+
|
43
|
+
## Test a package
|
44
|
+
|
45
|
+
```
|
46
|
+
$ debify help test
|
47
|
+
NAME
|
48
|
+
test - Test a Conjur debian package in a Conjur appliance container
|
49
|
+
|
50
|
+
SYNOPSIS
|
51
|
+
debify [global options] test [command options] project-name test-script
|
52
|
+
|
53
|
+
DESCRIPTION
|
54
|
+
First, a Conjur appliance container is created and started. By default, the container image is registry.tld/conjur-appliance-cuke-master. An image tag
|
55
|
+
MUST be supplied. This image is configured with all the CONJUR_ environment variables setup for the local environment (appliance URL, cert path, admin
|
56
|
+
username and password, etc). The project source tree is also mounted into the container, at /src/<project-name>.
|
57
|
+
|
58
|
+
This command then waits for Conjur to initialize and be healthy. It proceeds by installing the conjur-<project-name>_latest_amd64.deb from the project
|
59
|
+
working directory.
|
60
|
+
|
61
|
+
Then the evoke "test-install" command is used to install the test code in the /src/<project-name>. Basically, the development bundle is installed and
|
62
|
+
the database configuration (if any) is setup.
|
63
|
+
|
64
|
+
Next, an optional "configure-script" from the project source tree is run, with the container id as the program argument. This command waits for Conjur
|
65
|
+
to be healthy again.
|
66
|
+
|
67
|
+
Finally, a test script from the project source tree is run, again with the container id as the program argument.
|
68
|
+
|
69
|
+
Then the Conjur container is deleted (use --keep to leave it running).
|
70
|
+
|
71
|
+
COMMAND OPTIONS
|
72
|
+
-c, --configure-script=arg - Shell script to configure the appliance before testing (default: none)
|
73
|
+
-d, --dir=arg - Set the current working directory (default: none)
|
74
|
+
-i, --image=arg - Image name (default: registry.tld/conjur-appliance-cuke-master)
|
75
|
+
-k, --[no-]keep - Keep the Conjur appliance container after the command finishes
|
76
|
+
--[no-]pull - Pull the image, even if it's in the Docker engine already (default: enabled)
|
77
|
+
-t, --image-tag=arg - Image tag, e.g. 4.5-stable, 4.6-stable (default: none)
|
78
|
+
```
|
79
|
+
|
80
|
+
### Example usage
|
81
|
+
|
82
|
+
```sh-session
|
83
|
+
$ debify test -i conjur-appliance-cuke-master --image-tag 4.6-dev --no-pull -d example example test.sh
|
84
|
+
```
|
85
|
+
|
86
|
+
## Installation
|
87
|
+
|
88
|
+
Add this line to your application's Gemfile:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
gem 'debify'
|
92
|
+
```
|
93
|
+
|
94
|
+
And then execute:
|
95
|
+
|
96
|
+
$ bundle
|
97
|
+
|
98
|
+
Or install it yourself as:
|
99
|
+
|
100
|
+
$ gem install debify
|
101
|
+
|
102
|
+
## Contributing
|
103
|
+
|
104
|
+
1. Fork it ( https://github.com/[my-github-username]/debify/fork )
|
105
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
106
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
107
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
108
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
require 'rdoc/task'
|
5
|
+
|
6
|
+
def cucumber?
|
7
|
+
require 'cucumber'
|
8
|
+
require 'cucumber/rake/task'
|
9
|
+
rescue LoadError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::RDocTask.new do |rd|
|
14
|
+
rd.main = "README.rdoc"
|
15
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
16
|
+
rd.title = 'Your application title'
|
17
|
+
end
|
18
|
+
|
19
|
+
spec = eval(File.read('debify.gemspec'))
|
20
|
+
|
21
|
+
Gem::PackageTask.new(spec) do |pkg|
|
22
|
+
end
|
23
|
+
|
24
|
+
if cucumber?
|
25
|
+
CUKE_RESULTS = 'results.html'
|
26
|
+
CLEAN << CUKE_RESULTS
|
27
|
+
|
28
|
+
desc 'Run features'
|
29
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
30
|
+
opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
|
31
|
+
opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
|
32
|
+
t.cucumber_opts = opts
|
33
|
+
t.fork = false
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Run features tagged as work-in-progress (@wip)'
|
37
|
+
Cucumber::Rake::Task.new('features:wip') do |t|
|
38
|
+
tag_opts = ' --tags ~@pending'
|
39
|
+
tag_opts = ' --tags @wip'
|
40
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
|
41
|
+
t.fork = false
|
42
|
+
end
|
43
|
+
|
44
|
+
task :cucumber => :features
|
45
|
+
task 'cucumber:wip' => 'features:wip'
|
46
|
+
task :wip => 'features:wip'
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => [:features]
|
data/bin/debify
ADDED
data/debify.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conjur/debify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conjur-debify"
|
8
|
+
spec.version = Conjur::Debify::VERSION
|
9
|
+
spec.authors = ["Kevin Gilpin"]
|
10
|
+
spec.email = ["kgilpin@conjur.net"]
|
11
|
+
spec.summary = %q{Utility commands to build and package Conjur services as Debian packages}
|
12
|
+
spec.homepage = "https://github.com/conjurinc/debify"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "gli"
|
21
|
+
spec.add_dependency "docker-api"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "cucumber"
|
26
|
+
spec.add_development_dependency "aruba"
|
27
|
+
end
|
data/example/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
source 'https://rubygems.org'
|
data/example/debify.sh
ADDED
data/example/test.sh
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Feature: Packaging
|
2
|
+
|
3
|
+
@announce-output
|
4
|
+
Scenario: 'example' project can be packaged successfully
|
5
|
+
When I run `env DEBUG=true GLI_DEBUG=true debify package -d ../../example -v 0.0.1 example -- --post-install /distrib/postinstall.sh`
|
6
|
+
Then the exit status should be 0
|
7
|
+
And the stdout should contain exactly "conjur-example_0.0.1_amd64.deb"
|
8
|
+
|
9
|
+
@announce-output
|
10
|
+
Scenario: 'example' project can be tested successfully
|
11
|
+
Given I run `env DEBUG=true GLI_DEBUG=true debify package -d ../../example -v 0.0.1 example -- --post-install /distrib/postinstall.sh`
|
12
|
+
And the exit status should be 0
|
13
|
+
When I run `env DEBUG=true GLI_DEBUG=true debify test -t 4.6-stable -d ../../example --no-pull example test.sh`
|
14
|
+
Then the exit status should be 0
|
15
|
+
And the stderr should contain "Test succeeded"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
|
3
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
4
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
5
|
+
|
6
|
+
Aruba.configure do |config|
|
7
|
+
config.exit_timeout = 120
|
8
|
+
end
|
9
|
+
|
10
|
+
Before do
|
11
|
+
# Using "announce" causes massive warnings on 1.9.2
|
12
|
+
@puts = true
|
13
|
+
@original_rubylib = ENV['RUBYLIB']
|
14
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
After do
|
18
|
+
ENV['RUBYLIB'] = @original_rubylib
|
19
|
+
end
|
data/jenkins.sh
ADDED
@@ -0,0 +1,323 @@
|
|
1
|
+
require "conjur/debify/version"
|
2
|
+
require 'docker'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
include GLI::App
|
6
|
+
|
7
|
+
# This is used to turn on DEBUG notices for the test case operation. For instance,
|
8
|
+
# messages from "evoke configure"
|
9
|
+
module DebugMixin
|
10
|
+
DEBUG = ENV['DEBUG']
|
11
|
+
|
12
|
+
def debug *a
|
13
|
+
DebugMixin.debug *a
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.debug *a
|
17
|
+
$stderr.puts *a if DEBUG
|
18
|
+
end
|
19
|
+
|
20
|
+
def debug_write *a
|
21
|
+
DebugMixin.debug_write *a
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.debug_write *a
|
25
|
+
$stderr.write *a if DEBUG
|
26
|
+
end
|
27
|
+
|
28
|
+
# you can give this to various docker methods to print output if debug is on
|
29
|
+
def self.docker_debug *a
|
30
|
+
if a.length == 2 && a[0].is_a?(Symbol)
|
31
|
+
debug a.last
|
32
|
+
else
|
33
|
+
a.each do |line|
|
34
|
+
line = JSON.parse(line)
|
35
|
+
line.keys.each do |k|
|
36
|
+
debug line[k]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
DOCKER = method :docker_debug
|
43
|
+
end
|
44
|
+
|
45
|
+
program_desc 'Utility commands for building and testing Conjur appliance Debian packages'
|
46
|
+
|
47
|
+
version Conjur::Debify::VERSION
|
48
|
+
|
49
|
+
subcommand_option_handling :normal
|
50
|
+
arguments :strict
|
51
|
+
|
52
|
+
desc "Build a debian package for a project"
|
53
|
+
long_desc <<DESC
|
54
|
+
The package is built using fpm (https://github.com/jordansissel/fpm).
|
55
|
+
|
56
|
+
The project directory is required to contain:
|
57
|
+
|
58
|
+
* A Gemfile and Gemfile.lock
|
59
|
+
* A shell script called debify.sh
|
60
|
+
|
61
|
+
debify.sh is invoked by the package build process to create any custom
|
62
|
+
files, other than the project source tree. For example, config files can be
|
63
|
+
created in /opt/conjur/etc.
|
64
|
+
|
65
|
+
The distrib folder in the project source tree is intended to create scripts
|
66
|
+
for package pre-install, post-install etc. The distrib folder is not included
|
67
|
+
in the deb package, so its contents should be copied to the file system or
|
68
|
+
packaged using fpm arguments.
|
69
|
+
|
70
|
+
All arguments to this command which follow the double-dash are propagated to
|
71
|
+
the fpm command.
|
72
|
+
DESC
|
73
|
+
arg_name "project-name -- <fpm-arguments>"
|
74
|
+
command "package" do |c|
|
75
|
+
c.desc "Set the current working directory"
|
76
|
+
c.flag [ :d, "dir" ]
|
77
|
+
|
78
|
+
c.desc "Specify the deb version; by default, it's computed from the Git tag"
|
79
|
+
c.flag [ :v, :version ]
|
80
|
+
|
81
|
+
c.action do |global_options,cmd_options,args|
|
82
|
+
raise "project-name is required" unless project_name = args.shift
|
83
|
+
fpm_args = []
|
84
|
+
if (delimeter = args.shift) == '--'
|
85
|
+
fpm_args = args.dup
|
86
|
+
else
|
87
|
+
raise "Unexpected argument '#{delimiter}'"
|
88
|
+
end
|
89
|
+
|
90
|
+
dir = cmd_options[:dir] || '.'
|
91
|
+
pwd = File.dirname(__FILE__)
|
92
|
+
version = cmd_options[:version]
|
93
|
+
|
94
|
+
fpm_image = Docker::Image.build_from_dir File.expand_path('fpm', File.dirname(__FILE__)), tag: "debify-fpm", &DebugMixin::DOCKER
|
95
|
+
DebugMixin.debug_write "Built base fpm image '#{fpm_image.id}'\n"
|
96
|
+
dir = File.expand_path(dir)
|
97
|
+
Dir.chdir dir do
|
98
|
+
unless version
|
99
|
+
version = `git describe --long --tags --abbrev=7 | sed -e 's/^v//'`.strip
|
100
|
+
raise "No Git version (tag) for project '#{project_name}'" if version.empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
package_name = "conjur-#{project_name}_#{version}_amd64.deb"
|
104
|
+
|
105
|
+
output = StringIO.new
|
106
|
+
Gem::Package::TarWriter.new(output) do |tar|
|
107
|
+
`git ls-files -z`.split("\x0").each do |fname|
|
108
|
+
stat = File.stat(fname)
|
109
|
+
tar.add_file(fname, stat.mode) { |tar_file| tar_file.write(File.read(fname)) }
|
110
|
+
end
|
111
|
+
tar.add_file('Dockerfile', 0640) { |tar_file| tar_file.write File.read(File.expand_path("debify/Dockerfile.fpm", pwd)).gsub("@@image@@", fpm_image.id) }
|
112
|
+
end
|
113
|
+
output.rewind
|
114
|
+
|
115
|
+
image = Docker::Image.build_from_tar output, &DebugMixin::DOCKER
|
116
|
+
|
117
|
+
DebugMixin.debug_write "Built fpm image '#{image.id}' for project #{project_name}\n"
|
118
|
+
|
119
|
+
# Make it under HOME so that Docker can map the volume on MacOS
|
120
|
+
tempdir = File.expand_path((0...50).map { ('a'..'z').to_a[rand(26)] }.join, ENV['HOME'])
|
121
|
+
FileUtils.mkdir tempdir
|
122
|
+
at_exit do
|
123
|
+
FileUtils.rm_rf tempdir
|
124
|
+
end
|
125
|
+
|
126
|
+
options = {
|
127
|
+
'Cmd' => [ project_name, version ] + fpm_args,
|
128
|
+
'Image' => image.id,
|
129
|
+
'Binds' => [
|
130
|
+
[ tempdir, '/dist' ].join(':')
|
131
|
+
]
|
132
|
+
}
|
133
|
+
|
134
|
+
container = Docker::Container.create options
|
135
|
+
begin
|
136
|
+
DebugMixin.debug_write "Packaging #{project_name} in container #{container.id}\n"
|
137
|
+
container.tap(&:start).attach { |stream, chunk| $stderr.puts chunk }
|
138
|
+
status = container.wait
|
139
|
+
raise "Failed to package #{project_name}" unless status['StatusCode'] == 0
|
140
|
+
|
141
|
+
deb_file = nil
|
142
|
+
Dir.chdir(tempdir) do
|
143
|
+
deb_file = Dir["*.deb"]
|
144
|
+
raise "Expected one deb file, got #{deb_file.join(', ')}" unless deb_file.length == 1
|
145
|
+
deb_file = deb_file[0]
|
146
|
+
FileUtils.cp deb_file, dir
|
147
|
+
end
|
148
|
+
FileUtils.ln_sf deb_file, deb_file.gsub(version, "latest")
|
149
|
+
puts File.basename(deb_file)
|
150
|
+
ensure
|
151
|
+
container.delete(force: true)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
desc "Test a Conjur debian package in a Conjur appliance container"
|
158
|
+
long_desc <<DESC
|
159
|
+
First, a Conjur appliance container is created and started. By default, the
|
160
|
+
container image is registry.tld/conjur-appliance-cuke-master. An image tag
|
161
|
+
MUST be supplied. This image is configured with all the CONJUR_ environment
|
162
|
+
variables setup for the local environment (appliance URL, cert path, admin username and
|
163
|
+
password, etc). The project source tree is also mounted into the container, at
|
164
|
+
/src/<project-name>.
|
165
|
+
|
166
|
+
This command then waits for Conjur to initialize and be healthy. It proceeds by
|
167
|
+
installing the conjur-<project-name>_latest_amd64.deb from the project working directory.
|
168
|
+
|
169
|
+
Then the evoke "test-install" command is used to install the test code in the
|
170
|
+
/src/<project-name>. Basically, the development bundle is installed and the database
|
171
|
+
configuration (if any) is setup.
|
172
|
+
|
173
|
+
Next, an optional "configure-script" from the project source tree is run, with the
|
174
|
+
container id as the program argument. This command waits for Conjur to be healthy again.
|
175
|
+
|
176
|
+
Finally, a test script from the project source tree is run, again with the container
|
177
|
+
id as the program argument.
|
178
|
+
|
179
|
+
Then the Conjur container is deleted (use --keep to leave it running).
|
180
|
+
DESC
|
181
|
+
arg_name "project-name test-script"
|
182
|
+
command "test" do |c|
|
183
|
+
c.desc "Set the current working directory"
|
184
|
+
c.flag [ :d, :dir ]
|
185
|
+
|
186
|
+
c.desc "Keep the Conjur appliance container after the command finishes"
|
187
|
+
c.default_value false
|
188
|
+
c.switch [ :k, :keep ]
|
189
|
+
|
190
|
+
c.desc "Image name"
|
191
|
+
c.default_value "registry.tld/conjur-appliance-cuke-master"
|
192
|
+
c.flag [ :i, :image ]
|
193
|
+
|
194
|
+
c.desc "Image tag, e.g. 4.5-stable, 4.6-stable"
|
195
|
+
c.flag [ :t, "image-tag"]
|
196
|
+
|
197
|
+
c.desc "Pull the image, even if it's in the Docker engine already"
|
198
|
+
c.default_value true
|
199
|
+
c.switch [ :pull ]
|
200
|
+
|
201
|
+
c.desc "Shell script to configure the appliance before testing"
|
202
|
+
c.flag [ :c, "configure-script" ]
|
203
|
+
|
204
|
+
c.action do |global_options,cmd_options,args|
|
205
|
+
raise "project-name is required" unless project_name = args.shift
|
206
|
+
raise "test-script is required" unless test_script = args.shift
|
207
|
+
|
208
|
+
dir = cmd_options[:dir] || '.'
|
209
|
+
dir = File.expand_path(dir)
|
210
|
+
|
211
|
+
raise "Directory #{dir} does not exist or is not a directory" unless File.directory?(dir)
|
212
|
+
raise "Directory #{dir} does not contain a .deb file" unless Dir["#{dir}/*.deb"].length >= 1
|
213
|
+
|
214
|
+
Dir.chdir dir do
|
215
|
+
image_tag = cmd_options["image-tag"] or raise "image-tag is required"
|
216
|
+
appliance_image_id = [ cmd_options[:image], image_tag ].join(":")
|
217
|
+
configure_script = cmd_options["configure-script"]
|
218
|
+
|
219
|
+
raise "#{configure_script} does not exist or is not a file" unless configure_script.nil? || File.file?(configure_script)
|
220
|
+
raise "#{test_script} does not exist or is not a file" unless File.file?(test_script)
|
221
|
+
|
222
|
+
appliance_image = if cmd_options[:pull]
|
223
|
+
Docker::Image.create 'fromImage' => appliance_image_id, &DebugMixin::DOCKER
|
224
|
+
else
|
225
|
+
Docker::Image.get(appliance_image_id)
|
226
|
+
end
|
227
|
+
|
228
|
+
options = {
|
229
|
+
'Image' => appliance_image.id,
|
230
|
+
'Env' => [
|
231
|
+
"CONJUR_APPLIANCE_URL=https://localhost/api",
|
232
|
+
"CONJUR_ACCOUNT=cucumber",
|
233
|
+
"CONJUR_CERT_FILE=/opt/conjur/etc/ssl/ca.pem",
|
234
|
+
"CONJUR_AUTHN_LOGIN=admin",
|
235
|
+
"CONJUR_ENV=production",
|
236
|
+
"CONJUR_AUTHN_API_KEY=secret",
|
237
|
+
"CONJUR_ADMIN_PASSWORD=secret",
|
238
|
+
],
|
239
|
+
'Binds' => [
|
240
|
+
[ dir, "/src/#{project_name}" ].join(':')
|
241
|
+
]
|
242
|
+
}
|
243
|
+
|
244
|
+
container = Docker::Container.create(options)
|
245
|
+
|
246
|
+
def wait_for_conjur appliance_image, container
|
247
|
+
wait_options = {
|
248
|
+
'Image' => appliance_image.id,
|
249
|
+
'Entrypoint' => '/opt/conjur/evoke/bin/wait_for_conjur',
|
250
|
+
'HostConfig' => {
|
251
|
+
'Links' => [
|
252
|
+
[ container.id, 'conjur' ].join(":")
|
253
|
+
]
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
wait_container = Docker::Container.create wait_options
|
258
|
+
begin
|
259
|
+
spawn("docker logs -f #{wait_container.id}", [ :out, :err ] => $stderr).tap do |pid|
|
260
|
+
Process.detach pid
|
261
|
+
end
|
262
|
+
wait_container.start
|
263
|
+
status = wait_container.wait
|
264
|
+
raise "wait_for_conjur failed" unless status['StatusCode'] == 0
|
265
|
+
ensure
|
266
|
+
wait_container.delete(force: true)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
begin
|
271
|
+
DebugMixin.debug_write "Testing #{project_name} in container #{container.id}\n"
|
272
|
+
spawn("docker logs -f #{container.id}", [ :out, :err ] => $stderr).tap do |pid|
|
273
|
+
Process.detach pid
|
274
|
+
end
|
275
|
+
container.start
|
276
|
+
|
277
|
+
DebugMixin.debug_write "Waiting for Conjur\n"
|
278
|
+
wait_for_conjur appliance_image, container
|
279
|
+
|
280
|
+
DebugMixin.debug_write "Installing #{project_name}\n"
|
281
|
+
|
282
|
+
stdout, stderr, exitcode = container.exec [ "dpkg", "-i", "/src/#{project_name}/conjur-#{project_name}_latest_amd64.deb" ], &DebugMixin::DOCKER
|
283
|
+
exit_now! "deb install failed", exitcode unless exitcode == 0
|
284
|
+
stdout, stderr, exitcode = container.exec [ "/opt/conjur/evoke/bin/test-install", project_name ], &DebugMixin::DOCKER
|
285
|
+
exit_now! "test-install failed", exitcode unless exitcode == 0
|
286
|
+
|
287
|
+
wait_for_conjur appliance_image, container
|
288
|
+
|
289
|
+
if configure_script
|
290
|
+
system "./#{configure_script} #{container.id}"
|
291
|
+
exit_now! "#{configure_script} failed with exit code #{$?.exitstatus}", $?.exitstatus unless $?.exitstatus == 0
|
292
|
+
wait_for_conjur appliance_image, container
|
293
|
+
end
|
294
|
+
|
295
|
+
system "./#{test_script} #{container.id}"
|
296
|
+
exit_now! "#{test_script} failed with exit code #{$?.exitstatus}", $?.exitstatus unless $?.exitstatus == 0
|
297
|
+
ensure
|
298
|
+
container.delete(force: true) unless cmd_options[:keep]
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
pre do |global,command,options,args|
|
305
|
+
# Pre logic here
|
306
|
+
# Return true to proceed; false to abort and not call the
|
307
|
+
# chosen command
|
308
|
+
# Use skips_pre before a command to skip this block
|
309
|
+
# on that command only
|
310
|
+
true
|
311
|
+
end
|
312
|
+
|
313
|
+
post do |global,command,options,args|
|
314
|
+
# Post logic here
|
315
|
+
# Use skips_post before a command to skip this
|
316
|
+
# block on that command only
|
317
|
+
end
|
318
|
+
|
319
|
+
on_error do |exception|
|
320
|
+
# Error logic here
|
321
|
+
# return false to skip default error handling
|
322
|
+
true
|
323
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
FROM @@image@@
|
2
|
+
|
3
|
+
RUN mkdir -p /src/opt/conjur/project
|
4
|
+
|
5
|
+
WORKDIR /src/opt/conjur/project
|
6
|
+
|
7
|
+
COPY Gemfile ./
|
8
|
+
COPY Gemfile.lock ./
|
9
|
+
|
10
|
+
RUN bundle --deployment --without "test development"
|
11
|
+
RUN mkdir -p .bundle
|
12
|
+
RUN cp /usr/local/bundle/config .bundle/config
|
13
|
+
|
14
|
+
COPY . .
|
15
|
+
ADD debify.sh /
|
16
|
+
|
17
|
+
WORKDIR /src
|
@@ -0,0 +1,12 @@
|
|
1
|
+
function bundle_clean() {
|
2
|
+
chmod og+r -R vendor/bundle # some gems have broken perms
|
3
|
+
|
4
|
+
gem install bundler --no-rdoc --no-ri --install-dir ./vendor/bundle/ruby/2.0.0
|
5
|
+
|
6
|
+
# some cleanup
|
7
|
+
rm -rf vendor/bundle/ruby/2.0.0/cache
|
8
|
+
rm -rf vendor/bundle/ruby/2.0.0/gems/*/{test,spec,examples,example,contrib,doc,ext,sample}
|
9
|
+
|
10
|
+
# Ruby 2.0 is ruby2.0 in ubuntu, fix shebangs
|
11
|
+
sed -i -e '1 c #!/usr/bin/env ruby2.0' vendor/bundle/ruby/2.0.0/bin/*
|
12
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/bin/bash -ex
|
2
|
+
|
3
|
+
project_name=$1
|
4
|
+
shift
|
5
|
+
version=$1
|
6
|
+
shift
|
7
|
+
|
8
|
+
if [ -z "$project_name" ]; then
|
9
|
+
echo Project name argument is required
|
10
|
+
exit 1
|
11
|
+
fi
|
12
|
+
if [ -z "$version" ]; then
|
13
|
+
echo Version argument is required
|
14
|
+
exit 1
|
15
|
+
fi
|
16
|
+
|
17
|
+
package_name=conjur-"$project_name"_"$version"_amd64.deb
|
18
|
+
|
19
|
+
echo Building $package_name
|
20
|
+
|
21
|
+
mv /src/opt/conjur/project /src/opt/conjur/$project_name
|
22
|
+
|
23
|
+
cd /src/opt/conjur/$project_name
|
24
|
+
|
25
|
+
source /debify_utils.sh
|
26
|
+
bundle_clean
|
27
|
+
|
28
|
+
cd /src
|
29
|
+
|
30
|
+
mkdir -p opt/conjur/etc
|
31
|
+
|
32
|
+
/debify.sh
|
33
|
+
|
34
|
+
[ -d opt/conjur/"$project_name"/distrib ] && mv opt/conjur/"$project_name"/distrib /
|
35
|
+
|
36
|
+
fpm -s dir -t deb -n conjur-$project_name -v $version -C . \
|
37
|
+
--maintainer "Conjur Inc." \
|
38
|
+
--vendor "Conjur Inc." \
|
39
|
+
--license "Proprietary" \
|
40
|
+
--url "https://www.conjur.net" \
|
41
|
+
--deb-no-default-config-files \
|
42
|
+
--config-files opt/conjur/etc \
|
43
|
+
--deb-user conjur \
|
44
|
+
--deb-group conjur \
|
45
|
+
--depends ruby2.0 \
|
46
|
+
--description "Conjur $project_name service" \
|
47
|
+
"$@"
|
48
|
+
|
49
|
+
ls -al *.deb
|
50
|
+
|
51
|
+
cp *.deb /dist/
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conjur-debify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Gilpin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: docker-api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cucumber
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- kgilpin@conjur.net
|
100
|
+
executables:
|
101
|
+
- debify
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- .project
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/debify
|
112
|
+
- debify.gemspec
|
113
|
+
- example/Gemfile
|
114
|
+
- example/Gemfile.lock
|
115
|
+
- example/debify.sh
|
116
|
+
- example/distrib/postinstall.sh
|
117
|
+
- example/test.sh
|
118
|
+
- features/debify.feature
|
119
|
+
- features/step_definitions/debify_steps.rb
|
120
|
+
- features/support/env.rb
|
121
|
+
- jenkins.sh
|
122
|
+
- lib/conjur/debify.rb
|
123
|
+
- lib/conjur/debify/Dockerfile.fpm
|
124
|
+
- lib/conjur/debify/version.rb
|
125
|
+
- lib/conjur/fpm/Dockerfile
|
126
|
+
- lib/conjur/fpm/debify_utils.sh
|
127
|
+
- lib/conjur/fpm/package.sh
|
128
|
+
homepage: https://github.com/conjurinc/debify
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.0.14.1
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Utility commands to build and package Conjur services as Debian packages
|
152
|
+
test_files:
|
153
|
+
- features/debify.feature
|
154
|
+
- features/step_definitions/debify_steps.rb
|
155
|
+
- features/support/env.rb
|
156
|
+
has_rdoc:
|