gordon 0.0.11 → 0.0.12
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/README.md +22 -7
- data/gordon.gemspec +0 -1
- data/lib/gordon/application/templates/java_web_app.rb +6 -4
- data/lib/gordon/application/templates/ruby_standalone_app.rb +4 -6
- data/lib/gordon/application/templates/ruby_web_app.rb +4 -6
- data/lib/gordon/application/types.rb +1 -1
- data/lib/gordon/cli.rb +15 -11
- data/lib/gordon/cooker.rb +4 -4
- data/lib/gordon/cookery/application_user.rb +1 -1
- data/lib/gordon/cookery/common.rb +7 -6
- data/lib/gordon/cookery/dependency_resolver.rb +8 -2
- data/lib/gordon/cookery/http_server.rb +3 -1
- data/lib/gordon/cookery/init.rb +5 -3
- data/lib/gordon/cookery/java/common.rb +0 -1
- data/lib/gordon/cookery/ruby/common.rb +0 -8
- data/lib/gordon/cookery/standalone.rb +3 -1
- data/lib/gordon/cookery/web_server.rb +3 -1
- data/lib/gordon/env_vars.rb +11 -8
- data/lib/gordon/exceptions.rb +10 -0
- data/lib/gordon/options.rb +3 -4
- data/lib/gordon/process.rb +5 -1
- data/lib/gordon/recipe.rb +1 -1
- data/lib/gordon/skeleton/types.rb +7 -0
- data/lib/gordon/version.rb +1 -1
- data/lib/gordon.rb +1 -0
- data/spec/gordon/application/types_spec.rb +48 -0
- data/spec/gordon/cli_spec.rb +63 -3
- data/spec/gordon/cooker_spec.rb +81 -4
- data/spec/gordon/cookery/application_user_spec.rb +59 -2
- data/spec/gordon/cookery/common_spec.rb +72 -5
- data/spec/gordon/cookery/dependency_resolver_spec.rb +58 -1
- data/spec/gordon/cookery/http_server_spec.rb +26 -1
- data/spec/gordon/cookery/init_spec.rb +52 -2
- data/spec/gordon/cookery/java/common_spec.rb +6 -2
- data/spec/gordon/cookery/java/web_app_spec.rb +33 -1
- data/spec/gordon/cookery/ruby/common_spec.rb +6 -2
- data/spec/gordon/cookery/standalone_spec.rb +25 -1
- data/spec/gordon/cookery/web_server_spec.rb +33 -0
- data/spec/gordon/env_vars_spec.rb +14 -11
- data/spec/gordon/factory_spec.rb +15 -1
- data/spec/gordon/options_spec.rb +1 -1
- data/spec/gordon/process_spec.rb +18 -1
- data/spec/gordon/recipe_spec.rb +13 -2
- data/spec/gordon/skeleton/types_spec.rb +147 -7
- metadata +8 -17
data/spec/gordon/cli_spec.rb
CHANGED
@@ -2,10 +2,70 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Gordon::CLI do
|
4
4
|
describe 'running a recipe' do
|
5
|
-
|
5
|
+
it 'cooks a recipe based on options' do
|
6
|
+
options = instance_double Gordon::Options
|
7
|
+
expect(options).to receive(:app_source=).with(Dir.pwd)
|
8
|
+
expect(options).to receive(:output_dir=).with(Dir.pwd)
|
9
|
+
expect(Gordon::Options).to receive(:new).and_return(options)
|
10
|
+
|
11
|
+
recipe = instance_double Gordon::Recipe
|
12
|
+
expect(Gordon::Recipe).to receive(:new).with(options).and_return(recipe)
|
13
|
+
|
14
|
+
cooker = instance_double Gordon::Cooker
|
15
|
+
expect(cooker).to receive(:cook)
|
16
|
+
expect(Gordon::Cooker).to receive(:new).with(recipe).and_return(cooker)
|
17
|
+
|
18
|
+
described_class.run
|
19
|
+
end
|
6
20
|
end
|
7
21
|
|
8
|
-
describe '
|
9
|
-
|
22
|
+
describe 'parsing options' do
|
23
|
+
let(:options) { instance_double Gordon::Options }
|
24
|
+
|
25
|
+
let(:options_map) do
|
26
|
+
[
|
27
|
+
[ %w(-N --app-name), "gordon" ],
|
28
|
+
[ %w(-D --app-description), "a packager" ],
|
29
|
+
[ %w(-G --app-homepage), "https://github.com/salizzar/gordon" ],
|
30
|
+
[ %w(-V --app-version), Gordon::VERSION ],
|
31
|
+
[ %w(-S --app-source), "." ],
|
32
|
+
[ %w(-T --app-type), "ruby_web_app" ],
|
33
|
+
[ %w(-X --runtime-name), "ruby" ],
|
34
|
+
[ %w(-R --runtime-version), "2.2.0" ],
|
35
|
+
[ %w(-H --http-server-type), "nginx" ],
|
36
|
+
[ %w(-W --web-server-type), "unicorn" ],
|
37
|
+
[ %w(-I --init-type), "systemd" ],
|
38
|
+
[ %w(-P --package-type), "rpm" ],
|
39
|
+
[ %w(-O --output-dir), "pkg" ],
|
40
|
+
[ %w(-d --debug), true ],
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:abbreviated) do
|
45
|
+
options_map.map { |item| [ item.first.first, item.last ] }
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:detailed) do
|
49
|
+
options_map.map { |item| [ item.first.last, item.last ] }
|
50
|
+
end
|
51
|
+
|
52
|
+
before :each do
|
53
|
+
options_map.each do |item|
|
54
|
+
attr = item.first.last.gsub(/^--/, '').tr('-', '_')
|
55
|
+
|
56
|
+
expect(options).to receive("#{attr}=").with(item.last)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'maps abbreviated options' do
|
61
|
+
parser = described_class.create_option_parser(options)
|
62
|
+
parser.parse!(abbreviated.flatten)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'maps detailed options' do
|
66
|
+
parser = described_class.create_option_parser(options)
|
67
|
+
parser.parse!(detailed.flatten)
|
68
|
+
end
|
10
69
|
end
|
11
70
|
end
|
71
|
+
|
data/spec/gordon/cooker_spec.rb
CHANGED
@@ -1,13 +1,90 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cooker do
|
4
|
+
let(:options) do
|
5
|
+
attrs = {
|
6
|
+
app_type: "web",
|
7
|
+
app_name: "gordon",
|
8
|
+
app_description: "a packager",
|
9
|
+
app_homepage: "https://github.com/salizzar/gordon",
|
10
|
+
app_version: Gordon::VERSION,
|
11
|
+
app_source: ".",
|
12
|
+
runtime_name: "ruby",
|
13
|
+
runtime_version: "2.2.0",
|
14
|
+
http_server_type: "nginx",
|
15
|
+
web_server_type: "unicorn",
|
16
|
+
init_type: "systemd",
|
17
|
+
package_type: "rpm",
|
18
|
+
output_dir: "pkg",
|
19
|
+
debug: true,
|
20
|
+
}
|
21
|
+
|
22
|
+
instance_double(Gordon::Options, attrs)
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:recipe) do
|
26
|
+
instance_double(Gordon::Recipe, options: options, application_template_path: '/a/path')
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:env_vars) do
|
30
|
+
Gordon::EnvVars.from_cook(options)
|
31
|
+
end
|
32
|
+
|
33
|
+
subject { described_class.new(recipe) }
|
34
|
+
|
35
|
+
before :each do
|
36
|
+
expect(subject).to receive(:debug)
|
37
|
+
end
|
38
|
+
|
4
39
|
describe 'cooking a package' do
|
5
|
-
|
6
|
-
|
40
|
+
it 'cleans fpm-cookery working directory' do
|
41
|
+
clean_command = %W{
|
42
|
+
#{env_vars.join " "}
|
43
|
+
fpm-cook
|
44
|
+
--debug
|
45
|
+
--target
|
46
|
+
#{options.package_type}
|
47
|
+
--pkg-dir
|
48
|
+
#{File.expand_path(options.output_dir)}
|
49
|
+
--cache-dir
|
50
|
+
#{File.expand_path(described_class::FPM_COOKERY_CACHE_DIR)}
|
51
|
+
--tmp-root
|
52
|
+
#{File.expand_path(described_class::FPM_COOKERY_BUILD_DIR)}
|
53
|
+
--no-deps
|
54
|
+
clean
|
55
|
+
#{recipe.application_template_path}
|
56
|
+
}
|
57
|
+
|
58
|
+
expect(Gordon::Process).to receive(:run).with(clean_command.join " ")
|
59
|
+
|
60
|
+
expect(subject).to receive(:package)
|
61
|
+
|
62
|
+
subject.cook
|
7
63
|
end
|
8
64
|
|
9
|
-
|
10
|
-
|
65
|
+
it 'packages calling fpm-cookery' do
|
66
|
+
package_command = %W{
|
67
|
+
#{env_vars.join " "}
|
68
|
+
fpm-cook
|
69
|
+
--debug
|
70
|
+
--target
|
71
|
+
#{options.package_type}
|
72
|
+
--pkg-dir
|
73
|
+
#{File.expand_path(options.output_dir)}
|
74
|
+
--cache-dir
|
75
|
+
#{File.expand_path(described_class::FPM_COOKERY_CACHE_DIR)}
|
76
|
+
--tmp-root
|
77
|
+
#{File.expand_path(described_class::FPM_COOKERY_BUILD_DIR)}
|
78
|
+
--no-deps
|
79
|
+
package
|
80
|
+
#{recipe.application_template_path}
|
81
|
+
}
|
82
|
+
|
83
|
+
expect(Gordon::Process).to receive(:run).with(package_command.join " ")
|
84
|
+
|
85
|
+
expect(subject).to receive(:clean)
|
86
|
+
|
87
|
+
subject.cook
|
11
88
|
end
|
12
89
|
end
|
13
90
|
end
|
@@ -1,11 +1,68 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::ApplicationUser do
|
4
|
+
subject do
|
5
|
+
class MyApplicationUser
|
6
|
+
include Gordon::Cookery::ApplicationUser
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:app_name) { "gordon" }
|
11
|
+
let(:app_description) { "a packager" }
|
12
|
+
let(:build_path) { 'tmp-build' }
|
13
|
+
let(:preinstall_file_name) { '.gordon-before-install' }
|
14
|
+
let(:postinstall_file_name) { '.gordon-after-install' }
|
15
|
+
let(:preinstall_path) { File.join(build_path, preinstall_file_name) }
|
16
|
+
let(:postinstall_path) { File.join(build_path, preinstall_file_name) }
|
17
|
+
let(:file) { instance_double File }
|
18
|
+
let(:env_vars) { instance_double Gordon::EnvVars, app_name: app_name, app_description: app_description }
|
19
|
+
let(:home_path) { '/usr/share/nginx/html' }
|
20
|
+
|
4
21
|
describe 'creating user and group' do
|
5
|
-
|
22
|
+
it 'installs script to create user on system' do
|
23
|
+
expect(subject).to receive(:builddir).with(preinstall_file_name).and_return(preinstall_path)
|
24
|
+
|
25
|
+
expect(File).to receive(:open).with(preinstall_path, 'w', 0755).and_yield(file)
|
26
|
+
allow(file).to receive(:path).and_return(preinstall_path)
|
27
|
+
|
28
|
+
bash = <<-__BASH
|
29
|
+
#!/bin/sh
|
30
|
+
|
31
|
+
set -e
|
32
|
+
|
33
|
+
/usr/bin/getent group #{env_vars.app_name} >/dev/null || /usr/sbin/groupadd --system #{env_vars.app_name};
|
34
|
+
/usr/bin/getent passwd #{env_vars.app_name} >/dev/null || /usr/sbin/useradd --system --gid #{env_vars.app_name} --home-dir #{home_path} --shell /sbin/nologin --comment "#{env_vars.app_description}" #{env_vars.app_name} >/dev/null || :;
|
35
|
+
__BASH
|
36
|
+
|
37
|
+
expect(file).to receive(:write).with(bash)
|
38
|
+
|
39
|
+
expect(subject.class).to receive(:pre_install).with(File.expand_path(file.path))
|
40
|
+
|
41
|
+
subject.create_user_and_group(env_vars, home_path)
|
42
|
+
end
|
6
43
|
end
|
7
44
|
|
8
45
|
describe 'setting user permissions' do
|
9
|
-
|
46
|
+
it 'install script to recursively own all files from home path' do
|
47
|
+
expect(subject).to receive(:builddir).with(postinstall_file_name).and_return(postinstall_path)
|
48
|
+
|
49
|
+
expect(File).to receive(:open).with(postinstall_path, 'w', 0755).and_yield(file)
|
50
|
+
allow(file).to receive(:path).and_return(postinstall_path)
|
51
|
+
|
52
|
+
bash = <<-__BASH
|
53
|
+
#!/bin/sh
|
54
|
+
|
55
|
+
set -e
|
56
|
+
|
57
|
+
/usr/bin/chown -R #{env_vars.app_name}:#{env_vars.app_name} #{home_path}
|
58
|
+
__BASH
|
59
|
+
|
60
|
+
expect(file).to receive(:write).with(bash)
|
61
|
+
|
62
|
+
expect(subject.class).to receive(:post_install).with(File.expand_path(file.path))
|
63
|
+
|
64
|
+
subject.setup_user_permissions(env_vars, home_path)
|
65
|
+
end
|
10
66
|
end
|
11
67
|
end
|
68
|
+
|
@@ -1,16 +1,83 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::Common do
|
4
|
+
subject do
|
5
|
+
class MyCommonExample
|
6
|
+
include Gordon::Cookery::Common
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
4
10
|
describe 'getting skeleton path from type' do
|
5
|
-
|
11
|
+
let(:env_vars) { instance_double Gordon::EnvVars, app_name: 'gordon' }
|
12
|
+
let(:skeleton) { instance_double 'Gordon::Skeleton::Types::Anything', get_default_path: '/a/path' }
|
13
|
+
let(:type) { :anything }
|
14
|
+
|
15
|
+
it 'responds from class' do
|
16
|
+
expect(subject.class).to respond_to(:get_skeleton_path_from_type)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'returning based on app name' do
|
20
|
+
before :each do
|
21
|
+
expect(Gordon::Skeleton::Factory).to receive(:create).with(type).and_return(skeleton)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns skeleton path without app name' do
|
25
|
+
expect(skeleton).to receive(:requires_app_name?).and_return(false)
|
26
|
+
expect(skeleton).to receive(:path).with('').and_return('/a/path')
|
27
|
+
|
28
|
+
result = subject.get_skeleton_path_from_type(env_vars, :anything)
|
29
|
+
|
30
|
+
expect(result).to eq('/a/path')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns skeleton path with app name' do
|
34
|
+
expect(skeleton).to receive(:requires_app_name?).and_return(true)
|
35
|
+
expect(skeleton).to receive(:path).with('gordon').and_return('/a/path/gordon')
|
36
|
+
|
37
|
+
result = subject.get_skeleton_path_from_type(env_vars, type)
|
38
|
+
|
39
|
+
expect(result).to eq('/a/path/gordon')
|
40
|
+
end
|
41
|
+
end
|
6
42
|
end
|
7
43
|
|
8
44
|
describe 'getting all files with blacklist' do
|
9
|
-
|
10
|
-
|
45
|
+
it 'returns all files except that are blacklisted on default map plus custom' do
|
46
|
+
files = %w{
|
47
|
+
.
|
48
|
+
..
|
49
|
+
.bundle
|
50
|
+
.git
|
51
|
+
.gitignore
|
52
|
+
.pki
|
53
|
+
Procfile
|
54
|
+
Vagrantfile
|
55
|
+
app
|
56
|
+
config
|
57
|
+
cruise-output
|
58
|
+
db
|
59
|
+
lib
|
60
|
+
log
|
61
|
+
public
|
62
|
+
spec
|
63
|
+
tmp
|
64
|
+
}
|
65
|
+
|
66
|
+
expected = %w{
|
67
|
+
.bundle
|
68
|
+
Procfile
|
69
|
+
app
|
70
|
+
config
|
71
|
+
db
|
72
|
+
lib
|
73
|
+
public
|
74
|
+
}
|
75
|
+
|
76
|
+
expect(Dir).to receive(:[]).with('{*,.*}').and_return(files)
|
11
77
|
|
12
|
-
|
13
|
-
|
78
|
+
result = subject.all_files_except_blacklisted(%w(log spec tmp))
|
79
|
+
expect(result).to eq(expected)
|
80
|
+
end
|
14
81
|
end
|
15
82
|
end
|
16
83
|
|
@@ -1,8 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::DependencyResolver do
|
4
|
+
subject do
|
5
|
+
class MyDependencyResolver
|
6
|
+
include Gordon::Cookery::DependencyResolver
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:env_vars) { instance_double Gordon::EnvVars }
|
11
|
+
|
4
12
|
describe 'resolving dependencies' do
|
5
|
-
|
13
|
+
context 'given a ruby app' do
|
14
|
+
it 'returns all dependencies for web' do
|
15
|
+
expect(env_vars).to receive(:app_type).and_return("ruby_web_app")
|
16
|
+
expect(env_vars).to receive(:runtime_version).and_return("2.2.0")
|
17
|
+
allow(env_vars).to receive(:http_server_type).and_return("apache")
|
18
|
+
expect(env_vars).to receive(:web_server_type).and_return("")
|
19
|
+
allow(env_vars).to receive(:init_type).and_return("systemd")
|
20
|
+
|
21
|
+
expected = [
|
22
|
+
"ruby = 2.2.0",
|
23
|
+
"httpd",
|
24
|
+
"systemd",
|
25
|
+
]
|
26
|
+
|
27
|
+
expect(subject.resolve_dependencies(env_vars)).to eq(expected)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns all dependencies for standalone' do
|
31
|
+
expect(env_vars).to receive(:app_type).and_return("ruby_standalone_app")
|
32
|
+
expect(env_vars).to receive(:runtime_version).and_return("2.1.5")
|
33
|
+
expect(env_vars).to receive(:http_server_type).and_return("")
|
34
|
+
expect(env_vars).to receive(:web_server_type).and_return("")
|
35
|
+
allow(env_vars).to receive(:init_type).and_return("systemd")
|
36
|
+
|
37
|
+
expected = [
|
38
|
+
"ruby = 2.1.5",
|
39
|
+
"systemd",
|
40
|
+
]
|
41
|
+
|
42
|
+
expect(subject.resolve_dependencies(env_vars)).to eq(expected)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'given a java standalone app' do
|
47
|
+
it 'returns all dependencies for web' do
|
48
|
+
expect(env_vars).to receive(:app_type).and_return("java_web_app")
|
49
|
+
allow(env_vars).to receive(:http_server_type).and_return("apache")
|
50
|
+
expect(env_vars).to receive(:runtime_version).and_return("1.7.0_60")
|
51
|
+
allow(env_vars).to receive(:web_server_type).and_return("tomcat")
|
52
|
+
expect(env_vars).to receive(:init_type).and_return("")
|
53
|
+
|
54
|
+
expected = [
|
55
|
+
"jre1.7.0_60",
|
56
|
+
"httpd",
|
57
|
+
"tomcat",
|
58
|
+
]
|
59
|
+
|
60
|
+
expect(subject.resolve_dependencies(env_vars)).to eq(expected)
|
61
|
+
end
|
62
|
+
end
|
6
63
|
end
|
7
64
|
end
|
8
65
|
|
@@ -1,8 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::HttpServer do
|
4
|
+
subject do
|
5
|
+
class MyHttpServer
|
6
|
+
include Gordon::Cookery::HttpServer
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:app_name) { "gordon" }
|
11
|
+
let(:http_server_type) { :apache }
|
12
|
+
let(:env_vars) { double Gordon::EnvVars, app_name: app_name, http_server_type: http_server_type }
|
13
|
+
let(:skeleton) { Gordon::Skeleton::Types::Apache.new }
|
14
|
+
let(:all_files) { %w(index.php pimp_my_system.php) }
|
15
|
+
let(:blacklist) { %w(.git) }
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
expect(Gordon::Skeleton::Types::Apache).to receive(:new).and_return(skeleton)
|
19
|
+
end
|
20
|
+
|
4
21
|
describe 'installing files' do
|
5
|
-
|
22
|
+
it 'install files based on http server path' do
|
23
|
+
expect(subject).to receive(:all_files_except_blacklisted).with(blacklist).and_return(all_files)
|
24
|
+
|
25
|
+
installer = double 'a path helper'
|
26
|
+
expect(subject).to receive(:root).with(skeleton.path).and_return(installer)
|
27
|
+
expect(installer).to receive(:install).with(all_files)
|
28
|
+
|
29
|
+
subject.install_http_server_files(env_vars, blacklist)
|
30
|
+
end
|
6
31
|
end
|
7
32
|
end
|
8
33
|
|
@@ -1,11 +1,61 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::Init do
|
4
|
+
subject do
|
5
|
+
class MyInit
|
6
|
+
include Gordon::Cookery::Init
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:app_name) { "gordon" }
|
11
|
+
let(:init_type) { :systemd }
|
12
|
+
let(:build_path) { '/tmp/gordon/tmp-build/systemd' }
|
13
|
+
let(:skeleton) { Gordon::Skeleton::Types::Systemd.new }
|
14
|
+
let(:env_vars) { instance_double Gordon::EnvVars, app_name: app_name, init_type: init_type }
|
15
|
+
|
16
|
+
before :each do
|
17
|
+
expect(subject).to receive(:builddir).with(env_vars.init_type).and_return(build_path)
|
18
|
+
|
19
|
+
expect(Gordon::Skeleton::Types::Systemd).to receive(:new).and_return(skeleton)
|
20
|
+
end
|
21
|
+
|
4
22
|
describe 'creating init files' do
|
5
|
-
|
23
|
+
it 'creates init calling foreman' do
|
24
|
+
command = %W{
|
25
|
+
foreman
|
26
|
+
export
|
27
|
+
--procfile
|
28
|
+
Procfile
|
29
|
+
--root
|
30
|
+
#{skeleton.path}
|
31
|
+
--app
|
32
|
+
#{env_vars.app_name}
|
33
|
+
--user
|
34
|
+
#{env_vars.app_name}
|
35
|
+
#{env_vars.init_type}
|
36
|
+
#{build_path}
|
37
|
+
}
|
38
|
+
|
39
|
+
expect(subject).to receive(:safesystem).with(command.join " ")
|
40
|
+
|
41
|
+
subject.create_init(env_vars, init_type)
|
42
|
+
end
|
6
43
|
end
|
7
44
|
|
8
45
|
describe 'installing init files' do
|
9
|
-
|
46
|
+
it 'installs all generated files' do
|
47
|
+
files = %w(app.target app.service app-web-1.service).map do |file|
|
48
|
+
File.join(build_path, file)
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(Dir).to receive(:[]).with("#{build_path}/*").and_return(files)
|
52
|
+
|
53
|
+
installer = double 'a path helper'
|
54
|
+
expect(subject).to receive(:root).with(skeleton.path).and_return(installer)
|
55
|
+
expect(installer).to receive(:install).with(files)
|
56
|
+
|
57
|
+
subject.install_init(env_vars)
|
58
|
+
end
|
10
59
|
end
|
11
60
|
end
|
61
|
+
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::Java::Common do
|
4
|
-
describe 'default blacklist
|
5
|
-
|
4
|
+
describe 'default blacklist' do
|
5
|
+
it 'maps common files' do
|
6
|
+
expected = %w()
|
7
|
+
|
8
|
+
expect(described_class::JAVA_BLACKLIST_FILES).to eq(expected)
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
@@ -1,8 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::Java::WebApp do
|
4
|
+
subject do
|
5
|
+
class MyJavaWebApp
|
6
|
+
include Gordon::Cookery::Java::WebApp
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:env_vars) { instance_double Gordon::EnvVars }
|
11
|
+
let(:workdir_path) { '/var/lib/tomcat/webapps/myapp' }
|
12
|
+
let(:build_path) { 'tmp-build' }
|
13
|
+
let(:preinstall_file_name) { '.gordon-before-install' }
|
14
|
+
let(:preinstall_path) { File.join(build_path, preinstall_file_name) }
|
15
|
+
let(:file) { instance_double File }
|
16
|
+
|
4
17
|
describe 'cleaning web app workdir before install package' do
|
5
|
-
|
18
|
+
it 'removes old application folder' do
|
19
|
+
expect(subject).to receive(:builddir).with(preinstall_file_name).and_return(preinstall_path)
|
20
|
+
|
21
|
+
expect(File).to receive(:open).with(preinstall_path, 'w', 0755).and_yield(file)
|
22
|
+
allow(file).to receive(:path).and_return(preinstall_path)
|
23
|
+
|
24
|
+
bash = <<-__BASH
|
25
|
+
#!/bin/sh
|
26
|
+
|
27
|
+
set -e
|
28
|
+
|
29
|
+
/usr/bin/rm -rf #{workdir_path}
|
30
|
+
__BASH
|
31
|
+
|
32
|
+
expect(file).to receive(:write).with(bash)
|
33
|
+
|
34
|
+
expect(subject.class).to receive(:pre_install).with(File.expand_path(file.path))
|
35
|
+
|
36
|
+
subject.clean_java_web_workdir(env_vars, workdir_path)
|
37
|
+
end
|
6
38
|
end
|
7
39
|
end
|
8
40
|
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::Ruby::Common do
|
4
|
-
describe '
|
5
|
-
|
4
|
+
describe 'default blacklist' do
|
5
|
+
it 'maps common files' do
|
6
|
+
expected = %w(.rspec coverage log spec tmp)
|
7
|
+
|
8
|
+
expect(described_class::RUBY_BLACKLIST_FILES).to eq(expected)
|
9
|
+
end
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
@@ -1,8 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gordon::Cookery::Standalone do
|
4
|
+
subject do
|
5
|
+
class MyStandalone
|
6
|
+
include Gordon::Cookery::Standalone
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:app_name) { "gordon" }
|
11
|
+
let(:env_vars) { instance_double Gordon::EnvVars, app_name: app_name }
|
12
|
+
let(:skeleton) { Gordon::Skeleton::Types::Misc.new }
|
13
|
+
let(:all_files) { %w(.bundle app config lib .ruby-version .ruby-gemset) }
|
14
|
+
let(:blacklist) { %w(.git) }
|
15
|
+
|
16
|
+
before :each do
|
17
|
+
expect(Gordon::Skeleton::Types::Misc).to receive(:new).and_return(skeleton)
|
18
|
+
end
|
19
|
+
|
4
20
|
describe 'installing files' do
|
5
|
-
|
21
|
+
it 'install all files based on misc skeleton' do
|
22
|
+
expect(subject).to receive(:all_files_except_blacklisted).with(blacklist).and_return(all_files)
|
23
|
+
|
24
|
+
installer = double 'a path helper'
|
25
|
+
expect(subject).to receive(:root).with(skeleton.path(app_name)).and_return(installer)
|
26
|
+
expect(installer).to receive(:install).with(all_files)
|
27
|
+
|
28
|
+
subject.install_standalone_files(env_vars, blacklist)
|
29
|
+
end
|
6
30
|
end
|
7
31
|
end
|
8
32
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gordon::Cookery::WebServer do
|
4
|
+
subject do
|
5
|
+
class MyWebServer
|
6
|
+
include Gordon::Cookery::WebServer
|
7
|
+
end.new
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:app_name) { "gordon" }
|
11
|
+
let(:web_server_type) { :tomcat }
|
12
|
+
let(:env_vars) { double Gordon::EnvVars, app_name: app_name, web_server_type: web_server_type }
|
13
|
+
let(:skeleton) { Gordon::Skeleton::Types::Tomcat.new }
|
14
|
+
let(:all_files) { %w(gordon.war) }
|
15
|
+
let(:blacklist) { %w(gordon.class) }
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
expect(Gordon::Skeleton::Types::Tomcat).to receive(:new).and_return(skeleton)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'installing web server files' do
|
22
|
+
it 'install files based on web server path' do
|
23
|
+
expect(subject).to receive(:all_files_except_blacklisted).with(blacklist).and_return(all_files)
|
24
|
+
|
25
|
+
installer = double 'a path helper'
|
26
|
+
expect(subject).to receive(:root).with(skeleton.path).and_return(installer)
|
27
|
+
expect(installer).to receive(:install).with(all_files)
|
28
|
+
|
29
|
+
subject.install_web_server_files(env_vars, blacklist)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -3,12 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe Gordon::EnvVars do
|
4
4
|
let(:attributes) do
|
5
5
|
{
|
6
|
-
app_type:
|
7
|
-
app_name:
|
8
|
-
|
9
|
-
|
6
|
+
app_type: "web",
|
7
|
+
app_name: "xirubiru",
|
8
|
+
app_description: "a nice description",
|
9
|
+
app_homepage: "http://some.github.repo",
|
10
10
|
app_version: "2.0.0",
|
11
|
-
|
11
|
+
app_source: ".",
|
12
|
+
runtime_name: "ruby",
|
12
13
|
runtime_version: "2.2.0",
|
13
14
|
http_server_type: "nginx",
|
14
15
|
web_server_type: "tomcat",
|
@@ -23,10 +24,11 @@ describe Gordon::EnvVars do
|
|
23
24
|
expected = [
|
24
25
|
"GORDON_APP_TYPE='#{options.app_type}'",
|
25
26
|
"GORDON_APP_NAME='#{options.app_name}'",
|
26
|
-
"
|
27
|
-
"
|
27
|
+
"GORDON_APP_DESCRIPTION='#{options.app_description}'",
|
28
|
+
"GORDON_APP_HOMEPAGE='#{options.app_homepage}'",
|
28
29
|
"GORDON_APP_VERSION='#{options.app_version}'",
|
29
|
-
"
|
30
|
+
"GORDON_APP_SOURCE='#{File.expand_path(options.app_source)}'",
|
31
|
+
"GORDON_RUNTIME_NAME='#{options.runtime_name}'",
|
30
32
|
"GORDON_RUNTIME_VERSION='#{options.runtime_version}'",
|
31
33
|
"GORDON_HTTP_SERVER_TYPE='#{options.http_server_type}'",
|
32
34
|
"GORDON_WEB_SERVER_TYPE='#{options.web_server_type}'",
|
@@ -42,10 +44,11 @@ describe Gordon::EnvVars do
|
|
42
44
|
env = {
|
43
45
|
'GORDON_APP_TYPE' => options.app_type,
|
44
46
|
'GORDON_APP_NAME' => options.app_name,
|
45
|
-
'
|
46
|
-
'
|
47
|
+
'GORDON_APP_DESCRIPTION' => options.app_description,
|
48
|
+
'GORDON_APP_HOMEPAGE' => options.app_homepage,
|
47
49
|
'GORDON_APP_VERSION' => options.app_version,
|
48
|
-
'
|
50
|
+
'GORDON_APP_SOURCE' => options.app_source,
|
51
|
+
'GORDON_RUNTIME_NAME' => options.runtime_name,
|
49
52
|
'GORDON_RUNTIME_VERSION' => options.runtime_version,
|
50
53
|
'GORDON_HTTP_SERVER_TYPE' => options.http_server_type,
|
51
54
|
'GORDON_WEB_SERVER_TYPE' => options.web_server_type,
|