4in1_ws_web/deploy/deploy.sh
2025-05-18 00:33:25 +03:00

71 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
die() {
>&2 echo "error: $*"
exit 1
}
set -e
if ! command -v yq >/dev/null 2>&1; then
die "yq is not installed. Please install yq to parse YAML files."
fi
DIR=$(cd "$(dirname "$(readlink -f "$0")")" && pwd)
DEV_DIR="$(realpath "$DIR/../")"
STAGING_DIR="$HOME/staging"
PROD_DIR="$HOME/www"
REPO_URI=$(yq -r '.git_repo' "$DEV_DIR/config.yaml")
[ "$(hostname)" = "4in1" ] || die "unexpected hostname. are you sure you're running it on the right machine?"
git push origin master
[ -d "$STAGING_DIR" ] || mkdir "$STAGING_DIR"
cd "$STAGING_DIR"
if [ ! -d .git ]; then
git init
git remote add origin "$REPO_URI"
git fetch
git checkout master
fi
git reset --hard
# Store the current commit hash before pulling
PREV_COMMIT=$(git rev-parse HEAD)
git pull origin master
composer install --no-dev --optimize-autoloader --ignore-platform-reqs
composer dump-autoload -o
if [ ! -d node_modules ]; then
npm i
fi
cp "$DEV_DIR/config.yaml" .
"$DIR/static_incremental.sh" -o "$STAGING_DIR" -p "$PREV_COMMIT"
cd "$DIR"
TWIG_CACHE_DIR=$(grep 'skin_cache_prod_dir:' "$DEV_DIR/config.yaml" | sed 's/.*skin_cache_prod_dir: *//' | tr -d '[:space:]')
if [ -d "$TWIG_CACHE_DIR" ]; then
find "$TWIG_CACHE_DIR" -maxdepth 1 -not -path "$TWIG_CACHE_DIR" -exec rm -rf {} +
fi
# copy staging to prod
rsync -a --delete --delete-excluded --info=progress2 "$STAGING_DIR/" "$PROD_DIR/" \
--exclude .git \
--exclude debug.log \
--exclude='/log' \
--exclude='/composer.*' \
--exclude='/public/*/scss' \
--exclude='/public/*/js' \
--exclude='/public/sass.php' \
--exclude='/public/js.php' \
--exclude='*.sh' \
--exclude='*.sql'