fulmar 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b677f5683a979d761f27915ec1181cf120f9e57
4
- data.tar.gz: 4af0a8618226dd09f4deda014c8fa0151e1d4841
3
+ metadata.gz: 868b4a631f7d6353d760308daccd0457903b21fc
4
+ data.tar.gz: 5059427443e582732688fe6d0c722d50bd395058
5
5
  SHA512:
6
- metadata.gz: 2037bd7be61b50fea042250a59b639c8dc85876039dd9bb3ade4804f9d128ee7d4b5eedf774a4308184270af5972cbe053245d3c6eeeb2feb826e406478dbbde
7
- data.tar.gz: aa06a04c726ae5f7588bc0b655639af26f78eac65afd74800167840483efd8b17d94396b114eaf66b8302cd1faea24a330dada3957e3fdc773718e7450b31a87
6
+ metadata.gz: eb09328c8bc4ba396c967329787a21a8d0fb7cd5fd8080636c6d105b3edb4902d7358a597c0e5e98d058c0288011c084db6c4b698fcbeb726305954790fbb00f
7
+ data.tar.gz: caa5e4392cc720b383e14029e378b01b808181e07e5fe09d5af0cf98d250538f205508ebc72c178d81e91696bdb0637ebc79e87f1b6704287f093827e4dc5749
@@ -30,12 +30,12 @@ module Fulmar
30
30
  end
31
31
 
32
32
  def wrap_environment
33
- proc do
33
+ proc do |t, args|
34
34
  configuration = Fulmar::Domain::Service::ConfigurationService.instance
35
35
  environment = configuration.environment
36
36
  target = configuration.target
37
37
 
38
- yield if block_given?
38
+ yield(t, args) if block_given?
39
39
 
40
40
  configuration.environment = environment unless environment.nil?
41
41
  configuration.target = target unless target.nil?
@@ -67,6 +67,10 @@ module Fulmar
67
67
  @target = target ? target.to_sym : nil
68
68
  end
69
69
 
70
+ def ssh_user_and_host
71
+ self[:user].blank? ? self[:hostname] : self[:user] + '@' + self[:hostname]
72
+ end
73
+
70
74
  def dependencies(env = nil)
71
75
  env.nil? ? @config[:dependencies][:all] : @config[:dependencies][:all].deep_merge(@config[:dependencies][env])
72
76
  end
@@ -0,0 +1,57 @@
1
+ require 'rugged'
2
+
3
+ module Fulmar
4
+ module Domain
5
+ module Service
6
+ # Manages dependencies to subrepositories
7
+ class DependencyService
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+
12
+ def setup(env = @config.environment)
13
+ shell = Fulmar::Infrastructure::Service::ShellService.new(@config[:local_path])
14
+ @config.dependencies(env).each_pair do |_key, data|
15
+ next unless data[:type].blank? || data[:type] == 'git'
16
+ shell.run "git clone #{data[:source]} #{data[:path]}"
17
+ end
18
+ end
19
+
20
+ def update(env = @config.environment)
21
+ @config.dependencies(env).each_pair do |_key, data|
22
+ next unless data[:type].blank? || data[:type] == 'git'
23
+ git = Rugged::Repository.new(data[:path])
24
+
25
+ # Switch to the configured branch/tag/commit
26
+ if git.branches.select { |b| b.name.split('/').last == data[:ref] }.any?
27
+ checkout_branch(git, data[:ref])
28
+ elsif git.tags.map(&:name).include?(data[:ref])
29
+ git.checkout('refs/tags/'+data[:ref])
30
+ elsif data[:ref].match(/^[a-zA-Z0-9]{40}$/) && git.exists?(data[:ref])
31
+ git.checkout(data[:ref])
32
+ else
33
+ fail "Cannot find ref #{data[:ref]} in repo #{data[:path]}"
34
+ end
35
+
36
+ # Pull
37
+ shell = Fulmar::Infrastructure::Service::ShellService.new @config[:local_path]+'/'+data[:path]
38
+ unless shell.run 'git pull --rebase -q'
39
+ fail "Cannot update repository #{data[:path]}. Please update manually."
40
+ end
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def checkout_branch(git, branch)
47
+ if git.branches.collect(&:name).include? branch
48
+ git.checkout(branch)
49
+ else
50
+ new_branch = git.branches.create(branch.split('/').last, branch)
51
+ git.checkout(new_branch)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -9,3 +9,8 @@ if configuration.feature? :flow
9
9
  require 'fulmar/service/helper/flow_helper'
10
10
  include Fulmar::Domain::Service::Helper::FlowHelper
11
11
  end
