Skip to content

Instantly share code, notes, and snippets.

@pmatseykanets
Last active March 17, 2018 01:40
Show Gist options
  • Save pmatseykanets/8a58d174663abeb12b4d28fc99ebedb7 to your computer and use it in GitHub Desktop.
Save pmatseykanets/8a58d174663abeb12b4d28fc99ebedb7 to your computer and use it in GitHub Desktop.
Forge Deploy script
APP_DIR=/home/forge/sub.domain.com
RELEASE=$(date +%Y%m%d%H%M%S)
RELEASE_DIR=$APP_DIR/releases/$RELEASE
ARCHIVE=$RELEASE.tar.gz
PHP=php7.1
[ -d $APP_DIR/releases ] || mkdir $APP_DIR/releases
cd $APP_DIR/releases
mkdir $RELEASE_DIR
cd $RELEASE_DIR
# Get the repo archive from a git ref (master in this case)
# GitHub
curl -L https://api.github.com/repos/username/repo/tarball/master?access_token=<TOKEN> > $ARCHIVE
# wget https://api.github.com/repos/username/repo/tarball/master?access_token=<TOKEN> -O $ARCHIVE
# GitLab
# curl -H "PRIVATE-TOKEN: <TOKEN>" https://gitlab.com/username/repo/repository/archive.tar.gz?ref=master > $ARCHIVE
# wget --header "PRIVATE-TOKEN: <TOKEN>" "https://gitlab.com/username/repo/repository/archive.tar.gz?ref=master" -O $ARCHIVE
tar -zxvf $ARCHIVE --strip=1 > /dev/null
rm -f $ARCHIVE
# install php denendencies
composer install --no-interaction --prefer-dist --no-dev --quiet --optimize-autoloader
# Link storage
rm -rf storage
ln -nfs $APP_DIR/storage storage;
# Link .env
ln -nfs $APP_DIR/.env .env;
# link the current dir
cd $APP_DIR
ln -nfs $RELEASE_DIR current
cd $RELEASE_DIR
php artisan config:clear
php artisan cache:clear
php artisan clear-compiled
php artisan optimize
#php artisan view:clear
sudo service "$PHP-fpm" restart
# sudo supervisorctl restart all
# Remove old releases
cd $APP_DIR/releases
ls -dt ./* | tail -n +6 | xargs -d "\n" rm -rf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment