onedesign / atomic-deploy
A script to easily handle atomic deployments in a Linux environment.
Installs: 1 428
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 9
Forks: 2
Open Issues: 2
pkg:composer/onedesign/atomic-deploy
This package is auto-updated.
Last update: 2025-10-07 09:26:35 UTC
README
This project is based on the concepts presented in Buddy Atomic Deployments. It provides functionality to handle shared files and directories across deployments. While this was built for use with Buddy, it will work in any standard *nix environment.
Dependencies
- PHP 5.5+
- curl
File Structure
deploy-cache/- the location where all files are uploaded to the serverrevisions/- a directory containing all revisionscurrent- a symbolic link to the current revisionshared/- a directory containing files that should be shared across all deploys
Usage
curl -sS https://raw.githubusercontent.com/onedesign/atomic-deployments/master/atomic-deploy.php | php -- --revision=$(date "+%F-%H-%M-%S")
Buddy + Craft 2 Example
Add the following in the "SSH Commands" section after your file upload action in your pipeline:
curl -sS https://raw.githubusercontent.com/onedesign/atomic-deployments/master/atomic-deploy.php | php -- --revision=${execution.to_revision.revision} --symlinks='{"shared/config/.env.php":".env.php","shared/storage":"craft/storage"}'
Options
--revision(required) accepts a string ID for this revision--deploy-diraccepts a base directory for deployments (default: current working directory)--deploy-cache-diraccepts a target cache directory (default:deploy-cachewithin deploy-dir)--revisions-to-keepnumber of old revisions to keep in addition to the current revision (default:20)--symlinksa JSON hash of symbolic links to be created in the revision directory (default:{})--helpprints help and usage instructions--ansiforces ANSI color output--no-ansidisables ANSI color output--quietsupresses unimportant messages--protectPassword protect sites at .oneis.us (default:true)
Symlinks
Symlinks are specified as {"target":"linkname"} and use the native ln utility to create links.
targetis relative to the--deploy-dirpathlinknameis relative to the revision path
For example, specifying this option:
--symlinks='{"shared/config/.env.php":".env.php","shared/logs":"logs"}'
will create symlinks the same way as:
ln -s <deploy-dir>/shared/config/.env.php revisions/<revision>/.env.php
ln -s <deploy-dir>/shared/logs revisions/<revision>/logs
Note: Files and directories that exist where the symlinks are being created will be overwritten. For example, using the above example, this is actually what is happening:
rm -rf revisions/<revision_id>/.env.php \
&& ln -sfn <deploy-dir>/shared/config/.env.php revisions/<revision>/.env.php
rm -rf revisions/<revision_id>/logs \
&& ln -sfn <deploy-dir>/shared/logs revisions/<revision>/logs
Password Protection
By default, the deployment will password protect any site that is served from a *.oneis.us domain name. This works by prepending the contents of the templates/htaccess-auth.txt file to any existing .htaccess file found in the current/web directory. If an .htaccess file does not exist within that directory, one will be generated using the templates/htaccess.txt file.
Testing
cd ./test php ../bin/deploy \ --deploy-cache-dir="./deploy-cache" \ --revision="123456" \ --symlinks='{"shared/config/env":".env","shared/storage":"storage"}'