Last active
May 13, 2016 18:56
-
-
Save sheadawson/1179ce63372c673f22bb to your computer and use it in GitHub Desktop.
SilverStripe Simple Bash Deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOST="[email protected] -pxxxx" | |
if [ ! $1 ]; then | |
ENVIRONMENT='prod' | |
else | |
ENVIRONMENT=${1} | |
fi | |
ssh $HOST << EOF | |
cd ~ | |
chmod +x deploy-"$ENVIRONMENT".sh | |
./deploy-"$ENVIRONMENT".sh | |
EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Settings | |
PROJECT_DIR="/home/[USER]/public_html/[PROJECT]" | |
REPO="[email protected]:livesource/project.git" | |
BRANCH="master" | |
PHP_EXEC="php" | |
COMPOSER_EXEC="php composer.phar" | |
# Gimme some color! | |
NC="\033[0m" | |
RED="\033[0;31m" | |
YELLOW="\033[0;33m" | |
GREEN="\033[0;32m" | |
# make sure TARGET_DIR exists and contains project | |
if [ ! -d "$PROJECT_DIR" ]; then | |
printf "\n${YELLOW}Cloning project into $PROJECT_DIR ${NC}\n" | |
printf "\n${GREEN}\$ git clone $REPO $PROJECT_DIR ${NC}\n" | |
git clone $REPO $PROJECT_DIR | |
fi | |
printf "\n${GREEN}\$ cd $PROJECT_DIR ${NC}\n" | |
cd $PROJECT_DIR | |
# update repository | |
printf "\n${GREEN}\$ git fetch origin ${NC}\n" | |
git fetch origin | |
printf "\n${GREEN}\$ git checkout $BRANCH ${NC}\n" | |
git checkout $BRANCH | |
printf "\n${GREEN}\$ git fetch origin $BRANCH ${NC}\n" | |
git fetch origin $BRANCH | |
printf "\n${GREEN}\$ git reset --hard FETCH_HEAD ${NC}\n" | |
git reset --hard FETCH_HEAD | |
# write version file | |
printf "\n${YELLOW}Writing VERSION file${NC}\n" | |
printf "\n${GREEN}\$ git describe --always > VERSION ${NC}\n" | |
git describe --always > "VERSION" | |
# remove deploy.sh file | |
if [ -f "deploy.sh" ]; then | |
printf "\n${GREEN}\$ rm deploy.sh ${NC}\n" | |
rm deploy.sh | |
fi | |
# run composer | |
printf "\n${YELLOW}Installing dependencies${NC}\n" | |
printf "\n${GREEN}\$ $COMPOSER_EXEC --no-interaction install ${NC}\n" | |
eval "$COMPOSER_EXEC --no-interaction install" | |
if [ -f "${PROJECT_DIR}_ss_environment.php" ]; then | |
# run dev/build | |
printf "\n${YELLOW}Running dev/build${NC}\n" | |
printf "\n${GREEN}\$ $PHP_EXEC framework/cli-script.php dev/build flush=all ${NC}\n" | |
eval "$PHP_EXEC framework/cli-script.php dev/build flush=all" | |
# clear dynamic cache | |
printf "\n${YELLOW}Clearing dynamic cache${NC}\n" | |
printf "\n${GREEN}\$ $PHP_EXEC framework/cli-script.php dev/tasks/ClearDynamicCacheTask ${NC}\n" | |
eval "$PHP_EXEC framework/cli-script.php dev/tasks/ClearDynamicCacheTask" | |
else | |
printf "\n${YELLOW}Please create a _ss_environment.php file for this project and run this script again to complete deployment${NC}\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment