capistrano-contao 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/capistrano-contao/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.authors = ["Wael M. Nasreddine"]
6
- gem.email = ["wael.nasreddine@gmail.com"]
7
- gem.description = 'Capistrano receipts for Contao deployment'
4
+ gem.authors = ['Wael M. Nasreddine']
5
+ gem.email = ['wael.nasreddine@gmail.com']
6
+ gem.description = 'Capistrano recipes for Contao deployment'
8
7
  gem.summary = gem.summary
9
8
  gem.homepage = 'http://technogate.github.com/contao'
10
9
  gem.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
@@ -12,15 +11,14 @@ Gem::Specification.new do |gem|
12
11
  gem.files = `git ls-files`.split($\)
13
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
- gem.name = "capistrano-contao"
16
- gem.require_paths = ["lib"]
17
- gem.version = TechnoGate::Capistrano::Contao::VERSION
14
+ gem.name = 'capistrano-contao'
15
+ gem.require_paths = ['lib']
16
+ gem.version = '0.0.2'
18
17
 
19
18
  # Runtime dependencies
20
19
  gem.add_dependency 'rake'
21
20
  gem.add_dependency 'activesupport'
22
-
23
- # Development dependencies
24
- gem.add_development_dependency 'rspec'
25
- gem.add_development_dependency 'fakefs'
21
+ gem.add_dependency 'capistrano-database'
22
+ gem.add_dependency 'capistrano-utils'
23
+ gem.add_dependency 'capistrano-server'
26
24
  end
