From 4e84d6fba38ce0ba1b42281bfdec9f9c7a6c8ec5 Mon Sep 17 00:00:00 2001 From: Martin Szymanski Date: Mon, 15 Jul 2019 15:39:34 +0200 Subject: [PATCH 1/5] Complete roadmap task --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98dc23f..bd172e5 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ When you don't want to spend money on deployment services and tools like Capistr ## Roadmap -- Add `.env` for better config handling. +- ~~Add `.env` for better config handling.~~ - ~~Delete releases folder if an error occurs during deployment.~~ - ~~Delete not only the oldest release folder, but multiple release folders if there's more than 5 folders (occurs if an deployment fails).~~ (Corrupt folders will be removed if installation fails) - ~~Integrate `update.sh` scripts into `deploy.sh` and/or create flags.~~ From eb0fbecb458c6fda0b6cbfff46c048520b6e65e9 Mon Sep 17 00:00:00 2001 From: Martin Szymanski Date: Mon, 22 Jul 2019 11:41:23 +0200 Subject: [PATCH 2/5] Add new .env constants; Add setup functions --- .env.example | 3 +++ CHANGELOG.md | 6 ++++++ deploy.sh | 3 ++- setup.sh | 14 +++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 2c64159..601fb4b 100644 --- a/.env.example +++ b/.env.example @@ -10,5 +10,8 @@ DEPLOY_ASSETS_DIR="uploads" # Restart PHP if symlinks are cached – optional DEPLOY_RESTART_PHP="" +# Releases to keep +DEPLOY_KEEP_RELEASES=5 + # Backups to keep DEPLOY_KEEP_BACKUPS=5 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b5abe7..5917045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Things change, people change, everything changes. +## Unreleased +### Added +- Added `DEPLOY_KEEP_RELEASES` constant. +- `setup.sh` will now create an empty log file. +- `setup.sh` will now rename `.env.example` to `.env`. + ## [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. diff --git a/deploy.sh b/deploy.sh index 77e3783..70480ee 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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_RELEASES=$(read_var DEPLOY_KEEP_RELEASES .env) KEEP_BACKUPS=$(read_var DEPLOY_KEEP_BACKUPS .env) ####################################### @@ -141,7 +142,7 @@ if composer install --no-interaction --prefer-dist --optimize-autoloader; then # delete old release directories ####################################### COUNT=`/bin/ls -l $ROOT_PATH/releases | /usr/bin/wc -l` - MINDIRS=6 # Keep 5 releases + MINDIRS=$KEEP_RELEASES+1 # Keep XX releases if [[ $COUNT -gt $MINDIRS ]]; then OLDEST_RELEASE=$(ls -tr releases/* | head -1) diff --git a/setup.sh b/setup.sh index de23298..879f136 100644 --- a/setup.sh +++ b/setup.sh @@ -21,4 +21,16 @@ then printf -- "Create shared folder. \n" mkdir shared && cd "$_" mkdir web -fi \ No newline at end of file +fi + +if [ ! -f "./deploy.log" ] +then + printf -- "Create empty log file. \n" + touch deploy.log +fi + +if [ ! -f "./.env.example" ] +then + printf -- "Rename .env.example. \n" + mv .env.example .env +fi From d3e4359b7ab8d58a221602e6d256a3baa0167c72 Mon Sep 17 00:00:00 2001 From: Martin Szymanski Date: Mon, 22 Jul 2019 11:43:14 +0200 Subject: [PATCH 3/5] Change instructions --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd172e5..32e79c5 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,8 @@ A bash script for zero-downtime Craft CMS deployment to run on production server ## Usage - Copy the files to your project folder on the server. -- Rename `.env.example` to `.env` and enter your credentials. - Run `chmod +x deploy.sh setup.sh` to set execution permissions. -- Run `./setup.sh` to create the initial folders. +- Run `./setup.sh` to create the initial folders and files. - Upload `.env` into `shared/`. - Upload `storage` folder into `shared/`. - Upload `web/.htaccess` into `shared/web/`. @@ -44,7 +43,7 @@ Creates the necessary `releases`, `shared` and `shared/web` folders on the serve - Creates symlinks for shared folders and files. - 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 old releases and keeps max. `[DEPLOY_KEEP_RELEASES]` releases. - Deletes oldest backup and keeps max. `[DEPLOY_KEEP_BACKUPS]` backups. - Restarts PHP to delete symlink cache (optional) From 675842a63a1d53461eaa88fe28f7fd3715e72780 Mon Sep 17 00:00:00 2001 From: Martin Szymanski Date: Mon, 22 Jul 2019 12:12:43 +0200 Subject: [PATCH 4/5] Add DEPLOY_BRANCH constant --- .env.example | 3 +++ CHANGELOG.md | 1 + deploy.sh | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 601fb4b..c0ad576 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,9 @@ # Git repo – required DEPLOY_REPO="" +# Git branch – optional (default: master) +DEPLOY_BRANCH="" + # Server root to project – required DEPLOY_ROOT="" diff --git a/CHANGELOG.md b/CHANGELOG.md index 5917045..03556f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Things change, people change, everything changes. ## Unreleased ### Added - Added `DEPLOY_KEEP_RELEASES` constant. +- Added `DEPLOY_BRANCH` constant to clone specific branch. - `setup.sh` will now create an empty log file. - `setup.sh` will now rename `.env.example` to `.env`. diff --git a/deploy.sh b/deploy.sh index 70480ee..f96219e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -3,13 +3,11 @@ # Craft CMS deployment script on staging/production servers. # @see https://github.com/elfacht/craft-deploy # -# @version 0.6.0 -# # - Creating a release folder # - Cloning the git repo. # - Creating symlinks to shared folders and files. # - Symlink on current folder to newest release. -# - Deleting old releases (keeping max. 5) +# - Deleting old releases and backups # # @author # Martin Szymanski @@ -21,9 +19,12 @@ ####################################### # Get constants from .env file: # - Git repo URL +# - Git repo branch # - Server root path to project # - Assets directory name (web/[ASSETS_DIR]) # - Restart PHP task (if symlinks are cached) +# - Releases to keep +# - Backups to keep ####################################### read_var() { VAR=$(grep $1 $2 | xargs) @@ -32,12 +33,22 @@ read_var() { } GIT_REPO=$(read_var DEPLOY_REPO .env) +GIT_BRANCH=$(read_var DEPLOY_BRANCH .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_RELEASES=$(read_var DEPLOY_KEEP_RELEASES .env) KEEP_BACKUPS=$(read_var DEPLOY_KEEP_BACKUPS .env) +####################################### +# Set git branch variable +####################################### +if [ -z "$GIT_BRANCH" ]; then + BRANCH="" +else + BRANCH="--branch $GIT_BRANCH" +fi + ####################################### # Exit if any command fails ####################################### @@ -86,7 +97,7 @@ if [ -d "./releases/" ]; then echo "Created release $CURRENT_RELEASE folder." ### Clone repo - git clone $GIT_REPO . + git clone $GIT_REPO $BRANCH . else exit 1 fi From 3d380eb63638e2d6d2570fd8be8635b0c01d6c59 Mon Sep 17 00:00:00 2001 From: Martin Szymanski Date: Mon, 22 Jul 2019 12:13:35 +0200 Subject: [PATCH 5/5] Bump version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03556f7..840fcbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ Things change, people change, everything changes. -## Unreleased +## [0.6.2](https://github.com/elfacht/craft-deploy/compare/0.6.1...0.6.2) - 2019-07-22 ### Added - Added `DEPLOY_KEEP_RELEASES` constant. - Added `DEPLOY_BRANCH` constant to clone specific branch.