Skip to content

Instantly share code, notes, and snippets.

@elenakondrateva
Last active June 28, 2017 00:09
Show Gist options
  • Save elenakondrateva/7958e99d569f53a53256ffd8c0339f50 to your computer and use it in GitHub Desktop.
Save elenakondrateva/7958e99d569f53a53256ffd8c0339f50 to your computer and use it in GitHub Desktop.
Magento2 deployment script sample
#!/bin/bash
echo "Patching out... Do you want to continue? (y/n)"
read CONFIRMATION
if [[ "$CONFIRMATION" != "y" && "$CONFIRMATION" != "Y" ]]; then
echo No worries.
exit 1
fi
cd /home/ubuntu/sites/myproject/myshop/
echo "Fetching the branches"
git fetch
if [[ $(git rev-parse HEAD) == $(git rev-parse @{u}) ]]; then
echo "You're running the latest version already."
exit 1
fi
echo "There're new changes in the repository, let's pull them"
git pull origin master
echo "Copying files"
cp -R /home/ubuntu/sites/myproject/myshop/ /var/www/myshop_
echo "Updating vendors"
composer install --working-dir=/var/www/myshop_
echo "Syncing media files"
cp -R /var/www/myshop/pub/media/* /var/www/myshop_/pub/media
echo "Syncing config"
cp /var/www/myshop/app/etc/env.php /var/www/myshop_/app/etc/env.php
cp /var/www/myshop/app/etc/config.php /var/www/myshop_/app/etc/config.php
echo "Cleaning up"
rm -rf /var/www/myshop_/var/cache/* \
/var/www/myshop_/var/page_cache/* \
/var/www/myshop_/var/di/* \
/var/www/myshop_/var/generation/* \
/var/www/myshop_/var/view_preprocessed/* \
/var/www/myshop_/pub/static/*
echo "Generating static files"
/var/www/myshop_/bin/magento setup:static-content:deploy --language en_NZ
/var/www/myshop_/bin/magento cache:flush
/var/www/myshop_/bin/magento indexer:reindex
echo "Compiling code"
/var/www/myshop_/bin/magento setup:di:compile
echo "Setting file permissions"
chown -R www-data:www-data /var/www/myshop_
find /var/www/myshop_/var /var/www/myshop_/pub/static /var/www/myshop_/pub/media /var/www/myshop_/app/etc -type f -exec chmod g+w {} \;
find /var/www/myshop_/var /var/www/myshop_/pub/static /var/www/myshop_/pub/media /var/www/myshop_/app/etc -type d -exec chmod g+ws {} \;
echo "Please confirm you want to proceed and enable your patch on live (y/n)"
read CONFIRMATION
if [[ "$CONFIRMATION" != "y" && "$CONFIRMATION" != "Y" ]]; then
echo No worries.
exit 1
fi
echo "Swapping site"
mv /var/www/myshop /var/www/myshop_$(whoami)_$(date +"%Y-%m-%d_%H-%M-%S")
mv /var/www/myshop_ /var/www/myshop
echo "Enabling maintenance mode"
/var/www/myshop/bin/magento maintenance:enable
echo "Upgrade modules"
/var/www/myshop/bin/magento setup:upgrade --keep-generated
chown -R www-data:www-data /var/www/myshop
echo "Disabling maintenance mode"
/var/www/myshop/bin/magento maintenance:disable
echo "All done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment