-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
85 lines (71 loc) · 2.63 KB
/
Copy pathdeploy.php
File metadata and controls
85 lines (71 loc) · 2.63 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
<?php
namespace Deployer;
require 'recipe/common.php';
// Load project metadata
$meta = json_decode(file_get_contents(__DIR__ . '/meta.json'), true);
// Project configuration
set('application', $meta['name']);
set('repository', 'git@github.com:nnosal/phpix.git');
set('git_tty', true);
set('keep_releases', 5);
set('shared_files', ['.env']);
set('shared_dirs', ['storage', 'vendor']);
set('writable_dirs', ['storage', 'storage/logs']);
// Hosts configuration from meta.json
foreach ($meta['env'] as $envName => $envConfig) {
if ($envName === 'develop') continue; // Skip local development
host($envName)
->set('hostname', $envConfig['host'])
->set('remote_user', $envConfig['user'])
->set('deploy_path', $envConfig['deploy_path'])
->set('branch', $envConfig['branch'] ?? 'main')
->set('keep_releases', $envConfig['keep_releases'] ?? 3);
}
// Custom tasks
task('deploy:install_deps', function () {
run('cd {{release_path}} && composer install --no-dev --optimize-autoloader');
});
task('deploy:cache_clear', function () {
run('cd {{release_path}} && php artisan cache:clear || true');
run('cd {{release_path}} && php artisan config:clear || true');
run('cd {{release_path}} && php artisan view:clear || true');
});
task('deploy:cache_warmup', function () {
run('cd {{release_path}} && php artisan config:cache || true');
run('cd {{release_path}} && php artisan route:cache || true');
run('cd {{release_path}} && php artisan view:cache || true');
});
task('deploy:migrations', function () {
run('cd {{release_path}} && php artisan migrate --force || true');
});
task('deploy:permissions', function () {
run('chmod -R 755 {{release_path}}/storage || true');
run('chmod -R 755 {{release_path}}/bootstrap/cache || true');
});
task('deploy:health_check', function () {
$url = get('hostname');
writeln("<info>Checking health at: https://{$url}</info>");
$response = run("curl -s -o /dev/null -w '%{http_code}' https://{$url}");
if ($response != '200') {
writeln("<error>Health check failed! HTTP {$response}</error>");
} else {
writeln("<info>✓ Health check passed!</info>");
}
});
// Main deploy task
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'deploy:install_deps',
'deploy:cache_clear',
'deploy:cache_warmup',
'deploy:permissions',
'deploy:publish',
'deploy:health_check',
])->desc('Deploy project');
// After deployment success
after('deploy:success', function () {
writeln('<info>✅ Deployment completed successfully!</info>');
});
// After deployment failure
after('deploy:failed', 'deploy:unlock');