Skip to content

Commit

Permalink
Merge branch 'release/0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Szymanski committed Jul 22, 2019
2 parents 210d757 + 3d380eb commit 0f0f66e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Git repo – required
DEPLOY_REPO=""

# Git branch – optional (default: master)
DEPLOY_BRANCH=""

# Server root to project – required
DEPLOY_ROOT=""

Expand All @@ -10,5 +13,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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Things change, people change, everything changes.

## [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.
- `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.
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/`.
Expand Down Expand Up @@ -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)

Expand All @@ -62,7 +61,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.~~
Expand Down
22 changes: 17 additions & 5 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <martin@elfacht.com>
Expand All @@ -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)
Expand All @@ -32,11 +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
#######################################
Expand Down Expand Up @@ -85,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
Expand Down Expand Up @@ -141,7 +153,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)
Expand Down
14 changes: 13 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ then
printf -- "Create shared folder. \n"
mkdir shared && cd "$_"
mkdir web
fi
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

0 comments on commit 0f0f66e

Please sign in to comment.