Skip to content

Commit 0f0f66e

Browse files
author
Martin Szymanski
committed
Merge branch 'release/0.6.2'
2 parents 210d757 + 3d380eb commit 0f0f66e

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Git repo – required
22
DEPLOY_REPO=""
33

4+
# Git branch – optional (default: master)
5+
DEPLOY_BRANCH=""
6+
47
# Server root to project – required
58
DEPLOY_ROOT=""
69

@@ -10,5 +13,8 @@ DEPLOY_ASSETS_DIR="uploads"
1013
# Restart PHP if symlinks are cached – optional
1114
DEPLOY_RESTART_PHP=""
1215

16+
# Releases to keep
17+
DEPLOY_KEEP_RELEASES=5
18+
1319
# Backups to keep
1420
DEPLOY_KEEP_BACKUPS=5

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Things change, people change, everything changes.
44

5+
## [0.6.2](https://github.com/elfacht/craft-deploy/compare/0.6.1...0.6.2) - 2019-07-22
6+
### Added
7+
- Added `DEPLOY_KEEP_RELEASES` constant.
8+
- Added `DEPLOY_BRANCH` constant to clone specific branch.
9+
- `setup.sh` will now create an empty log file.
10+
- `setup.sh` will now rename `.env.example` to `.env`.
11+
512
## [0.6.1](https://github.com/elfacht/craft-deploy/compare/0.6.0...0.6.1) - 2019-07-15
613
### Added
714
- Added `DEPLOY_KEEP_BACKUPS` option and function.

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ A bash script for zero-downtime Craft CMS deployment to run on production server
55
## Usage
66

77
- Copy the files to your project folder on the server.
8-
- Rename `.env.example` to `.env` and enter your credentials.
98
- Run `chmod +x deploy.sh setup.sh` to set execution permissions.
10-
- Run `./setup.sh` to create the initial folders.
9+
- Run `./setup.sh` to create the initial folders and files.
1110
- Upload `.env` into `shared/`.
1211
- Upload `storage` folder into `shared/`.
1312
- Upload `web/.htaccess` into `shared/web/`.
@@ -44,7 +43,7 @@ Creates the necessary `releases`, `shared` and `shared/web` folders on the serve
4443
- Creates symlinks for shared folders and files.
4544
- Runs `./craft migrate/all` and `./craft project-config/sync`.
4645
- Creates a symlink from the `current` folder to the newest release.
47-
- Deletes old releases and keeps max. 5 releases.
46+
- Deletes old releases and keeps max. `[DEPLOY_KEEP_RELEASES]` releases.
4847
- Deletes oldest backup and keeps max. `[DEPLOY_KEEP_BACKUPS]` backups.
4948
- Restarts PHP to delete symlink cache (optional)
5049

@@ -62,7 +61,7 @@ When you don't want to spend money on deployment services and tools like Capistr
6261

6362
## Roadmap
6463

65-
- Add `.env` for better config handling.
64+
- ~~Add `.env` for better config handling.~~
6665
- ~~Delete releases folder if an error occurs during deployment.~~
6766
- ~~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)
6867
- ~~Integrate `update.sh` scripts into `deploy.sh` and/or create flags.~~

deploy.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
# Craft CMS deployment script on staging/production servers.
44
# @see https://github.com/elfacht/craft-deploy
55
#
6-
# @version 0.6.0
7-
#
86
# - Creating a release folder
97
# - Cloning the git repo.
108
# - Creating symlinks to shared folders and files.
119
# - Symlink on current folder to newest release.
12-
# - Deleting old releases (keeping max. 5)
10+
# - Deleting old releases and backups
1311
#
1412
# @author
1513
# Martin Szymanski <martin@elfacht.com>
@@ -21,9 +19,12 @@
2119
#######################################
2220
# Get constants from .env file:
2321
# - Git repo URL
22+
# - Git repo branch
2423
# - Server root path to project
2524
# - Assets directory name (web/[ASSETS_DIR])
2625
# - Restart PHP task (if symlinks are cached)
26+
# - Releases to keep
27+
# - Backups to keep
2728
#######################################
2829
read_var() {
2930
VAR=$(grep $1 $2 | xargs)
@@ -32,11 +33,22 @@ read_var() {
3233
}
3334

3435
GIT_REPO=$(read_var DEPLOY_REPO .env)
36+
GIT_BRANCH=$(read_var DEPLOY_BRANCH .env)
3537
ROOT_PATH=$(read_var DEPLOY_ROOT .env)
3638
ASSETS_DIR=$(read_var DEPLOY_ASSETS_DIR .env)
3739
RESTART_PHP=$(read_var DEPLOY_RESTART_PHP .env)
40+
KEEP_RELEASES=$(read_var DEPLOY_KEEP_RELEASES .env)
3841
KEEP_BACKUPS=$(read_var DEPLOY_KEEP_BACKUPS .env)
3942

43+
#######################################
44+
# Set git branch variable
45+
#######################################
46+
if [ -z "$GIT_BRANCH" ]; then
47+
BRANCH=""
48+
else
49+
BRANCH="--branch $GIT_BRANCH"
50+
fi
51+
4052
#######################################
4153
# Exit if any command fails
4254
#######################################
@@ -85,7 +97,7 @@ if [ -d "./releases/" ]; then
8597
echo "Created release $CURRENT_RELEASE folder."
8698

8799
### Clone repo
88-
git clone $GIT_REPO .
100+
git clone $GIT_REPO $BRANCH .
89101
else
90102
exit 1
91103
fi
@@ -141,7 +153,7 @@ if composer install --no-interaction --prefer-dist --optimize-autoloader; then
141153
# delete old release directories
142154
#######################################
143155
COUNT=`/bin/ls -l $ROOT_PATH/releases | /usr/bin/wc -l`
144-
MINDIRS=6 # Keep 5 releases
156+
MINDIRS=$KEEP_RELEASES+1 # Keep XX releases
145157

146158
if [[ $COUNT -gt $MINDIRS ]]; then
147159
OLDEST_RELEASE=$(ls -tr releases/* | head -1)

setup.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,16 @@ then
2121
printf -- "Create shared folder. \n"
2222
mkdir shared && cd "$_"
2323
mkdir web
24-
fi
24+
fi
25+
26+
if [ ! -f "./deploy.log" ]
27+
then
28+
printf -- "Create empty log file. \n"
29+
touch deploy.log
30+
fi
31+
32+
if [ ! -f "./.env.example" ]
33+
then
34+
printf -- "Rename .env.example. \n"
35+
mv .env.example .env
36+
fi

0 commit comments

Comments
 (0)