Last active
July 4, 2018 08:28
-
-
Save LostinOrchid/b8be86745634548113c4d51ed59e7042 to your computer and use it in GitHub Desktop.
Example deployment script for roots bedrock
This file contains 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 | |
# The document root of the project | |
APP_ROOT= | |
# The directory of the remote repository | |
GIT_DIR= | |
# What branch to accept | |
BRANCH="master" | |
composer=~/bin/composer | |
wp=~/bin/wp | |
install_dotenv() | |
{ | |
dotenv_name="aaemnnosttv/wp-cli-dotenv-command" | |
# install dotenv wp cli command | |
if [[ $($wp package list --fields=name | grep -iF "$dotenv_name") != *$dotenv_name* ]]; then | |
echo "Installing $dotenv_name package." | |
echo "php -d memory_limit=-1 $composer require $dotenv_name --working-dir=$(wp package path)" | |
php -d memory_limit=-1 $composer require $dotenv_name --working-dir=$(wp package path) | |
fi | |
} | |
install_wp() | |
{ | |
$wp --version >/dev/null 2>&1 || { | |
echo >&2 "WP CLI does not exists, installing..." | |
cd ~ | |
mkdir -p ~/bin | |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
chmod +x wp-cli.phar | |
mv wp-cli.phar $wp | |
} | |
} | |
install_composer() | |
{ | |
$composer --version >/dev/null 2>&1 || { | |
cd ~ | |
echo >&2 "Composer does not exists, installing..." | |
mkdir -p ~/bin | |
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)" | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")" | |
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] | |
then | |
>&2 echo 'ERROR: Invalid installer signature' | |
rm composer-setup.php | |
exit 1 | |
fi | |
php composer-setup.php --quiet | |
RESULT=$? | |
rm composer-setup.php | |
mv ~/composer.phar $composer | |
} | |
} | |
install_composer | |
install_wp | |
# optional ra ni | |
# install_dotenv | |
while read oldrev newrev ref | |
do | |
# only checking out the master (or whatever branch you would like to deploy) | |
if [[ $ref = refs/heads/$BRANCH ]]; | |
then | |
if [[ -z "$APP_ROOT" ]]; | |
then | |
echo "APP_ROOT must be defined" | |
exit 1; | |
elif [[ -z "$GIT_DIR" ]]; | |
then | |
echo "GIT_DIR must be defined"; | |
fi | |
if [[ ! -d "$APP_ROOT" ]]; | |
then | |
echo "mkdir -p $APP_ROOT" | |
mkdir -p $APP_ROOT >/dev/null 2>&1 || { | |
echo "Cannot create $APP_ROOT, permission denied"; | |
exit 1; | |
} | |
fi | |
echo "Ref $ref received. Deploying ${BRANCH} branch to ${APP_ROOT}..." | |
git --work-tree=$APP_ROOT --git-dir=$GIT_DIR checkout -f | |
composer install --working-dir=$APP_ROOT | |
# Allow group to have read,write access to app root. | |
chown git:apache $APP_ROOT | |
# Folders | |
find $APP_ROOT -type d -exec chmod 0750 {} \; | |
# Files | |
find $APP_ROOT -type f -exec chmod 0644 {} \; | |
else | |
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment