Skip to content

Commit 9d7157b

Browse files
committed
Envoy
1 parent 3734aaa commit 9d7157b

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

Envoy.blade.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@story('deploy', ['skipBackup' => false, 'skipFrontend' => false])
55
@if(!$skipFrontend)
66
build-frontend
7+
push-frontend
78
@endif
89
@if(!$skipBackup)
910
backup-database
@@ -14,7 +15,7 @@
1415
perform-migration
1516
optimize-cache
1617
@if(!$skipFrontend)
17-
push-frontend
18+
switch-frontend
1819
@endif
1920
up
2021
@endstory
@@ -76,6 +77,39 @@
7677

7778
@task('push-frontend', ['on' => 'local'])
7879
set -e
79-
echo "Copying compiled assets to server..."
80-
scp -r {{ __DIR__ }}/public/build root@143.198.129.111:/var/www/ComputerScienceResources.com/public
80+
echo "Copying compiled frontend to server (staging to new_public)..."
81+
# ensure destination staging directory exists on server
82+
ssh root@143.198.129.111 'mkdir -p /var/www/ComputerScienceResources.com/new_public'
83+
# copy the whole public directory (including build assets) to the staging directory
84+
scp -r {{ __DIR__ }}/public root@143.198.129.111:/var/www/ComputerScienceResources.com/new_public
85+
@endtask
86+
87+
88+
@task('switch-frontend', ['on' => 'server'])
89+
set -e
90+
cd /var/www/ComputerScienceResources.com
91+
echo "Checking maintenance mode before switching frontend..."
92+
# only switch if application is in maintenance mode (artisan creates storage/framework/down)
93+
if [ -f storage/framework/down ]; then
94+
echo "Maintenance mode detected — performing frontend switch"
95+
if [ ! -d new_public ]; then
96+
echo "No new_public directory found, aborting frontend switch"
97+
exit 1
98+
fi
99+
100+
if [ -d public ]; then
101+
timestamp=$(date +%s)
102+
echo "Backing up current public to public_old_$timestamp"
103+
mv public public_old_$timestamp
104+
fi
105+
106+
echo "Promoting new_public to public"
107+
mv new_public public
108+
109+
# Fix permissions if needed
110+
chown -R www-data:www-data public || true
111+
echo "Frontend switch complete"
112+
else
113+
echo "Application is not in maintenance mode — skipping frontend switch"
114+
fi
81115
@endtask

0 commit comments

Comments
 (0)