Skip to content

Commit

Permalink
Update run
Browse files Browse the repository at this point in the history
- Added check for never version
- Added -v parameter to display the current version
- Improved deployment process
  • Loading branch information
magefan authored Dec 13, 2019
1 parent 265ed69 commit 1d6c47d
Showing 1 changed file with 76 additions and 21 deletions.
97 changes: 76 additions & 21 deletions run
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
#!/bin/bash
CURRENT_VERSION=1.0.2

usage()
{
echo "usage: bash deploy/run.sh [-a] | [-u] | [-d] | [-s] | [-m]"
echo "usage: bash deploy/run.sh [-a] | [-u] | [-d] | [-s] | [-m] | [-v]"
}

vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}

NEW_VERSION=$(curl -s "https://api.github.com/repos/magefan/magento2-zero-downtime-deploy/releases/latest" | awk -F '"' '/tag_name/{print $4}')
if [ $NEW_VERSION ]; then
vercomp $NEW_VERSION $CURRENT_VERSION
case $? in
1)
echo -e "\e[32m${1}There is a new Zero Downtime v$NEW_VERSION available. Your current version is $CURRENT_VERSION \e[0m"
echo -e "\e[32m${1}To install the newest version remove the current one and install the script again:\e[0m"
echo -e "\e[32m${1}https://magefan.com/blog/magento-2-zero-downtime-deployment\e[0m"

;;
esac
fi

if [ $# -gt 0 ]; then
echo ''
else
Expand All @@ -25,6 +70,10 @@ while [ "$1" != "" ]; do
-s | --static-content )
SETUP_STATIC_CONTENT=1
;;
-v | --version )
echo $CURRENT_VERSION
exit
;;
-m | --modules )
#do nothing here
;;
Expand Down Expand Up @@ -54,6 +103,7 @@ MDIR="$PWD"
DIR="$PWD/deploy"
cd $DIR
INSTANCE="$PWD/instance"
MAGE_INIT_PARAMS="--magento-init-params=MAGE_DIRS[base][path]=$INSTANCE&MAGE_DIRS[cache][path]=$INSTANCE/var/cache"

SEK=SECONDS
echo 'Remove old files ...'
Expand All @@ -69,52 +119,50 @@ mkdir -p var;

cp -rf $MDIR/app app
cp -rf $MDIR/bin bin
cp -rf $MDIR/dev dev
cp -rf $MDIR/lib lib
cp -rf $MDIR/setup setup
cp -rf $MDIR/vendor vendor
cp -rf $MDIR/phpserver phpserver
cp -rf $MDIR/update update
cp -rf $MDIR/composer.json composer.json
cp -rf $MDIR/composer.lock composer.lock


# temporary copy env.php file with save cache local
rm app/etc/env.php
cp -rf $DIR/app/env.php app/etc/env.php


ln -sfn $MDIR/deploy deploy
ln -sfn $MDIR/dev dev
ln -sfn $MDIR/lib lib
ln -sfn $MDIR/phpserver phpserver


ln -sfn $MDIR/update update
ln -sfn $MDIR/composer.json composer.json
ln -sfn $MDIR/composer.lock composer.lock


if [ "$SETUP_MODULES" ]; then
echo 'Enabling modules ...'
$INSTANCE/bin/magento module:enable $SETUP_MODULES
bin/magento module:enable $SETUP_MODULES $MAGE_INIT_PARAMS
fi

echo 'Start deploying ...'

if [ $SETUP_ALL ] || [ $SETUP_DI ]; then
$INSTANCE/bin/magento setup:di:compile
bin/magento setup:di:compile
fi

if [ $SETUP_ALL ] || [ $SETUP_STATIC_CONTENT ]; then
#$INSTANCE/bin/magento setup:static-content:deploy
. "$DIR/app/static-content-deploy.sh"
cd $INSTANCE
fi


if [ $SETUP_ALL ]; then
$MDIR/bin/magento maintenance:enable
$MDIR/bin/magento setup:upgrade
cd $MDIR
bin/magento maintenance:enable
cd $INSTANCE
bin/magento setup:upgrade --keep-generated $MAGE_INIT_PARAMS
fi


if [ $SETUP_ALL ]; then
GENERATED_FOLDERS=( "generated" "pub/static/adminhtml" "pub/static/frontend" "pub/static/deployed_version.txt" "var/view_preprocessed" )
GENERATED_FOLDERS=( "app/etc/config.php" "generated" "pub/static/adminhtml" "pub/static/frontend" "pub/static/deployed_version.txt" "var/view_preprocessed" )
else
GENERATED_FOLDERS=()
GENERATED_FOLDERS=( "app/etc/config.php" )
if [ $SETUP_DI ]; then
GENERATED_FOLDERS+=( "generated")
fi
Expand Down Expand Up @@ -150,7 +198,14 @@ do
done

if [ $SETUP_ALL ]; then
$MDIR/bin/magento maintenance:disable
cd $MDIR
bin/magento maintenance:disable
fi

$MDIR/bin/magento c:f
cd $MDIR
bin/magento c:f

echo 'Remove tmp files ...'
rm -rf $INSTANCE

echo 'Finished.'

0 comments on commit 1d6c47d

Please sign in to comment.