Skip to content

Instantly share code, notes, and snippets.

@cagartner
Forked from rafaelstz/magedeploy.sh
Created November 9, 2021 13:39
Show Gist options
  • Save cagartner/66d218196adc92808cb8566f4e3b4222 to your computer and use it in GitHub Desktop.
Save cagartner/66d218196adc92808cb8566f4e3b4222 to your computer and use it in GitHub Desktop.
Magento 2 Deploy script
#!/usr/bin/env bash
LANGUAGES="en_US pt_BR"
# production or developer
ENVIRONMENT="production"
COMPOSER=$(which composer)
PHP=$(which php)
ROOT=$(pwd)
MAGENTO=$(pwd)'/bin/magento'
echo "Magento maintenance mode enable"
$PHP $MAGENTO maintenance:enable &&
echo "Git reset"
git fetch origin &&
git reset --hard origin &&
git pull origin &&
echo "Composer"
if [ "$ENVIRONMENT" == "production" ]; then
$COMPOSER install --no-dev
else
$COMPOSER install
fi
echo "Magento deploy"
$PHP $MAGENTO setup:upgrade &&
$PHP $MAGENTO cache:enable &&
if [ "$ENVIRONMENT" == "production" ]; then
echo "Production deploy"
$PHP $MAGENTO deploy:mode:set production --skip-compilation &&
$PHP $MAGENTO config:set dev/js/move_script_to_bottom 1 &&
$PHP $MAGENTO config:set dev/js/enable_js_bundling 0 &&
$PHP $MAGENTO config:set dev/js/merge_files 1 &&
$PHP $MAGENTO config:set dev/js/minify_files 1 &&
$PHP $MAGENTO config:set design/head/default_robots 'INDEX,FOLLOW' &&
$PHP $MAGENTO config:set google/analytics/active 1
else
echo "Development deploy"
$PHP $MAGENTO deploy:mode:set developer &&
$PHP $MAGENTO config:set dev/js/move_script_to_bottom 0 &&
$PHP $MAGENTO config:set dev/js/enable_js_bundling 0 &&
$PHP $MAGENTO config:set dev/js/merge_files 0 &&
$PHP $MAGENTO config:set dev/js/minify_files 0 &&
$PHP $MAGENTO config:set google/analytics/active 0 &&
$PHP $MAGENTO config:set design/head/default_robots 'NOINDEX,NOFOLLOW'
fi
$PHP $MAGENTO setup:di:compile &&
$PHP $MAGENTO setup:static-content:deploy $LANGUAGES -f &&
$PHP $MAGENTO indexer:reindex &&
$PHP $MAGENTO cache:clean &&
$PHP $MAGENTO maintenance:disable &&
echo "Deploy completed 🎉"
# Created by Rafael Corrêa Gomes (https://github.com/rafaelstz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment