Skip to content

Instantly share code, notes, and snippets.

@leek
Last active May 31, 2022 23:53
Show Gist options
  • Save leek/a17dc01d982afcde5a3c40679a2e914e to your computer and use it in GitHub Desktop.
Save leek/a17dc01d982afcde5a3c40679a2e914e to your computer and use it in GitHub Desktop.
Magento 2 Deployment Script
#!/bin/bash
LOCKFILE=deploy.lock
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "-- ERROR"
echo "-- Deployment is already running"
exit
fi
# Remove lock file when exiting
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
# Make sure we are in the right directory
if [ ! -f ./app/etc/config.php ]; then
echo "-- ERROR"
echo "-- This doesn't look like a Magento 2 install. Please make sure"
echo "-- that you are running this from the Magento main doc root dir"
exit
fi
# Begin deployment
php bin/magento maintenance:enable --ip=127.0.0.1
# Preclean
rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf generated/code/*
# Composer
composer install
php bin/magento setup:upgrade
php bin/magento setup:di:compile
# Deploy locales for associated themes
php -d memory_limit=-1 bin/magento setup:static-content:deploy -f en_US
# php -d memory_limit=-1 bin/magento setup:static-content:deploy -f --exclude-area=adminhtml en_CA
# php -d memory_limit=-1 bin/magento setup:static-content:deploy -f --exclude-area=adminhtml fr_CA
# php -d memory_limit=-1 bin/magento setup:static-content:deploy -f --exclude-area=adminhtml es_MX
# php -d memory_limit=-1 bin/magento setup:static-content:deploy -f --exclude-area=adminhtml pt_BR
php bin/magento cache:flush
php bin/magento maintenance:disable
php bin/magento cache:enable
# Remove lock file
rm -f ${LOCKFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment