This commit is contained in:
72
scripts/deploy.sh
Executable file
72
scripts/deploy.sh
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
log() {
|
||||
printf '\n[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
|
||||
}
|
||||
|
||||
require_command() {
|
||||
if ! command -v "$1" >/dev/null 2>&1; then
|
||||
printf 'Missing required command: %s\n' "$1" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
require_command php
|
||||
require_command composer
|
||||
require_command npm
|
||||
|
||||
if [[ ! -f artisan ]]; then
|
||||
printf 'artisan not found in %s\n' "$ROOT_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f .env ]]; then
|
||||
printf '.env not found. Create it from .env.example and set production values before deploying.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
maintenance_enabled=0
|
||||
deploy_succeeded=0
|
||||
|
||||
cleanup() {
|
||||
if [[ "$maintenance_enabled" -eq 1 && "$deploy_succeeded" -eq 0 ]]; then
|
||||
printf '\nDeployment failed. The application remains in maintenance mode.\n' >&2
|
||||
printf 'Fix the issue and run: php artisan up\n' >&2
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
log "Putting the application into maintenance mode"
|
||||
php artisan down --retry=60
|
||||
maintenance_enabled=1
|
||||
|
||||
log "Installing PHP dependencies"
|
||||
composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
|
||||
|
||||
log "Installing Node.js dependencies"
|
||||
npm ci
|
||||
|
||||
log "Building frontend assets"
|
||||
npm run build
|
||||
|
||||
log "Ensuring the public storage link exists"
|
||||
php artisan storage:link >/dev/null 2>&1 || true
|
||||
|
||||
log "Running Laravel deployment tasks"
|
||||
composer run deploy --no-interaction
|
||||
|
||||
log "Restarting queue workers if they are running"
|
||||
php artisan queue:restart >/dev/null 2>&1 || true
|
||||
|
||||
log "Bringing the application back online"
|
||||
php artisan up
|
||||
maintenance_enabled=0
|
||||
deploy_succeeded=1
|
||||
|
||||
log "Deployment completed successfully"
|
||||
Reference in New Issue
Block a user