Created
January 19, 2020 18:44
-
-
Save landsman/e229888c7cb8a400851976dd59f029ca to your computer and use it in GitHub Desktop.
drupal 8 deployment backup - 2y ago
This file contains 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
# Deployment | |
*Build action* process: | |
``` | |
# copy database parameters | |
cp "$DPSETTINGSPATH" docroot/sites/default/settings.production.php | |
# fix chmods | |
chmod 644 docroot/sites/default/settings.production.php | |
chmod 644 docroot/sites/default/settings.php | |
chmod 644 docroot/sites/default/services.yml | |
# remove devel files | |
rm docroot/sites/default/settings.local.php | |
rm docroot/sites/development.services.yml | |
# create build folder and move all content into this | |
mkdir -p builds/${BUILD_ID} | |
find . ! -name . -prune ! -path ./builds \ | |
-exec mv {} builds/${BUILD_ID} \; | |
# move in | |
cd builds/${BUILD_ID} | |
# run it | |
#composer clearcache | |
composer install --no-dev | |
# download libraries | |
cd docroot/libraries | |
bower install | |
cd ../../ | |
# hot fix - meta tag plugin: | |
mv docroot/modules/contrib/metatag/metatag_mobile/src/Plugin/metatag/Tag/MsapplicationStarturl.php docroot/modules/contrib/metatag/metatag_mobile/src/Plugin/metatag/Tag/MsapplicationStartUrl.php | |
# create archive | |
cd ../../ | |
tar --exclude=".git" -pczf build.tar.gz builds | |
``` | |
We have interesting folder structure for virtual hosts, because its useful. | |
In root must be foders: | |
- data (static files uploaded via admin), setup for symlink to the build folder | |
- builds | |
- {number} - build number with repository state after composer install and theme deployment | |
- live - symlink to last active build, setup as virtual host root | |
Here are symlinks for *Post-build Actions* on destination server: | |
``` | |
cd ~/yourdomain.cz | |
tar -xzf build.tar.gz | |
rm build.tar.gz | |
# find active build | |
BUILD_ACTUAL=$(ls -l live | sed 's/^.* -> //') | |
# backup actual database | |
cd ${BUILD_ACTUAL}/docroot | |
drush config-export -y | |
drush sql-dump --skip-tables-list=cache,cache_* > ../tmp/private/dump-before-next-build.sql | |
cd ../../.. | |
pwd | |
# make live actual build | |
LIVE=/home/hf/yourdomain.cz/live | |
if [ ! -L $LIVE ]; then | |
ln -s builds/${BUILD_ID}/ $LIVE | |
else | |
rm $LIVE | |
ln -s builds/${BUILD_ID}/ $LIVE | |
fi | |
# remove auto-generated empty folder | |
rm -r /home/hf/yourdomain.cz/live/docroot/sites/default/files | |
# make symlink with data to actual build | |
ln -sT ../../../../../data/sites/default/files/ /home/hf/yourdomain.cz/live/docroot/sites/default/files | |
# go to root | |
cd builds/${BUILD_ID}/docroot | |
# maintenance | |
drush sset system.maintenance_mode 1 | |
# clear drush cache | |
drush cache-clear drush | |
# run config/sync, database updates | |
drush config-import -y | |
drush updb -y | |
#drush entity-updates | |
# allow uglify | |
drush -y config-set system.performance css.preprocess 1 | |
drush -y config-set system.performance js.preprocess 1 | |
# clear cache | |
drush cr | |
# go live | |
drush sset system.maintenance_mode 0 | |
# delete two oldest builds | |
BCOUNT=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l); | |
FOLDERS=$(ls -t1 | tail -n2); | |
if [ $BCOUNT -gt "6" ]; then | |
echo "Deleting oldest builds:"; | |
echo $FOLDERS; | |
rm -rf $FOLDERS; | |
fi | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment