Last active
March 30, 2018 20:32
-
-
Save vikbert/27701d2edfb7f13985aae50a91712c28 to your computer and use it in GitHub Desktop.
[deploy shell] deploy deploy and callback with shell script #shell, #deployment
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
#!/usr/bin/env bash | |
ARTIFACTS=shop.tar.gz | |
TARGET_BASE=/srv/www | |
TARGET_ARCHIVE=$TARGET_BASE/$ARTIFACTS | |
TARGET_LOCATION=$TARGET_BASE/shop | |
case "$1" in | |
deploy) | |
echo 'backing up artifacts ...' | |
if [ -f $TARGET_ARCHIVE ]; | |
then | |
mv $TARGET_ARCHIVE $TARGET_ARCHIVE.bak | |
fi | |
cp -f /home/gitlab-runner/$ARTIFACTS $TARGET_ARCHIVE | |
echo "cleaning old deployment ..." | |
rm -rf $TARGET_LOCATION/* | |
echo "deploying ..." | |
if [ -f $TARGET_LOCATION ]; | |
then | |
mkdir -p TARGET_LOCATION | |
fi | |
tar xfvz $TARGET_ARCHIVE -C $TARGET_LOCATION | |
echo 'cleaning caching ...' | |
sudo rm -rf /var/cache/shop/prod/* | |
;; | |
rollback) | |
echo "rolling back ..." | |
rm -rf $TARGET_LOCATION/* | |
mv $TARGET_ARCHIVE.bak $TARGET_ARCHIVE | |
tar xfvz $TARGET_ARCHIVE -C $TARGET_LOCATION | |
echo 'cleaning caching' | |
sudo rm -rf /var/cache/shop/prod/* | |
;; | |
*) | |
echo "usage: $0 [deploy] [rollback]" | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment