-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeploy.example.sh
More file actions
executable file
·88 lines (71 loc) · 2.87 KB
/
deploy.example.sh
File metadata and controls
executable file
·88 lines (71 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
set -e
# ====================================
# Example deploy script for a Laravel app
# Copy this file (e.g. deploy-myapp.sh) and adjust the variables below.
#
# Expected layout (single-folder Laravel):
# projects/myapp.com/
#
# Or split frontend/backend layout:
# projects/myapp.com/
# ├── backend/ (Laravel)
# └── frontend/ (SPA / Vite)
# Set FRONTEND_DIR to "" if you don't have a separate frontend folder.
# ====================================
APP_NAME="myapp.com"
APP_DIR="/root/docker-webstack/projects/${APP_NAME}"
BACKEND_DIR="${APP_DIR}" # or: "${APP_DIR}/backend"
FRONTEND_DIR="" # or: "${APP_DIR}/frontend"
PHP_CONTAINER="webstack-php84"
WORK_DIR="/var/www/projects/${APP_NAME}"
BACKEND_WORK_DIR="${WORK_DIR}" # or: "${WORK_DIR}/backend"
# Set to "true" if the app uses stancl/tenancy (or similar) tenant migrations.
RUN_TENANT_MIGRATIONS="false"
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
log() { echo -e "${GREEN}[DEPLOY]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
fail() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
# Check php container is running
docker ps --format '{{.Names}}' | grep -q "^${PHP_CONTAINER}$" || fail "Container ${PHP_CONTAINER} is not running"
log "Putting application in maintenance mode..."
docker exec ${PHP_CONTAINER} php ${BACKEND_WORK_DIR}/artisan down --retry=60 || warn "Already in maintenance mode or artisan down failed"
# 1. Git pull
log "Pulling latest changes..."
cd "${APP_DIR}"
git pull || fail "Git pull failed"
# 2. Composer install (backend)
log "Running composer install..."
docker exec ${PHP_CONTAINER} composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader -d ${BACKEND_WORK_DIR}
# 3. NPM build
if [ -n "${FRONTEND_DIR}" ] && [ -d "${FRONTEND_DIR}" ]; then
log "Running npm install & build (frontend)..."
cd "${FRONTEND_DIR}"
npm ci --no-audit --no-fund
npm run build
elif [ -f "${BACKEND_DIR}/package.json" ]; then
log "Running npm install & build..."
cd "${BACKEND_DIR}"
npm ci --no-audit --no-fund
npm run build
else
warn "No package.json found, skipping npm build"
fi
# 4. Database migration
log "Running database migrations..."
docker exec ${PHP_CONTAINER} php ${BACKEND_WORK_DIR}/artisan migrate --force
# 5. Tenant migrations (optional)
if [ "${RUN_TENANT_MIGRATIONS}" = "true" ]; then
log "Running tenant migrations..."
docker exec ${PHP_CONTAINER} php ${BACKEND_WORK_DIR}/artisan tenants:migrate --force || warn "tenants:migrate failed or not applicable"
fi
# 6. Optimize (cache config, routes, views)
log "Optimizing application..."
docker exec ${PHP_CONTAINER} php ${BACKEND_WORK_DIR}/artisan optimize
# 7. Bring app back up
log "Bringing application back online..."
docker exec ${PHP_CONTAINER} php ${BACKEND_WORK_DIR}/artisan up
log "Deploy completed successfully!"