Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Introducing a core config namespace #8

Open
wants to merge 1 commit into from

2 participants

Damien Varron Jad Bitar
Damien Varron

I reintroduced the ability to separate local core.php config file from production one in a cleaner way.

Jad Bitar
Owner

Thanks, maybe I am missing something.

How are you separating the local core.php from the one being deployed exactly? I see that you are merely moving the core.php file tracked by the repo (which means the same one exists in your local clone) into the shared path. Maybe I am missing something?

Usually speaking, files that end up in the shared path are not tracked by the repo. In core.php case, the file wouldn't be tracked by the repo, another version of it like core.php.example would be tracked and a modified copy of it would be stored remotely in the shared path before symlink-ing to it from the latest deployed release.

Damien Varron

Moving the core.php file tracked by the repo into the shared path only occurs at config time (first time) or if manually triggered. Then, at each deploy, the core.php file tracked by the repo will be deleted and a symlink will be created to the shared one. Same as for the database.php file actually, only without the config prompt. This means that you have to get your core.php file right before the first deploy, or manually change it afterwards, or manually update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2012
  1. Damien Varron
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 1 deletion.
  1. +37 −1 lib/capcake.rb
38 lib/capcake.rb
View
@@ -47,11 +47,14 @@ def capcake()
if cake2
set :shared_children, %w(Config System tmp)
set :database_partial_path, "Config/database.php"
+ set :core_partial_path, "Config/core.php"
else
set :shared_children, %w(config system tmp)
set :database_partial_path, "config/database.php"
+ set :core_partial_path, "config/core.php"
end
set(:database_path) { File.join(shared_path, database_partial_path) }
+ set(:core_path) { File.join(shared_path, core_partial_path) }
set(:shared_path) { File.join(deploy_to, shared_dir) }
_cset(:cake_path) { shared_path }
_cset(:tmp_path) { File.join(shared_path, "tmp") }
@@ -106,6 +109,7 @@ def remote_file_exists?(full_path)
set :git_flag_quiet, "-q "
cake.setup if (!cake_branch.empty?)
cake.database.config if (!remote_file_exists?(database_path))
+ cake.core.config if (!remote_file_exists?(core_path))
end
desc <<-DESC
@@ -120,7 +124,7 @@ def remote_file_exists?(full_path)
transaction do
update_code
symlink
- cake.cache.clear
+ cake.cache.clear
end
end
@@ -172,6 +176,7 @@ def remote_file_exists?(full_path)
run "ln -s #{shared_path}/system #{latest_release}/webroot/system && ln -s #{shared_path}/tmp #{latest_release}/tmp";
run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
cake.database.symlink if (remote_file_exists?(database_path))
+ cake.core.symlink if (remote_file_exists?(core_path))
end
desc <<-DESC
@@ -500,6 +505,7 @@ def remote_file_exists?(full_path)
put(result, "#{database_path}", :mode => 0644, :via => :scp)
after("deploy:symlink", "cake:database:symlink")
end
+
desc <<-DESC
Creates MySQL database, database user and grants permissions on DB servers
DESC
@@ -527,12 +533,14 @@ def remote_file_exists?(full_path)
run "mysql -u #{mysql_admin_user} -p#{mysql_admin_password} < #{tmp_filename}"
run "#{try_sudo} rm #{tmp_filename}"
end
+
desc <<-DESC
Creates database tables on primary DB servers
DESC
task :schema, :roles => :db, :primary => true, :except => { :no_release => true } do
# ...
end
+
desc <<-DESC
Creates required CakePHP's APP/config/database.php as a symlink to \
#{deploy_to}/shared/config/database.php
@@ -542,6 +550,34 @@ def remote_file_exists?(full_path)
end
end
+ namespace :core do
+ desc <<-DESC
+ Force updates CakePHP core configuration file with the latest deployed
+ DESC
+ task :reset, :roles => :web, :except => { :no_release => true } do
+ run "#{try_sudo} rm -f #{core_path}" if (remote_file_exists?(core_path))
+ cake.core.config
+ end
+
+ desc <<-DESC
+ Generates CakePHP core configuration file in #{shared_path}/config \
+ as a copy of the latest #{current_path}/config/core.php \
+ and symlinks #{current_path}/config/core.php to it
+ DESC
+ task :config, :roles => :web, :except => { :no_release => true } do
+ run "cp -p #{current_path}/#{core_partial_path} #{core_path}" if (!remote_file_exists?(core_path))
+ cake.core.symlink
+ end
+
+ desc <<-DESC
+ Creates required CakePHP's APP/config/core.php as a symlink to \
+ #{deploy_to}/shared/config/core.php
+ DESC
+ task :symlink, :roles => :web, :except => { :no_release => true } do
+ run "#{try_sudo} rm -f #{current_path}/#{core_partial_path} && #{try_sudo} ln -s #{core_path} #{current_path}/#{core_partial_path}"
+ end
+ end
+
namespace :logs do
desc <<-DESC
Clears CakePHP's APP/tmp/logs and its sub-directories
Something went wrong with that request. Please try again.