Repository navigation
Expand file tree
/
Copy pathdeploy.php
More file actions
143 lines (120 loc) · 5.36 KB
/
Copy pathdeploy.php
File metadata and controls
143 lines (120 loc) · 5.36 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Deployer;
require 'recipe/laravel.php';
require __DIR__.'/vendor/austinmastlab/deployer-recipes/recipe/ssm-env.php';
require 'deploy/custom.php';
/*
* BIOSPEX CI/CD DEPLOYMENT CONFIGURATION - Option 1 Implementation
*
* USAGE:
* - Automatic deployment via GitHub Actions (recommended)
* - Manual deployment: dep deploy production|development
*
* HOW IT WORKS:
* 1. GitHub Actions builds assets and creates artifacts
* 2. Deployer downloads artifacts (no server-side building)
* 3. Queue-safe deployment (checks for active jobs)
* 4. Environment-specific configuration
* 5. Automatic cleanup (node_modules removed)
*/
// Deployment Configuration
set('repository', 'https://github.com/AustinMastLab/Biospex.git');
set('ssm_app', 'biospex'); // .env is generated from SSM /biospex/{environment} (env:ssm)
set('base_path', '/data/web');
set('remote_user', 'ubuntu');
set('ssh_multiplexing', true);
set('writable_mode', 'chmod');
set('keep_releases', 3); // Keep only 3 recent releases
// Use sudo for cleanup to prevent "Directory not empty" or permission errors
set('cleanup_use_sudo', true);
// Shared Files (persisted across deployments)
set('shared_files', [
'.env', // Environment configuration
]);
// Shared Directories (persisted across deployments).
// The Vite build (public/build) and the static images (public/images) belong to each release, so a rollback
// gets the assets it was built with. Filament publishes its assets into public/css, public/js and
// public/fonts on every deploy (artisan:filament:assets).
set('shared_dirs', [
'storage', // Laravel storage (logs, cache, uploads)
'public/svg', // SVG assets
'public/vendor', // Vendor assets (Livewire, etc.)
]);
// Files/Directories to Remove After Deployment
set('clear_paths', [
'node_modules', // Remove after CI artifacts are deployed
'deployment-package', // Remove any residual nesting dirs
]);
// One-off app:update-queries operation for this release. Set back to '' once it has run in production.
set('update_queries_operation', '');
// Determine if the local identity file exists (for manual deployments)
$localKey = '/home/ubuntu/.ssh/biospexaws.pem';
$hasLocalKey = file_exists($localKey);
// Server Configurations
// Production: main branch → /data/web/biospex
host('production')
->set('hostname', '3.142.169.134')
->set('deploy_path', '{{base_path}}/biospex')
->set('branch', 'main')
->set('environment', 'production')
->set('app_tag', 'biospex');
if ($hasLocalKey) {
host('production')->set('identity_file', $localKey);
}
// Development: development branch → /data/web/dev.biospex
host('development')
->set('hostname', '3.138.217.206')
->set('deploy_path', '{{base_path}}/biospex')
->set('branch', 'development')
->set('environment', 'development')
->set('app_tag', 'biospex');
if ($hasLocalKey) {
host('development')->set('identity_file', $localKey);
}
/*
* DEPLOYMENT TASK SEQUENCE - CI/CD Option 1 Implementation
*
* This sequence eliminates server-side building by using CI artifacts.
* Each task is executed in order with proper error handling.
*/
desc('Deploys your project using CI/CD artifacts');
task('deploy', [
// Phase 1: Preparation
'deploy:prepare', // Create release directory and setup structure
// Phase 1.5: Ensure .env from SSM is ready (Moved after prepare)
'env:ssm',
// Phase 2: Dependencies & Assets
'deploy:vendors', // Install PHP Composer dependencies safely
'deploy:ci-artifacts', // Download & extract pre-built assets from GitHub Actions (NEW: No server building!)
// Phase 3: Laravel Setup
'artisan:storage:link', // Create symbolic link for storage directory
'artisan:package:discover', // Run package discovery after environment is ready (SAFE: after .env is linked)
'artisan:filament:assets',
'artisan:app:deploy-files', // Custom app deployment files
// Phase 4: Database & Updates
'artisan:migrate', // Run database migrations
'artisan:app:update-queries', // One-off data updates (skipped when update_queries_operation is empty)
// Phase 5: Cache Optimization
'artisan:optimize:clear', // Clear all Laravel caches
'artisan:cache:clear', // Clear application cache
'artisan:config:cache', // Cache configuration files
'artisan:route:cache', // Cache route definitions
'artisan:view:cache', // Cache Blade templates
'artisan:event:cache', // Cache event listeners
'artisan:optimize', // Run Laravel optimization
'artisan:filament:optimize', // Optimize Filament resources and assets
// Phase 8: Finalization
'deploy:clear_paths', // Remove unnecessary files/directories
'deploy:publish', // <--- SYMLINK SWITCHES HERE
'artisan:responsecache:clear', // Drop pages cached by the old release, which name its asset files
// Phase 7: Supervisor and long-running processes, after the symlink switch,
// so Supervisor starts them from the new release instead of the one being
// replaced. A changed config makes `supervisorctl update` restart the group.
'supervisor:reload',
'artisan:queue:restart',
'artisan:reverb:restart',
'supervisor:restart-panoptes-listener',
'deploy:verify-structure', // Verify flat structure post-deploy
]);
// Hooks
after('deploy:failed', 'deploy:unlock');