Created
November 16, 2022 14:57
-
-
Save hans2103/0ef0bededb689d5a25bd0d13a9d37c1c to your computer and use it in GitHub Desktop.
deployment script for Magento 2
This file contains hidden or 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
#!/bin/bash | |
# This script will start deployment | |
# $ ~/bin/deploy | |
# $ chmod +x ~/bin/deploy | |
################################################################################ | |
# Help # | |
################################################################################ | |
Help() | |
{ | |
# Display Help | |
echo "This command will start deployment of Magento 2 changes on an environment (production or staging)." | |
echo | |
echo "Syntax: scriptTemplate [h]" | |
echo "options:" | |
echo "h Print this Help." | |
echo | |
} | |
################################################################################ | |
################################################################################ | |
# Main program # | |
################################################################################ | |
################################################################################ | |
################################################################################ | |
# Process the input options. Add options as needed. # | |
################################################################################ | |
# Get the options | |
while getopts ":h" option; do | |
case $option in | |
h) # display Help | |
Help | |
exit;; | |
\?) # incorrect option | |
echo "Error: Invalid option" | |
exit;; | |
esac | |
done | |
## Get arguments from script | |
SCRIPTNAME="$0" | |
ENVIRONMENT="${@}" | |
## Exit if no arguments | |
if [ "${ENVIRONMENT}x" == "x" ] ; then | |
echo "$0 Usage $SCRIPTNAME <environment>" | |
exit 1 | |
fi | |
# Go To Staging environment | |
if [ "${ENVIRONMENT}" == "production" ] ; then | |
echo "$ cd ~/magento2"; | |
cd ~/magento2; | |
else | |
echo "$ cd ~/magento2_staging"; | |
cd ~/magento2_staging; | |
fi | |
# Add whatever is currently not commtted to git | |
echo "update git"; | |
git add -A; | |
git commit --author [email protected] -m "pending server changes"; | |
# Enable maintenance mode | |
bin/magento maintenance:enable; | |
# Wait to finish possible API calls or Cronjobs | |
echo "Wait for 5 seconds"; | |
sleep 5; | |
# Get changes from Git | |
git pull; | |
# Deploy changes | |
echo "$ composer2 install --ignore-platform-reqs"; | |
composer2 install --ignore-platform-reqs; | |
echo "$ rm -rf generated/code"; | |
rm -rf generated/code; | |
echo "$ bin/magento cache:flush;"; | |
bin/magento cache:flush; | |
echo "$ bin/magento setup:upgrade;"; | |
bin/magento setup:upgrade; | |
echo "$ bin/magento setup:di:compile;"; | |
bin/magento setup:di:compile; | |
echo "$ bin/magento setup:static-content:deploy nl_NL en_US -f;"; | |
bin/magento setup:static-content:deploy nl_NL en_US -f; | |
bin/magento maintenance:disable; | |
# Commit changes to git | |
git add -A; | |
git commit -m "pending server changes"; | |
git push; | |
# Done | |
echo "Done"; | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment