fulmar 1.10.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +11 -4
- data/README.md +87 -102
- data/fulmar.gemspec +2 -2
- data/lib/fulmar/domain/{service/application_service.rb → model/application.rb} +16 -2
- data/lib/fulmar/domain/model/configuration.rb +185 -0
- data/lib/fulmar/domain/service/config_test_service.rb +32 -114
- data/lib/fulmar/domain/service/config_tests/hosts.rb +23 -0
- data/lib/fulmar/domain/service/config_tests/mariadb.rb +19 -0
- data/lib/fulmar/domain/service/config_tests/paths.rb +15 -0
- data/lib/fulmar/domain/service/config_tests/project.rb +5 -0
- data/lib/fulmar/domain/service/configuration_service.rb +13 -131
- data/lib/fulmar/domain/service/file_sync_service.rb +7 -7
- data/lib/fulmar/domain/service/helper/common_helper.rb +18 -32
- data/lib/fulmar/domain/service/plugin_service.rb +60 -0
- data/lib/fulmar/domain/service/{config_rendering_service.rb → template_rendering_service.rb} +3 -3
- data/lib/fulmar/domain/task/configuration.rake +9 -7
- data/lib/fulmar/domain/task/console.rake +3 -3
- data/lib/fulmar/domain/task/environment.rake +5 -12
- data/lib/fulmar/domain/task/initialization/base.rake +3 -9
- data/lib/fulmar/domain/task/versions.rake +8 -12
- data/lib/fulmar/infrastructure/default_files/Fulmar/project.config.yml +26 -0
- data/lib/fulmar/infrastructure/default_files/Fulmarfile +22 -0
- data/lib/fulmar/infrastructure/{service → model}/transfer/base.rb +4 -4
- data/lib/fulmar/infrastructure/{service → model}/transfer/rsync.rb +4 -2
- data/lib/fulmar/infrastructure/{service → model}/transfer/rsync_with_versions.rb +18 -20
- data/lib/fulmar/infrastructure/{service → model}/transfer/tar.rb +2 -2
- data/lib/fulmar/infrastructure/service/copy_service.rb +2 -2
- data/lib/fulmar/infrastructure/service/ssh_config_service.rb +8 -21
- data/lib/fulmar/service/bootstrap_service.rb +1 -5
- data/lib/fulmar/task_manager.rb +2 -8
- data/lib/fulmar/version.rb +1 -1
- data/spec/lib/fulmar/model/configuration_spec.rb +193 -0
- data/spec/lib/fulmar/service/plugin_service_spec.rb +29 -0
- metadata +29 -34
- data/lib/fulmar/domain/service/helper/database_helper.rb +0 -14
- data/lib/fulmar/domain/service/helper/flow_helper.rb +0 -16
- data/lib/fulmar/domain/service/helper/vhost_helper.rb +0 -21
- data/lib/fulmar/domain/task/database_sync.rake +0 -63
- data/lib/fulmar/infrastructure/service/composer_service.rb +0 -22
- data/lib/fulmar/infrastructure/service/database/database_service.rb +0 -118
- data/lib/fulmar/infrastructure/service/flow_service.rb +0 -47
- data/lib/fulmar/infrastructure/service/shell_service.rb +0 -10
- data/lib/fulmar/service/logger_service.rb +0 -7
- data/test/rsync_with_versions.rb +0 -20
@@ -1,12 +1,12 @@
|
|
1
1
|
desc 'Open an interactive terminal within fulmar'
|
2
|
-
task :console, [:environment] do |
|
2
|
+
task :console, [:environment] do |_t, args|
|
3
3
|
require 'irb'
|
4
4
|
require 'irb/completion'
|
5
5
|
ARGV.clear
|
6
6
|
if args[:environment] && args[:environment].include?(':')
|
7
7
|
environment, target = args[:environment].split(':')
|
8
|
-
|
9
|
-
|
8
|
+
config.environment = environment.to_sym
|
9
|
+
config.target = target.to_sym
|
10
10
|
end
|
11
11
|
IRB.start
|
12
12
|
end
|
@@ -2,19 +2,12 @@
|
|
2
2
|
# so that these tasks might be a dependency for other tasks
|
3
3
|
|
4
4
|
namespace :environment do
|
5
|
-
|
6
|
-
# Sets the environment to #{env}
|
7
|
-
task env do
|
8
|
-
configuration.environment = env
|
9
|
-
end
|
10
|
-
|
5
|
+
config.each do |env, target, _data|
|
11
6
|
namespace env do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
configuration.target = target
|
17
|
-
end
|
7
|
+
# Sets the environment to #{env} and the target to #{target}
|
8
|
+
task target do
|
9
|
+
config.environment = env
|
10
|
+
config.target = target
|
18
11
|
end
|
19
12
|
end
|
20
13
|
end
|
@@ -1,12 +1,6 @@
|
|
1
1
|
require 'fulmar/domain/service/helper/common_helper'
|
2
2
|
include Fulmar::Domain::Service::Helper::CommonHelper
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
if configuration.feature? :flow
|
10
|
-
require 'fulmar/domain/service/helper/flow_helper'
|
11
|
-
include Fulmar::Domain::Service::Helper::FlowHelper
|
12
|
-
end
|
4
|
+
Fulmar::Domain::Service::PluginService.instance.helpers.each do |helper|
|
5
|
+
include helper
|
6
|
+
end
|
@@ -3,12 +3,8 @@ include Fulmar::Domain::Service::Helper::CommonHelper
|
|
3
3
|
namespace :versions do
|
4
4
|
@versioned_servers = {}
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
targets.each_pair do |target, config|
|
10
|
-
@versioned_servers["#{env}:#{target}"] = config if config[:type].to_s == 'rsync_with_versions'
|
11
|
-
end
|
6
|
+
config.each do |env, target, config|
|
7
|
+
@versioned_servers["#{env}:#{target}"] = config if config[:type].to_s == 'rsync_with_versions'
|
12
8
|
end
|
13
9
|
|
14
10
|
unless @versioned_servers.empty?
|
@@ -25,8 +21,8 @@ namespace :versions do
|
|
25
21
|
|
26
22
|
desc "List available versions for environment/target \"#{env}\""
|
27
23
|
task task_environment do
|
28
|
-
|
29
|
-
|
24
|
+
config.environment = env.split(':').first
|
25
|
+
config.target = env.split(':').last
|
30
26
|
file_sync.list_releases(false).each { |item| puts item }
|
31
27
|
end
|
32
28
|
end
|
@@ -34,8 +30,8 @@ namespace :versions do
|
|
34
30
|
namespace :clean do
|
35
31
|
desc "Delete obsolete versions for target \"#{env}\""
|
36
32
|
task task_environment do
|
37
|
-
|
38
|
-
|
33
|
+
config.environment = env.split(':').first
|
34
|
+
config.target = env.split(':').last
|
39
35
|
file_sync.cleanup
|
40
36
|
end
|
41
37
|
end
|
@@ -43,8 +39,8 @@ namespace :versions do
|
|
43
39
|
namespace :revert do
|
44
40
|
desc "Revert to the previous version for \"#{env}\""
|
45
41
|
task task_environment do
|
46
|
-
|
47
|
-
|
42
|
+
config.environment = env.split(':').first
|
43
|
+
config.target = env.split(':').last
|
48
44
|
error 'Cannot revert to previous version.' unless file_sync.revert
|
49
45
|
end
|
50
46
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
project:
|
2
|
+
name: example_project
|
3
|
+
fulmar_version: '~> 2.0'
|
4
|
+
|
5
|
+
environments:
|
6
|
+
local:
|
7
|
+
base:
|
8
|
+
local_path: .
|
9
|
+
|
10
|
+
staging:
|
11
|
+
files:
|
12
|
+
host: staging_server
|
13
|
+
|
14
|
+
dependencies:
|
15
|
+
# Dependencies under "all" are merged into all environments
|
16
|
+
all:
|
17
|
+
application:
|
18
|
+
type: git
|
19
|
+
|
20
|
+
|
21
|
+
hosts:
|
22
|
+
staging_server:
|
23
|
+
hostname: staging
|
24
|
+
ssh_config:
|
25
|
+
Hostname: staging
|
26
|
+
User: deployment
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This is a basic Fulmarfile. You can add task just like in Rake. Additionally, you can
|
2
|
+
# use helper to modify the ssh config, open a shell locally or remote, or upload files to a preconfigured host
|
3
|
+
# All paths and hostname are configured in Fulmar/project.config.yml. You can split you configuration over multiple
|
4
|
+
# *.config.yml files which are all merged. You can create additional .rake files within the Fulmar directory.
|
5
|
+
# For more help, look at https://github.com/CORE4/fulmar
|
6
|
+
|
7
|
+
desc 'setup this project'
|
8
|
+
task setup: 'environment:local:base' do
|
9
|
+
info 'Withing this task you can add the initialization of your project.'
|
10
|
+
# Maybe do this:
|
11
|
+
# dependencies.setup
|
12
|
+
# ssh_config.add_hosts
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :deploy do
|
16
|
+
desc 'Deploy to staging system'
|
17
|
+
task staging: 'environment:staging:application' do
|
18
|
+
info 'Here you can upload your files and maybe flush the cache'
|
19
|
+
# file_sync.transfer
|
20
|
+
# remote_shell.run 'php cli/console cache:flush'
|
21
|
+
end
|
22
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
1
|
require 'fulmar/shell'
|
3
2
|
|
4
3
|
module Fulmar
|
5
4
|
module Infrastructure
|
6
|
-
module
|
5
|
+
module Model
|
7
6
|
module Transfer
|
8
|
-
# Abstract class for
|
7
|
+
# Abstract class for all transfers, provides common methods
|
9
8
|
class Base
|
10
9
|
DEFAULT_CONFIG = {
|
11
10
|
debug: false,
|
@@ -38,7 +37,8 @@ module Fulmar
|
|
38
37
|
end
|
39
38
|
|
40
39
|
def prepare
|
41
|
-
@local_shell = Fulmar::
|
40
|
+
@local_shell = Fulmar::Shell.new @config[:local_path]
|
41
|
+
@local_shell.strict = true
|
42
42
|
@local_shell.debug = @config[:debug]
|
43
43
|
@prepared = true
|
44
44
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require 'fulmar/infrastructure/
|
2
|
+
require 'fulmar/infrastructure/model/transfer/base'
|
3
3
|
|
4
4
|
module Fulmar
|
5
5
|
module Infrastructure
|
6
|
-
module
|
6
|
+
module Model
|
7
7
|
module Transfer
|
8
8
|
# Implements the rsync transfer
|
9
9
|
class Rsync < Base
|
@@ -27,6 +27,8 @@ module Fulmar
|
|
27
27
|
@config[:rsync][:exclude_file] = @config[:local_path] + '/.rsyncignore'
|
28
28
|
end
|
29
29
|
|
30
|
+
fail 'Hostname not set. Cannot initialize sync.' if @config[:hostname].empty?
|
31
|
+
|
30
32
|
super(@config)
|
31
33
|
end
|
32
34
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
require 'fulmar/infrastructure/
|
2
|
+
require 'fulmar/infrastructure/model/transfer/base'
|
3
3
|
require 'time'
|
4
|
-
require '
|
4
|
+
require 'active_support'
|
5
5
|
|
6
6
|
module Fulmar
|
7
7
|
module Infrastructure
|
8
|
-
module
|
8
|
+
module Model
|
9
9
|
module Transfer
|
10
10
|
# Provides syncing with versioning on the server
|
11
11
|
#
|
@@ -24,7 +24,7 @@ module Fulmar
|
|
24
24
|
exclude_file: nil,
|
25
25
|
chown: nil,
|
26
26
|
chmod: nil,
|
27
|
-
delete:
|
27
|
+
delete: true
|
28
28
|
},
|
29
29
|
symlinks: {},
|
30
30
|
limit_releases: 5,
|
@@ -47,7 +47,7 @@ module Fulmar
|
|
47
47
|
# Ensures all needed services are set up
|
48
48
|
def prepare
|
49
49
|
super
|
50
|
-
@remote_shell = Fulmar::
|
50
|
+
@remote_shell = Fulmar::Shell.new @config[:remote_path], @config.ssh_user_and_host
|
51
51
|
@remote_shell.debug = @config[:debug]
|
52
52
|
end
|
53
53
|
|
@@ -56,10 +56,7 @@ module Fulmar
|
|
56
56
|
def transfer
|
57
57
|
prepare unless @prepared
|
58
58
|
|
59
|
-
|
60
|
-
fail 'Deployment failed. Cannot sync files.' unless @local_shell.run(rsync_command)
|
61
|
-
fail 'Deployment failed when trying to move file from temporary upload dir.' unless copy_temp_to_release
|
62
|
-
fail 'Deployment failed when creating symlinks for shared folders' unless add_shared
|
59
|
+
create_paths && @local_shell.run(rsync_command) && copy_temp_to_release && add_shared
|
63
60
|
end
|
64
61
|
|
65
62
|
# Publishes the current release (i.e. sets the 'current' symlink)
|
@@ -156,7 +153,7 @@ module Fulmar
|
|
156
153
|
# Builds the rsync command
|
157
154
|
# @return [String] the command
|
158
155
|
def rsync_command
|
159
|
-
options =
|
156
|
+
options = ['-rl']
|
160
157
|
options << rsync_excludes if rsync_excludes
|
161
158
|
options << "--exclude-from='#{@config[:rsync][:exclude_file]}'" if @config[:rsync][:exclude_file]
|
162
159
|
options << "--chown='#{@config[:rsync][:chown]}'" if @config[:rsync][:chown]
|
@@ -169,7 +166,7 @@ module Fulmar
|
|
169
166
|
# Copies the data from the sync temp to the actual release directory
|
170
167
|
# @return [true, false] success
|
171
168
|
def copy_temp_to_release
|
172
|
-
@remote_shell.run "cp -
|
169
|
+
@remote_shell.run "cp -pr #{@config[:temp_dir]} #{release_dir}"
|
173
170
|
end
|
174
171
|
|
175
172
|
# Set the symlink to the given release or the return value of release_dir() otherwise
|
@@ -190,23 +187,24 @@ module Fulmar
|
|
190
187
|
# @return [true, false] success
|
191
188
|
def add_shared
|
192
189
|
commands = [] # Collect all remote commands first, then execute them in one step to avoid reconnecting very often
|
193
|
-
@config[:shared].each do |
|
194
|
-
commands << "mkdir -p \"#{release_dir}/#{
|
190
|
+
@config[:shared].each do |dir|
|
191
|
+
commands << "mkdir -p \"#{release_dir}/#{dir}\""
|
195
192
|
|
196
|
-
unless
|
197
|
-
commands << "mkdir -p \"#{@config[:shared_dir]}/#{
|
193
|
+
unless remote_dir_exists?("#{@config[:shared_dir]}/#{dir}")
|
194
|
+
commands << "mkdir -p \"#{@config[:shared_dir]}/#{File.dirname(dir)}\""
|
195
|
+
commands << "cp -pr \"#{release_dir}/#{dir}\" \"#{@config[:shared_dir]}/#{File.dirname(dir)}\""
|
198
196
|
end
|
199
197
|
|
200
|
-
commands << "rm -fr \"#{release_dir}/#{
|
201
|
-
commands << "mkdir -p \"#{release_dir}/#{File.dirname(
|
202
|
-
commands << "ln -s \"#{@config[:remote_path]}/#{@config[:shared_dir]}/#{
|
198
|
+
commands << "rm -fr \"#{release_dir}/#{dir}\""
|
199
|
+
commands << "mkdir -p \"#{release_dir}/#{File.dirname(dir)}\""
|
200
|
+
commands << "ln -s \"#{@config[:remote_path]}/#{@config[:shared_dir]}/#{dir}\" \"#{release_dir}/#{dir}\""
|
203
201
|
end
|
204
202
|
|
205
203
|
@remote_shell.run commands if commands.length > 0
|
206
204
|
end
|
207
205
|
|
208
|
-
def
|
209
|
-
@remote_shell.run "test -
|
206
|
+
def remote_dir_exists?(dir)
|
207
|
+
@remote_shell.run "test -d \"#{dir}\""
|
210
208
|
end
|
211
209
|
end
|
212
210
|
end
|
@@ -4,7 +4,7 @@ module Fulmar
|
|
4
4
|
# Provides access to composer
|
5
5
|
class CopyService
|
6
6
|
# Copies a file to a remote server
|
7
|
-
# @param [Fulmar::
|
7
|
+
# @param [Fulmar::Shell] shell
|
8
8
|
# @param [String] local_file local filename, should be absolute
|
9
9
|
# @param [String] remote_host SSH hostname
|
10
10
|
# @param [String] remote_dir remote directory
|
@@ -15,7 +15,7 @@ module Fulmar
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Downloads a file from a remote server
|
18
|
-
# @param [Fulmar::
|
18
|
+
# @param [Fulmar::Shell] shell
|
19
19
|
# @param [String] remote_host SSH hostname
|
20
20
|
# @param [String] remote_file remote directory
|
21
21
|
# @param [String] local_dir local filename, should be absolute
|
@@ -7,26 +7,13 @@ module Fulmar
|
|
7
7
|
class SSHConfigService
|
8
8
|
CONFIG_FILE = "#{ENV['HOME']}/.ssh/config"
|
9
9
|
KNOWN_HOST_FILE = "#{ENV['HOME']}/.ssh/known_hosts"
|
10
|
-
# @todo: Get rid of this layer (Version 2?)
|
11
|
-
CONFIG_MAP = {
|
12
|
-
hostname: 'Hostname',
|
13
|
-
port: 'Port',
|
14
|
-
user: 'User',
|
15
|
-
proxycommand: 'ProxyCommand',
|
16
|
-
checkhostip: 'CheckHostIP',
|
17
|
-
stricthostkeychecking: 'StrictHostKeyChecking',
|
18
|
-
identityfile: 'IdentityFile',
|
19
|
-
userknownhostfile: 'UserKnownHostsFile',
|
20
|
-
loglevel: 'LogLevel',
|
21
|
-
forwardagent: 'ForwardAgent'
|
22
|
-
}
|
23
10
|
|
24
11
|
def initialize(config)
|
25
12
|
@config = config
|
26
13
|
end
|
27
14
|
|
28
15
|
def add_hosts
|
29
|
-
@config.
|
16
|
+
@config.hosts.values.each do |data|
|
30
17
|
unless config_valid?(data)
|
31
18
|
puts "Skipping #{data[:hostname]}, config not sufficient." if @config[:debug]
|
32
19
|
next
|
@@ -68,17 +55,17 @@ module Fulmar
|
|
68
55
|
puts "Adding host #{hostname}..." if @config[:debug]
|
69
56
|
config_file = File.open(CONFIG_FILE, 'a')
|
70
57
|
|
71
|
-
unless ssh_config[:
|
72
|
-
ssh_config[:
|
58
|
+
unless ssh_config[:IdentityFile].blank? or ssh_config[:IdentityFile][0, 1] == '/'
|
59
|
+
ssh_config[:IdentityFile] = @config.base_path + '/' + ssh_config[:IdentityFile]
|
73
60
|
end
|
74
61
|
|
75
62
|
config_file.puts "\n" # Add some space between this and the second last entry
|
76
|
-
config_file.puts "# Automatically generated by fulmar for project #{@config.project.description}"
|
63
|
+
config_file.puts "# Automatically generated by fulmar for project '#{@config.project.description}'"
|
77
64
|
config_file.puts "Host #{hostname}"
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
65
|
+
ssh_config.keys.each do |key|
|
66
|
+
value = ssh_config[key].to_s
|
67
|
+
value = "\"#{value.gsub('"', '\\"')}\"" if value.include?(' ')
|
68
|
+
config_file.puts " #{key} #{value}"
|
82
69
|
end
|
83
70
|
|
84
71
|
config_file.close
|
@@ -2,12 +2,8 @@ module Fulmar
|
|
2
2
|
module Service
|
3
3
|
# Initializes the rake service and starts it
|
4
4
|
class BootstrapService
|
5
|
-
def initialize
|
6
|
-
$logger = Fulmar::Service::LoggerService.new(STDOUT)
|
7
|
-
end
|
8
|
-
|
9
5
|
def fly
|
10
|
-
Fulmar::Domain::Service::
|
6
|
+
Fulmar::Domain::Service::Application.new.run
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
data/lib/fulmar/task_manager.rb
CHANGED
@@ -2,22 +2,16 @@ require 'fulmar/version'
|
|
2
2
|
|
3
3
|
require 'fulmar/service/bootstrap_service'
|
4
4
|
require 'fulmar/service/helper_service'
|
5
|
-
require 'fulmar/service/logger_service'
|
6
5
|
|
7
6
|
require 'fulmar/domain/service/initialization_service'
|
8
|
-
require 'fulmar/domain/
|
7
|
+
require 'fulmar/domain/model/application'
|
9
8
|
require 'fulmar/domain/service/configuration_service'
|
10
|
-
require 'fulmar/domain/service/
|
9
|
+
require 'fulmar/domain/service/template_rendering_service'
|
11
10
|
require 'fulmar/domain/service/file_sync_service'
|
12
11
|
|
13
|
-
require 'fulmar/infrastructure/service/composer_service'
|
14
|
-
require 'fulmar/infrastructure/service/shell_service'
|
15
12
|
require 'fulmar/infrastructure/service/copy_service'
|
16
13
|
require 'fulmar/infrastructure/service/ssh_config_service'
|
17
14
|
|
18
|
-
require 'fulmar/infrastructure/service/database/database_service'
|
19
|
-
|
20
|
-
require 'ruby_wings'
|
21
15
|
require 'fileutils'
|
22
16
|
|
23
17
|
bootstrap = Fulmar::Service::BootstrapService.new
|
data/lib/fulmar/version.rb
CHANGED
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'fulmar/service/helper_service'
|
2
|
+
require 'fulmar/domain/model/configuration'
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
FULMAR_TEST_CONFIG = {
|
6
|
+
project: {
|
7
|
+
name: 'Test data'
|
8
|
+
},
|
9
|
+
environments: {
|
10
|
+
all: {
|
11
|
+
local_path: 'Application',
|
12
|
+
inherit_test: 'global'
|
13
|
+
},
|
14
|
+
staging: {
|
15
|
+
all: {
|
16
|
+
host: 'stagingserver',
|
17
|
+
local_path: '/tmp',
|
18
|
+
inherit_test: 'environment'
|
19
|
+
},
|
20
|
+
data: {
|
21
|
+
relative_path: 'relative',
|
22
|
+
absolute_path: '/absolute',
|
23
|
+
remote_path: '/'
|
24
|
+
},
|
25
|
+
files: {
|
26
|
+
inherit_test: 'local',
|
27
|
+
local_path: '.',
|
28
|
+
remote_path: 'tmp',
|
29
|
+
hostname: 'localhost'
|
30
|
+
}
|
31
|
+
},
|
32
|
+
live: {
|
33
|
+
files: {
|
34
|
+
},
|
35
|
+
data: {
|
36
|
+
local_path: 'Application',
|
37
|
+
relative_path: 'SubApplication'
|
38
|
+
}
|
39
|
+
}
|
40
|
+
},
|
41
|
+
hosts: {
|
42
|
+
liveserver: {
|
43
|
+
hostname: 'liveserver',
|
44
|
+
remote_path: '/liveserver'
|
45
|
+
},
|
46
|
+
stagingserver: {
|
47
|
+
hostname: 'stagingserver',
|
48
|
+
remote_path: '/stagingserver'
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
}
|
53
|
+
|
54
|
+
describe Fulmar::Domain::Model::Configuration do
|
55
|
+
before :each do
|
56
|
+
# Make a deep copy of the hash so we have a fresh copy for every test
|
57
|
+
config_data = Marshal.load( Marshal.dump(FULMAR_TEST_CONFIG) )
|
58
|
+
@config = Fulmar::Domain::Model::Configuration.new(config_data, '/tmp')
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#instantiation' do
|
62
|
+
it 'should return a simple configuration option' do
|
63
|
+
@config.environment = :staging
|
64
|
+
@config.target = :files
|
65
|
+
expect(@config[:inherit_test]).to eql('local')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should return an inherited configuration option from the environment' do
|
69
|
+
@config.environment = :staging
|
70
|
+
@config.target = :data
|
71
|
+
expect(@config[:inherit_test]).to eql('environment')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return an globally inherited configuration option' do
|
75
|
+
@config.environment = :live
|
76
|
+
@config.target = :files
|
77
|
+
expect(@config[:inherit_test]).to eql('global')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#each' do
|
82
|
+
it 'should iterate over all environments/targets do' do
|
83
|
+
@all_targets = []
|
84
|
+
FULMAR_TEST_CONFIG[:environments].keys.each do |env|
|
85
|
+
next if env == :all
|
86
|
+
FULMAR_TEST_CONFIG[:environments][env].keys.each do |target, _value|
|
87
|
+
next if target == :all
|
88
|
+
@all_targets << "#{env}/#{target}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
@targets = []
|
92
|
+
@config.each do |env, target, _data|
|
93
|
+
@targets << "#{env}/#{target}"
|
94
|
+
end
|
95
|
+
expect(@targets).to eql(@all_targets)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#project' do
|
100
|
+
it 'should return a new project' do
|
101
|
+
expect(@config.project).to be_a Fulmar::Domain::Model::Project
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#ready?' do
|
106
|
+
it 'should return false if settings are missing' do
|
107
|
+
expect(@config.ready?).to be false
|
108
|
+
@config.environment = :staging
|
109
|
+
expect(@config.ready?).to be false
|
110
|
+
@config.environment = nil
|
111
|
+
@config.target = :files
|
112
|
+
expect(@config.ready?).to be false
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return true with all settings given' do
|
116
|
+
@config.environment = :staging
|
117
|
+
@config.target = :files
|
118
|
+
expect(@config.ready?).to be true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#merge_hosts' do
|
123
|
+
it 'should merge the host configuration into the target' do
|
124
|
+
@config.environment = :staging
|
125
|
+
@config.target = :data
|
126
|
+
expect(@config[:hostname]).to eql('stagingserver')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should prefer the local configuration over the host configuration' do
|
130
|
+
@config.environment = :staging
|
131
|
+
@config.target = :data
|
132
|
+
expect(@config[:remote_path]).to eql('/')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#merge' do
|
137
|
+
it 'merges the given configuration into the current target' do
|
138
|
+
default_config = { new_default_value: 'default' }
|
139
|
+
@config.environment = :staging
|
140
|
+
@config.target = :data
|
141
|
+
@config.merge(default_config)
|
142
|
+
expect(@config[:new_default_value]).to eql('default')
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'prefers the explicit config over the default values' do
|
146
|
+
default_config = { remote_path: '/default' }
|
147
|
+
@config.environment = :staging
|
148
|
+
@config.target = :data
|
149
|
+
@config.merge(default_config)
|
150
|
+
expect(@config[:remote_path]).to eql('/')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#path_expansion' do
|
155
|
+
it 'keeps absolute paths' do
|
156
|
+
@config.environment = :staging
|
157
|
+
@config.target = :data
|
158
|
+
expect(@config[:absolute_path]).to eql('/absolute')
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'keeps remote paths' do
|
162
|
+
@config.environment = :staging
|
163
|
+
@config.target = :files
|
164
|
+
expect(@config[:remote_path]).to eql('tmp')
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'makes paths absolute' do
|
168
|
+
@config.environment = :staging
|
169
|
+
@config.target = :data
|
170
|
+
expect(@config[:relative_path][0,1]).to eql('/')
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'joins the path, local_path and a given third path' do
|
174
|
+
@config.environment = :live
|
175
|
+
@config.target = :data
|
176
|
+
expect(@config[:relative_path]).to eql('/tmp/Application/SubApplication')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#set' do
|
181
|
+
it 'should set the environment only' do
|
182
|
+
@config.set(:live)
|
183
|
+
expect(@config.environment).to eql(:live)
|
184
|
+
expect(@config.target).to be_nil
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should set the environment and the target' do
|
188
|
+
@config.set(:live, :data)
|
189
|
+
expect(@config.environment).to eql(:live)
|
190
|
+
expect(@config.target).to eql(:data)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#require 'fulmar/service/helper_service'
|
2
|
+
#require 'fulmar/domain/model/configuration'
|
3
|
+
|
4
|
+
require 'fulmar/domain/service/plugin_service'
|
5
|
+
|
6
|
+
module Fulmar
|
7
|
+
module Plugin
|
8
|
+
module MariaDB
|
9
|
+
class Database
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Fulmar::Domain::Service::PluginService do
|
16
|
+
before :each do
|
17
|
+
@plugin_service = Fulmar::Domain::Service::PluginService.instance
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#classname' do
|
21
|
+
it 'returns a module' do
|
22
|
+
expect(@plugin_service.classname :maria).to eql(Fulmar::Plugin::MariaDB)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns a class' do
|
26
|
+
expect(@plugin_service.classname(:maria, :database)).to eql(Fulmar::Plugin::MariaDB::Database)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|