12
+
13
+ if full_configuration[:dependencies].any?
14
+ require 'fulmar/service/helper/dependencies_helper'
15
+ include Fulmar::Domain::Service::Helper::DependenciesHelper
16
+ end
@@ -0,0 +1,55 @@
1
+ if configuration.any? { |data| data[:type] == 'vhost' }
2
+ namespace :vhost do
3
+ configuration.each do |env, target, data|
4
+ next if data[:type] != 'vhost'
5
+
6
+ desc "Create a vhost for #{env}"
7
+ task :create do
8
+ configuration.environment = env
9
+ configuration.target = target
10
+ branch = git.current_branch
11
+ match = branch.match(/f\d+_([a-zA-Z0-9]+)/)
12
+ unless match
13
+ STDERR.puts "Cannot deploy branch '#{branch}'"
14
+ return
15
+ end
16
+ configuration[:branch_name] = branch
17
+ configuration[:vhost_name] = match[1]
18
+ render_templates
19
+ upload configuration[:vhost_template]
20
+ sites_enabled_dir = configuration[:sites_enabled_dir] || '../sites_enabled'
21
+ remote_shell.run [
22
+ "ln -s #{configuration[:vhost_template]} #{sites_enabled_dir}/#{configuration[:vhost_template]}",
23
+ "service #{configuration[:webserver] || 'nginx'} reload"
24
+ ]
25
+ end
26
+
27
+ desc "List existing vhosts for #{env}"
28
+ task :list do
29
+ configuration.environment = env
30
+ configuration.target = target
31
+
32
+ remote_shell.run 'ls -1'
33
+ remote_shell.last_output.each do |line|
34
+ match = line.match(/auto_vhost_(.*)\.conf/)
35
+ if match
36
+ name = match[1]
37
+ puts "- #{name}, delete via 'fulmar vhost:delete[#{name}]'"
38
+ end
39
+ end
40
+ end
41
+
42
+ desc "Delete a vhost for #{env}"
43
+ task :delete, [:name] do |_t, argv|
44
+ configuration.environment = env
45
+ configuration.target = target
46
+
47
+ remote_shell.run [
48
+ "rm auto_vhost_#{argv[:name]}.conf",
49
+ "service #{configuration[:webserver] || 'nginx'} reload"
50
+ ]
51
+ end
52
+ end
53
+ end
54
+
55
+ end
@@ -3,12 +3,15 @@ module Fulmar
3
3
  module Service
4
4
  # Provides access to composer
5
5
  class ComposerService
6
+ DEFAULT_PARAMS = ['--no-dev']
7
+
6
8
  def initialize(shell, custom_path = '/usr/bin/env composer')
7
9
  @local_shell = shell
10
+ @local_shell.quiet = true
8
11
  @path = custom_path
9
12
  end
10
13
 
11
- def execute(command, arguments = %w(--no-dev -q))
14
+ def execute(command, arguments = DEFAULT_PARAMS)
12
15
  @local_shell.run "#{@path} #{command} #{arguments.join(' ')}"
13
16
  end
14
17
  end
@@ -45,12 +45,6 @@ module Fulmar
45
45
  # Placeholder for consistent api, currently only implemented in rsync_with_versions
46
46
  true
47
47
  end
48
-
49
- protected
50
-
51
- def ssh_user_and_host
52
- @config[:user].blank? ? @config[:hostname] : @config[:user] + '@' + @config[:hostname]
53
- end
54
48
  end
55
49
  end
56
50
  end
@@ -37,9 +37,9 @@ module Fulmar
37
37
  def rsync_command
38
38
  if @config[:rsync][:direction] == 'up'
39
39
  from = @config[:local_path]
40
- to = ssh_user_and_host + ':' + @config[:remote_path]
40
+ to = @config.ssh_user_and_host + ':' + @config[:remote_path]
41
41
  else
42
- from = ssh_user_and_host + ':' + @config[:remote_path]
42
+ from = @config.ssh_user_and_host + ':' + @config[:remote_path]
43
43
  to = @config[:local_path]
44
44
  end
45
45
 
@@ -45,7 +45,7 @@ module Fulmar
45
45
  # Ensures all needed services are set up
46
46
  def prepare
47
47
  super
48
- @remote_shell = Fulmar::Infrastructure::Service::ShellService.new @config[:remote_path], ssh_user_and_host
48
+ @remote_shell = Fulmar::Infrastructure::Service::ShellService.new @config[:remote_path], @config.ssh_user_and_host
49
49
  @remote_shell.debug = @config[:debug]
50
50
  end
51
51
 
@@ -143,7 +143,7 @@ module Fulmar
143
143
  options << "--chmod='#{@config[:rsync][:chmod]}'" if @config[:rsync][:chmod]
144
144
  options << '--delete' if @config[:rsync][:delete]
145
145
 
146
- "rsync #{options.join(' ')} '#{@config[:local_path]}/' '#{ssh_user_and_host}:#{@config[:remote_path]}/#{@config[:temp_dir]}'"
146
+ "rsync #{options.join(' ')} '#{@config[:local_path]}/' '#{@config.ssh_user_and_host}:#{@config[:remote_path]}/#{@config[:temp_dir]}'"
147
147
  end
