Website/app/bin/deploy.sh
Snoweuph 37a63c29cc
Some checks failed
Quality Check / Check (push) Failing after 3s
#1: Restructure
2024-07-13 12:30:13 +02:00

80 lines
3.4 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
# ---------------------------------------------------------------------------------------------------------------------
# 1. testing for important env vars to be set
[[ -z "$SYMFONY_DECRYPTION_SECRET" ]] && echo "SYMFONY_DECRYPTION_SECRET missing" && exit 1;
[[ -z "$WEBROOT" ]] && echo "WEBROOT missing" && exit 1;
[[ -f ~/.bash_profile ]] && source ~/.bash_profile
# ---------------------------------------------------------------------------------------------------------------------
# 2. syncing persistent shared data into new release and making sure folder structure exists
touch ./public/maintenance.flag
mkdir -p ../../shared/log
mkdir -p ../../shared/sessions
mkdir -p ../../shared/images
mkdir -p ../../shared/videos
mkdir -p ../../shared/assets
mkdir -p ./var
mkdir -p ./public/assets
ln -sf ../../shared/log ./var/log
ln -sf ../../shared/sessions ./var/sessions
ln -sf ../../shared/images ./public/assets/images
ln -sf ../../shared/videos ./public/assets/videos
ln -sf ../../shared/assets ./public/assets/assets
# ---------------------------------------------------------------------------------------------------------------------
# 3. Update robots.txt
echo "Sitemap: $WEBROOT/sitemap.xml" >> ./public/robots.txt
# ---------------------------------------------------------------------------------------------------------------------
# 4. decrypt secret vault into local prod environment
php ./bin/console secrets:decrypt-to-local --force
rm -rf ./config/secrets/prod/
# ---------------------------------------------------------------------------------------------------------------------
# 5. move temp folder to release-x folder with the next higher number
# and delete the release-x folder with the lowest number
cd ..
# Set the release folder prefix and initialize counter
prefix="release-"
counter=0
# Loop through all the folders with the given prefix and find the highest numbered release folder
for folder in $prefix*; do
if [[ -d $folder ]]; then
num=${folder#$prefix}
if [[ $num =~ ^[0-9]+$ && $num -gt $counter ]]; then
counter=$num
fi
fi
done
# Rename the "temp" folder to the next highest release folder
new_release="$prefix$((counter+1))"
mv temp "$new_release"
# ---------------------------------------------------------------------------------------------------------------------
# 6. symlink new release
ln -sfn $new_release latest
cd $new_release
# ---------------------------------------------------------------------------------------------------------------------
# 7. run migrations and update plugins/apps
php ./bin/console doctrine:migrations:migrate -n
# ---------------------------------------------------------------------------------------------------------------------
# 8. clean up and end maintenance mode
php ./bin/console cache:clear
rm -f ./public/maintenance.flag
# ---------------------------------------------------------------------------------------------------------------------
# 9. Clear the Webcache
~/bin/cachetool.phar opcache:reset
# ---------------------------------------------------------------------------------------------------------------------
# 10. remove all but the last four releases (including the one just created)
# We do this after the deployment in order to reduce the chance of deleted folders reappearing because of old processes
# still using them.
ls -d ../release-* | sort -t- -k2n | head -n -4 | xargs --no-run-if-empty rm -rf