@@ -0,0 +1,117 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'capistrano/monkey_patches/fix_capture_conflict'
3
+ require 'capistrano/ext/helpers'
4
+ require 'capistrano/ext/git'
5
+ require 'capistrano/ext/custom_colors'
6
+ require 'capistrano/ext/decouple_from_rails'
7
+ require 'capistrano/ext/contao_assets'
8
+ require 'capistrano/ext/database'
9
+ require 'capistrano/ext/server'
10
+ require 'capistrano/ext/deploy'
11
+
12
+ unless Capistrano::Configuration.respond_to?(:instance)
13
+ abort 'capistrano/ext/contao requires capistrano 2'
14
+ end
15
+
16
+ Capistrano::Configuration.instance(:must_exist).load do
17
+ namespace :contao do
18
+ desc '[internal] Setup contao'
19
+ task :setup, :roles => :app, :except => { :no_release => true } do
20
+ # Empty task, the rest should hook to it
21
+ end
22
+
23
+ desc '[internal] Setup contao shared contents'
24
+ task :setup_shared_folder, :roles => :app, :except => { :no_release => true } do
25
+ shared_path = fetch :shared_path
26
+ run <<-CMD
27
+ #{try_sudo} mkdir -p #{shared_path}/logs &&
28
+ #{try_sudo} mkdir -p #{shared_path}/config
29
+ CMD
30
+
31
+ # TODO: The deny access should follow denied_access config
32
+ deny_htaccess = "order deny,allow\n"
33
+ deny_htaccess << "deny from all"
34
+
35
+ put deny_htaccess, "#{shared_path}/logs/.htaccess"
36
+ end
37
+
38
+ desc '[internal] Setup contao localconfig'
39
+ task :setup_localconfig, :roles => :app, :except => { :no_release => true } do
40
+ localconfig_php_config_path = "#{fetch :shared_path}/config/public_system_config_localconfig.php"
41
+ on_rollback { run "rm -f #{localconfig_php_config_path}" }
42
+ db_credentials = fetch :db_credentials
43
+
44
+ localconfig = File.read('config/examples/localconfig.php.erb')
45
+
46
+ config = TechnoGate::Contao::Application.config.contao_global_config
47
+
48
+ if !config || config.install_password.blank? || config.encryption_key.blank?
49
+ message = <<-EOS
50
+ You did not set the install password, and the encryption key in your
51
+ #{ENV['HOME']}/.contao/config.yml, I cannot generate a localconfig
52
+ since the required configuration keys are missing.
53
+ EOS
54
+ message.gsub!(/ [ ]+/, ' ').gsub!(/\n/, '').gsub!(/^ /, '')
55
+ logger.important message if logger
56
+ abort 'Required configurations are not set'
57
+ else
58
+ config = config.clone
59
+ config.application_name = TechnoGate::Contao::Application.name
60
+ config.db_server_app = fetch :db_server_app
61
+ config.db_database = fetch :db_database_name
62
+
63
+ [:hostname, :port, :username, :password].each do |item|
64
+ if db_credentials[item].present?
65
+ config.send "db_#{item}=", db_credentials[item]
66
+ end
67
+ end
68
+
69
+ write ERB.new(localconfig).result(binding), localconfig_php_config_path
70
+ end
71
+ end
72
+
73
+ desc '[internal] Link files from contao to inside public folder'
74
+ task :link_contao_files, :roles => :app, :except => { :no_release => true } do
75
+ files = exhaustive_list_of_files_to_link("#{fetch :latest_release}/contao", "#{fetch :latest_release}/public")
76
+ commands = files.map do |list|
77
+ "#{try_sudo} ln -nsf #{list[0]} #{list[1]}"
78
+ end
79
+
80
+ begin
81
+ run commands.join(';')
82
+ rescue Capistrano::CommandError
83
+ abort 'Unable to create to link contao files'
84
+ end
85
+ end
86
+
87
+ desc '[internal] Fix contao symlinks to the shared path'
88
+ task :fix_links, :roles => :app, :except => { :no_release => true } do
89
+ latest_release = fetch :latest_release
90
+ shared_path = fetch :shared_path
91
+
92
+ # Remove files
93
+ run <<-CMD
94
+ #{try_sudo} rm -rf #{latest_release}/public/system/logs
95
+ CMD
96
+
97
+ # Create symlinks
98
+ run <<-CMD
99
+ #{try_sudo} ln -nsf #{shared_path}/logs #{latest_release}/public/system/logs
100
+ CMD
101
+ end
102
+ end
103
+
104
+ # Dependencies
105
+ after 'deploy:setup', 'contao:setup'
106
+ after 'contao:setup', 'contao:setup_shared_folder'
107
+ after 'contao:setup', 'contao:setup_localconfig'
108
+ after 'deploy:finalize_update', 'contao:link_contao_files'
109
+ after 'contao:link_contao_files', 'contao:fix_links'
110
+
111
+ # Assets
112
+ after 'contao:link_contao_files', 'contao:assets:deploy'
113
+
114
+ # Database credentions
115
+ before 'contao:setup_localconfig', 'db:credentials'
116
+ before 'contao:setup_db', 'db:credentials'
117
+ end
@@ -0,0 +1,28 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort 'capistrano/ext/contao requires Capistrano 2'
3
+ end
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+ namespace :contao do
7
+ namespace :assets do
8
+ desc '[internal] Upload contao assets'
9
+ task :deploy, :roles => :app, :except => { :no_release => true } do
10
+ path = File.join 'public', Rails.application.config.assets.prefix
11
+ upload(path, "#{fetch :latest_release}/#{path}", :via => :scp, :recursive => true)
12
+ end
13
+
14
+ desc '[internal] Generate assets'
15
+ task :precompile, :roles => :app, :except => { :no_release => true } do
16
+ run_locally 'bundle exec rake assets:precompile'
17
+ end
18
+
19
+ desc '[internal] Clean assets'
20
+ task :clean, :roles => :app, :except => { :no_release => true } do
21
+ run_locally 'bundle exec rake assets:clean'
22
+ end
23
+ end
24
+ end
25
+
26
+ before 'contao:assets:deploy', 'contao:assets:precompile'
27
+ after 'contao:assets:deploy', 'contao:assets:clean'
28
+ end
@@ -0,0 +1,23 @@
1
+ if Capistrano::Logger.respond_to? :add_color_matcher
2
+ Capistrano::Logger.add_color_matcher({
3
+ :match => /adapter:|hostname:|username:|password:/,
4
+ :color => :red,
5
+ :level => Capistrano::Logger::TRACE,
6
+ :prio => -20,
7
+ :attribute => :blink
8
+ })
9
+
10
+ Capistrano::Logger.add_color_matcher({
11
+ :match => /WARNING:/,
12
+ :color => :yellow,
13
+ :level => Capistrano::Logger::INFO,
14
+ :prio => -20
15
+ })
16
+
17
+ Capistrano::Logger.add_color_matcher({
18
+ :match => /ERROR:/,
19
+ :color => :red,
20
+ :level => Capistrano::Logger::IMPORTANT,
21
+ :prio => -20
22
+ })
23
+ end
@@ -0,0 +1,15 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort 'capistrano/ext/decouple_from_rails requires capistrano 2'
3
+ end
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+ # Prevent capistrano from creating log, system and pids folders.
7
+ set :shared_children, Array.new
8
+
9
+ namespace :deploy do
10
+ desc "Empty task, overriden by #{__FILE__}:#{__LINE__}"
11
+ task :finalize_update do
12
+ # Empty task, we do not want to delete the system folder.
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort 'capistrano/ext/contao requires capistrano 2'
3
+ end
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+ namespace :deploy do
7
+ desc 'Check if the remote is ready, should we run cap deploy:setup?'
8
+ task :check_if_remote_ready, :roles => :app do
9
+ unless remote_file_exists?(shared_path)
10
+ logger.important 'ERROR: The project is not ready for deployment.'
11
+ logger.important 'please run `cap deploy:setup'
12
+ abort
13
+ end
14
+ end
15
+
16
+ desc 'Fix permissions'
17
+ task :fix_permissions, :roles => :app do
18
+ if exists?(:app_owner) or exists?(:app_group)
19
+ run <<-CMD
20
+ #{try_sudo} chown -R \
21
+ #{fetch :app_owner, 'www-data'}:#{fetch :app_group, 'www-data'} \
22
+ #{fetch :deploy_to}/releases \
23
+ #{fetch :deploy_to}/shared
24
+ CMD
25
+ end
26
+
27
+ run "chmod -R g+w #{fetch :latest_release}" if fetch(:group_writable, true)
28
+ end
29
+
30
+ desc '[internal] create the required folders.'
31
+ task :folders, :roles => :app do
32
+ backup_path = fetch :backup_path, "#{fetch :deploy_to}/backups"
33
+
34
+ run <<-CMD
35
+ #{try_sudo} mkdir -p \
36
+ #{fetch :deploy_to} \
37
+ #{backup_path} \
38
+ #{fetch :shared_path}/{items,__system__,config} \
39
+ #{fetch :logs_path, ''}
40
+ CMD
41
+ end
42
+
43
+ desc '[internal] Setup if needed'
44
+ task :setup_if_needed, :roles => :app do
45
+ setup unless main_task == 'deploy:setup'
46
+ end
47
+
48
+ desc '[internal] Symlink public folder'
49
+ task :symlink_public_folders, :roles => :web, :except => { :no_release => true } do
50
+ deploy_to = fetch :deploy_to
51
+
52
+ ['htdocs', 'httpdocs', 'www'].each do |folder|
53
+ if remote_file_exists?("#{deploy_to}/#{folder}")
54
+ begin
55
+ run <<-CMD
56
+ #{try_sudo} mkdir -p #{deploy_to}/old &&
57
+ #{try_sudo} mv #{deploy_to}/#{folder} #{deploy_to}/old/#{folder} &&
58
+ #{try_sudo} ln -nsf #{fetch :public_path} #{deploy_to}/#{folder}
59
+ CMD
60
+ rescue Capistrano::CommandError
61
+ logger.info "WARNING: I could not replace the #{folder} please do so manually"
62
+ end
63
+ logger.info "The #{folder} folder has been moved to the #{deploy_to}/old/#{folder}"
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ # Dependencies
70
+ before 'deploy', 'deploy:check_if_remote_ready'
71
+ after 'deploy:restart', 'deploy:fix_permissions'
72
+ before 'deploy:setup', 'deploy:folders'
73
+ after 'deploy:setup', 'deploy:symlink_public_folders'
74
+ end
@@ -0,0 +1,7 @@
1
+ # https://github.com/capistrano/capistrano/issues/168#issuecomment-4144687
2
+ # XXX: Remove once https://github.com/capistrano/capistrano/pull/175 has been released
3
+ Capistrano::Configuration::Namespaces::Namespace.class_eval do
4
+ def capture(*args)
5
+ parent.capture *args
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-contao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-30 00:00:00.000000000 Z
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -44,14 +44,14 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rspec
47
+ name: capistrano-database
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :development
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
@@ -60,14 +60,30 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: fakefs
63
+ name: capistrano-utils
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- type: :development
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: capistrano-server
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
73
89
  none: false
@@ -75,7 +91,7 @@ dependencies:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
78
- description: Capistrano receipts for Contao deployment
94
+ description: Capistrano recipes for Contao deployment
79
95
  email:
80
96
  - wael.nasreddine@gmail.com
81
97
  executables: []
@@ -88,8 +104,12 @@ files:
88
104
  - README.md
89
105
  - Rakefile
90
106
  - capistrano-contao.gemspec
91
- - lib/capistrano-contao.rb
92
- - lib/capistrano-contao/version.rb
107
+ - lib/capistrano/ext/contao.rb
108
+ - lib/capistrano/ext/contao_assets.rb
109
+ - lib/capistrano/ext/custom_colors.rb
110
+ - lib/capistrano/ext/decouple_from_rails.rb
111
+ - lib/capistrano/ext/deploy.rb
112
+ - lib/capistrano/monkey_patches/fix_capture_conflict.rb
93
113
  homepage: http://technogate.github.com/contao
94
114
  licenses: []
95
115
  post_install_message:
@@ -110,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
130
  version: '0'
111
131
  segments:
112
132
  - 0
113
- hash: -3501654877264623199
133
+ hash: 3411963624336550606
114
134
  requirements: []
115
135
  rubyforge_project:
116
136
  rubygems_version: 1.8.23
@@ -1,7 +0,0 @@
1
- module TechnoGate
2
- module Capistrano
3
- module Contao
4
- VERSION = "0.0.1"
5
- end
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- require "capistrano-contao/version"
2
-
3
- module TechnoGate
4
- module Capistrano
5
- module Contao
6
- # Your code goes here...
7
- end
8
- end
9
- end