minor fixes

This commit is contained in:
2026-04-09 08:50:36 +02:00
parent 23d363a50c
commit a2457f4e49
75 changed files with 3848 additions and 387 deletions

View File

@@ -17,12 +17,15 @@ run_local_build=1
run_remote_migrations=1
run_db_sync=0
run_meilisearch_setup=0
auto_detect_meilisearch=1
db_sync_source=""
legacy_db_sync_mode=0
force_db_sync=0
skip_maintenance=0
db_sync_confirm_target="${DB_SYNC_CONFIRM_TARGET:-}"
db_sync_confirm_phrase="${DB_SYNC_CONFIRM_PHRASE:-}"
meilisearch_models_csv=""
readonly all_meilisearch_models_csv='App\Models\Artwork,App\Models\User,App\Models\Group,App\Models\Post,App\Models\Message'
usage() {
cat <<'EOF'
@@ -38,7 +41,8 @@ Options:
Must equal 'replace production db from local' when running non-interactively.
--with-db Legacy alias for --with-db-from=local.
--force-db-sync Legacy extra confirmation flag for --with-db.
--with-meilisearch Sync index settings then reimport all searchable models.
--with-meilisearch Force Meilisearch settings sync and reimport all searchable models.
--skip-meilisearch Skip Meilisearch refresh, including auto-detected refreshes.
--no-maintenance Skip php artisan down/up during deploy.
--help Show this help.
@@ -120,6 +124,97 @@ run_frontend_build() {
)
}
build_rsync_args() {
rsync_args=(
-rlvz
--no-perms
--no-times
--omit-dir-times
--delete
--delete-delay
--exclude ".phpintel/"
--exclude "bootstrap/cache/"
--exclude ".env"
--exclude "public/hot"
--exclude "node_modules"
--exclude "public/files/"
--exclude "resources/lang/"
--exclude "storage/"
--exclude ".git/"
--exclude ".cursor/"
--exclude ".venv/"
--exclude "/oldSite"
--exclude "/vendor"
-e "$ssh_bin"
)
}
collect_sync_changed_files() {
local itemized
if ! itemized="$($rsync_bin "${rsync_args[@]}" --dry-run --itemize-changes "$local_folder/" "$remote_server:$remote_folder/" 2>/dev/null)"; then
return 1
fi
printf '%s\n' "$itemized" | awk '
/^deleting / {
sub(/^deleting /, "", $0)
if ($0 !~ /\/$/) print
next
}
/^[<>ch.*][^ ]* / {
path = $0
sub(/^[^ ]+ /, "", path)
if (path !~ /\/$/) print path
}
' | sed '/^$/d' | sort -u
}
detect_meilisearch_models_from_sync() {
local changed_files
local file
local force_full=0
local -a models=()
if ! changed_files="$(collect_sync_changed_files)"; then
return 1
fi
[[ -n "$changed_files" ]] || return 1
while IFS= read -r file; do
case "$file" in
config/scout.php|app/Console/Commands/ConfigureMeilisearchIndex.php)
force_full=1
;;
app/Models/Artwork.php)
models+=("App\Models\Artwork")
;;
app/Models/User.php)
models+=("App\Models\User")
;;
app/Models/Group.php)
models+=("App\Models\Group")
;;
app/Models/Post.php)
models+=("App\Models\Post")
;;
app/Models/Message.php)
models+=("App\Models\Message")
;;
esac
done <<< "$changed_files"
if [[ "$force_full" -eq 1 ]]; then
printf '%s\n' "$all_meilisearch_models_csv"
return 0
fi
[[ ${#models[@]} -gt 0 ]] || return 1
printf '%s\n' "$(printf '%s\n' "${models[@]}" | awk '!seen[$0]++' | paste -sd, -)"
}
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-build)
@@ -161,6 +256,13 @@ while [[ $# -gt 0 ]]; do
;;
--with-meilisearch)
run_meilisearch_setup=1
auto_detect_meilisearch=0
meilisearch_models_csv="$all_meilisearch_models_csv"
;;
--skip-meilisearch)
run_meilisearch_setup=0
auto_detect_meilisearch=0
meilisearch_models_csv=""
;;
--no-maintenance)
skip_maintenance=1
@@ -202,27 +304,17 @@ if [[ "$run_local_build" -eq 1 ]]; then
run_frontend_build
fi
build_rsync_args
if [[ "$run_meilisearch_setup" -eq 0 && "$auto_detect_meilisearch" -eq 1 ]]; then
if meilisearch_models_csv="$(detect_meilisearch_models_from_sync)"; then
run_meilisearch_setup=1
echo "Detected Meilisearch-relevant changes in this deployment; will refresh indexes for: $meilisearch_models_csv"
fi
fi
echo "Syncing application files to $remote_server..."
"$rsync_bin" -avz \
--delete \
--delete-delay \
--chmod=D755,F644 \
--exclude ".phpintel/" \
--exclude "bootstrap/cache/" \
--exclude ".env" \
--exclude "public/hot" \
--exclude "node_modules" \
--exclude "public/files/" \
--exclude "resources/lang/" \
--exclude "storage/" \
--exclude ".git/" \
--exclude ".cursor/" \
--exclude ".venv/" \
--exclude "/oldSite" \
--exclude "/vendor" \
-e ssh \
"$local_folder/" \
"$remote_server:$remote_folder/"
"$rsync_bin" "${rsync_args[@]}" "$local_folder/" "$remote_server:$remote_folder/"
if [[ "$run_db_sync" -eq 1 ]]; then
echo "Replacing the production database from the local dump..."
@@ -241,11 +333,34 @@ echo "Running remote Composer and Artisan steps..."
RUN_REMOTE_MIGRATIONS="$run_remote_migrations" \
SKIP_MAINTENANCE="$skip_maintenance" \
RUN_MEILISEARCH_SETUP="$run_meilisearch_setup" \
MEILISEARCH_MODELS_CSV="$(printf '%q' "$meilisearch_models_csv")" \
'bash -s' <<'EOF'
set -euo pipefail
cd "$REMOTE_FOLDER"
ensure_php_runtime_dir() {
local target_dir="$1"
if command -v sudo >/dev/null 2>&1; then
if [[ ! -d "$target_dir" ]]; then
mkdir -p "$target_dir"
fi
chown -R skinbase:skinbase "$target_dir"
chmod 770 "$target_dir"
return
fi
if [[ ! -d "$target_dir" ]]; then
mkdir -p "$target_dir"
fi
chown -R skinbase:skinbase "$target_dir"
chmod 770 "$target_dir"
}
ensure_php_runtime_dir "$REMOTE_FOLDER/var/php-tmp"
ensure_php_runtime_dir "$REMOTE_FOLDER/var/php-sessions"
bring_app_up() {
if [[ "$SKIP_MAINTENANCE" -eq 0 ]]; then
"$PHP_BIN" artisan up >/dev/null 2>&1 || true
@@ -270,12 +385,18 @@ fi
"$PHP_BIN" artisan queue:restart || true
if [[ "$RUN_MEILISEARCH_SETUP" -eq 1 ]]; then
if [[ -z "${MEILISEARCH_MODELS_CSV:-}" ]]; then
MEILISEARCH_MODELS_CSV='App\Models\Artwork,App\Models\User,App\Models\Group,App\Models\Post,App\Models\Message'
fi
IFS=',' read -r -a meilisearch_models <<< "$MEILISEARCH_MODELS_CSV"
echo "Importing searchable models into Meilisearch (auto-creates indexes)..."
"$PHP_BIN" artisan scout:import "App\\Models\\Artwork"
"$PHP_BIN" artisan scout:import "App\\Models\\User"
"$PHP_BIN" artisan scout:import "App\\Models\\Group"
"$PHP_BIN" artisan scout:import "App\\Models\\Post"
"$PHP_BIN" artisan scout:import "App\\Models\\Message"
for model in "${meilisearch_models[@]}"; do
[[ -n "$model" ]] || continue
echo " -> $model"
"$PHP_BIN" artisan scout:import "$model"
done
echo "Syncing Meilisearch index settings..."
"$PHP_BIN" artisan scout:sync-index-settings
echo "Meilisearch setup complete."