148
148
 
149
149
  # Copies the data from the sync temp to the actual release directory
@@ -17,7 +17,7 @@ module Fulmar
17
17
  (@_config_service ||= Fulmar::Domain::Service::ConfigurationService.instance)
18
18
  end
19
19
 
20
- def composer(command, arguments = [])
20
+ def composer(command, arguments = Fulmar::Infrastructure::Service::ComposerService::DEFAULT_PARAMS)
21
21
  (storage['composer'] ||= Fulmar::Infrastructure::Service::ComposerService.new(local_shell)).execute(command, arguments)
22
22
  end
23
23
 
@@ -42,11 +42,11 @@ module Fulmar
42
42
  end
43
43
 
44
44
  def upload(filename)
45
- Fulmar::Infrastructure::Service::CopyService.upload(local_shell, filename, configuration[:hostname], configuration[:remote_path])
45
+ Fulmar::Infrastructure::Service::CopyService.upload(local_shell, filename, configuration.ssh_user_and_host, configuration[:remote_path])
46
46
  end
47
47
 
48
48
  def download(filename)
49
- Fulmar::Infrastructure::Service::CopyService.download(local_shell, configuration[:hostname], filename, configuration[:local_path])
49
+ Fulmar::Infrastructure::Service::CopyService.download(local_shell, configuration.ssh_user_and_host, filename, configuration[:local_path])
50
50
  end
51
51
 
52
52
  def new_shell(path, hostname = 'localhost')
@@ -64,15 +64,15 @@ module Fulmar
64
64
  end
65
65
 
66
66
  def info(text)
67
- puts (ENV['TERM'] == 'xterm-256color' ? text.blue : "* Info: #{text}")
67
+ puts (ENV['TERM'] == 'xterm-256color' ? text.blue : "* Info: #{text}") if verbose
68
68
  end
69
69
 
70
70
  def warn(text)
71
- puts (ENV['TERM'] == 'xterm-256color' ? text.magenta : "* Warning: #{text}")
71
+ STDERR.puts (ENV['TERM'] == 'xterm-256color' ? text.magenta : "* Warning: #{text}")
72
72
  end
73
73
 
74
74
  def error(text)
75
- puts (ENV['TERM'] == 'xterm-256color' ? text.light_red : "* Error: #{text}")
75
+ STDERR.puts (ENV['TERM'] == 'xterm-256color' ? text.light_red : "* Error: #{text}")
76
76
  end
77
77
  end
78
78
  end
@@ -0,0 +1,16 @@
1
+ require 'fulmar/domain/service/dependency_service'
2
+
3
+ module Fulmar
4
+ module Domain
5
+ module Service
6
+ module Helper
7
+ # Provides access helper to the database service from within a task
8
+ module DependenciesHelper
9
+ def dependencies
10
+ storage['dependecies'] ||= Fulmar::Domain::Service::DependencyService.new configuration
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,4 @@
1
1
  # Provides a global version number
2
2
  module Fulmar
3
- VERSION = '1.3.0'
3
+ VERSION = '1.4.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulmar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Siegl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-09 00:00:00.000000000 Z
12
+ date: 2015-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -140,12 +140,14 @@ files:
140
140
  - lib/fulmar/domain/service/application_service.rb
141
141
  - lib/fulmar/domain/service/config_rendering_service.rb
142
142
  - lib/fulmar/domain/service/configuration_service.rb
143
+ - lib/fulmar/domain/service/dependency_service.rb
143
144
  - lib/fulmar/domain/service/file_sync_service.rb
144
145
  - lib/fulmar/domain/service/initialization_service.rb
145
146
  - lib/fulmar/domain/task/base.rake
146
147
  - lib/fulmar/domain/task/database_sync.rake
147
148
  - lib/fulmar/domain/task/environment.rake
148
149
  - lib/fulmar/domain/task/versions.rake
150
+ - lib/fulmar/domain/task/vhost.rake
149
151
  - lib/fulmar/infrastructure/service/composer_service.rb
150
152
  - lib/fulmar/infrastructure/service/copy_service.rb
151
153
  - lib/fulmar/infrastructure/service/database/database_service.rb
@@ -160,6 +162,7 @@ files:
160
162
  - lib/fulmar/service/bootstrap_service.rb
161
163
  - lib/fulmar/service/helper/common_helper.rb
162
164
  - lib/fulmar/service/helper/database_helper.rb
165
+ - lib/fulmar/service/helper/dependencies_helper.rb
163
166
  - lib/fulmar/service/helper/flow_helper.rb
164
167
  - lib/fulmar/service/helper_service.rb
165
168
  - lib/fulmar/service/logger_service.rb