Skip to content

Commit

Permalink
Merge branch 'release/0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Szymanski committed Jul 15, 2019
2 parents db7a4e2 + 94b6ee4 commit 210d757
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ DEPLOY_ASSETS_DIR="uploads"

# Restart PHP if symlinks are cached – optional
DEPLOY_RESTART_PHP=""

# Backups to keep
DEPLOY_KEEP_BACKUPS=5
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Things change, people change, everything changes.

## [0.6.1](https://github.com/elfacht/craft-deploy/compare/0.6.0...0.6.1) - 2019-07-15
### Added
- Added `DEPLOY_KEEP_BACKUPS` option and function.

## [0.6.0](https://github.com/elfacht/craft-deploy/compare/0.5.0...0.6.0) - 2019-07-08
### Added
- Added `.env` environment to separate config from code.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Creates the necessary `releases`, `shared` and `shared/web` folders on the serve
- Runs `./craft migrate/all` and `./craft project-config/sync`.
- Creates a symlink from the `current` folder to the newest release.
- Deletes old releases and keeps max. 5 releases.
- Deletes oldest backup and keeps max. `[DEPLOY_KEEP_BACKUPS]` backups.
- Restarts PHP to delete symlink cache (optional)

### gitlab-webhook-push.php
Expand Down
24 changes: 24 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ GIT_REPO=$(read_var DEPLOY_REPO .env)
ROOT_PATH=$(read_var DEPLOY_ROOT .env)
ASSETS_DIR=$(read_var DEPLOY_ASSETS_DIR .env)
RESTART_PHP=$(read_var DEPLOY_RESTART_PHP .env)
KEEP_BACKUPS=$(read_var DEPLOY_KEEP_BACKUPS .env)

#######################################
# Exit if any command fails
Expand Down Expand Up @@ -158,6 +159,29 @@ if composer install --no-interaction --prefer-dist --optimize-autoloader; then
printf -- ' DONE!\n';
fi

#######################################
# Kepp max. X backups,
# delete oldest backup
#######################################
COUNT=`/bin/ls -l $ROOT_PATH/shared/storage/backups | /usr/bin/wc -l`
MINBACKUPS=$KEEP_BACKUPS+1 # Keep X releases

if [[ $COUNT -gt $MINBACKUPS ]]; then
OLDEST_BACKUP=$(ls -tr $ROOT_PATH/shared/storage/backups/* | head -1)
printf -- "- Delete oldest backup '$OLDEST_BACKUP' .."

DONE=0;
while [ $DONE -eq 0 ]; do
rm -rf $OLDEST_BACKUP

if [ "$?" = "0" ]; then DONE=1; fi;
printf -- '.';
sleep 1;
done

printf -- ' DONE!\n';
fi

#######################################
# Restart PHP
#######################################
Expand Down

0 comments on commit 210d757

Please sign in to comment.