Luke Cousins asked:
We have a website and our deployment process goes somewhat like the following (with lots of irrelevant steps excluded)
echo "Remove previous, if it exists, we don't need that anymore" rm -rf /home/[XXX]/php_code/previous echo "Create the current dir if it doesn't exist (just in case this is the first deploy to this server)" mkdir -p /home/[XXX]/php_code/current echo "Create the var_www dir if it doesn't exist (just in case this is the first deploy to this server)" mkdir -p /home/[XXX]/var_www echo "Copy current to previous so we can use temporarily" cp -R /home/[XXX]/php_code/current/* /home/[XXX]/php_code/previous/ echo "Atomically swap the symbolic link to use previous instead of current" ln -s /home/[XXX]/php_code/previous /home/[XXX]/var_www/live_tmp && mv -Tf /home/[XXX]/var_www/live_tmp /home/[XXX]/var_www/live # Rsync latest code into the current dir, code not shown here echo "Atomically swap the symbolic link to use current instead of previous" ln -s /home/[XXX]/php_code/current /home/[XXX]/var_www/live_tmp && mv -Tf /home/[XXX]/var_www/live_tmp /home/[XXX]/var_www/live
The problem we are having and would like help with is that, the first thing any website page load does is work out the base dir of the application and define it as a constant (we use PHP). If then during that page load a deployment occurs, the system tries to
include() a file using the original full path and will get the new version of that file. We need it to get the old one from the old dir which has now moved as in:
System starts page load and determines
SYSTEM_ROOT_PATHconstant to be
/home/[XXX]/var_www/liveor by using PHP’s
realpath()it could be
/home/[XXX]/var_www/liveget updated to point to
/home/[XXX]/php_code/currentwhere it did originally.
System tries to load
I’m sorry if that is not explained very well. I’d really appreciate some ideas on how to get around this problem if someone can. Thank you.
current should not be an actual directory containing your files, but a symbolic link. This is the way capistrano does it:
- Create a directory named with the current date.
- Deploy the new files to that directory.
- Change the
currentsymlink to point to the new directory.
- Delete any old unwanted directories.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.