Managing shared files and directories with atomic deployments
DeployBot’s atomic deployments are a great tool to ensure that your application updates with zero downtime. This unique property is made possible by storing each release in a separate directory and then just re-pointing your web server to the updated version.
But what if you want your released copies to share some common resources? For example, the files your users uploaded, or application logs. This is where the
shared directory comes into the play. Paired with symbolic links, it makes for the ultimate solution to this problem.
For every shared directory you might have, simply add the following commands to the post-upload part of your deployment process:
ln -s $SHARED/<source_resource> $RELEASE/<target_resource>
Note: Don’t forget to replace
<target_resource> with paths to your source and target files (or directories).
Keep in mind that all these files must exist in the shared directory for symbolic links to work properly. Because of that, you might want to auto-create directories with
mkdir -p $SHARED/<directory_name> and files with
touch $SHARED/<file_name>. Both of these commands are safe to run on every deployments to ensure that the linked files are still present.
# Create and link a directory mkdir -p $SHARED/avatars; ln -s $SHARED/avatars $RELEASE/wp-content/avatars # Create andk a file touch $SHARED/application.log; ln -s $SHARED/application.log $RELEASE/lopplication.log