-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.php
More file actions
113 lines (91 loc) · 3.59 KB
/
project.php
File metadata and controls
113 lines (91 loc) · 3.59 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
<?php
declare(strict_types=1);
namespace Deployer;
task('deploy:livewire:storage', function () {
set('remote_user', get('provision_user'));
run('mkdir -p {{deploy_path}}/shared/storage/app/private/livewire-tmp');
run('chown www-data:www-data -R {{deploy_path}}/shared/storage/app/');
})->oncePerNode();
desc('pnpm install and build');
task('deploy:build', function () {
run('sudo chown -R {{remote_user}}:{{remote_user}} {{current_path}}/node_modules', no_throw: true);
run('source /etc/profile.d/fnm.sh && cd {{current_path}} && CI=true pnpm install && pnpm run build && pnpm run build:ssr');
});
desc('Publish Livewire assets');
task('artisan:publish:livewire', artisan('vendor:publish --force --tag=livewire:assets'));
desc('Deploys your project');
task('deploy', [
'deploy:prepare',
'deploy:vendors',
//'env:db',
//'artisan:storage:link',
//'artisan:config:cache',
//'artisan:route:cache',
//'artisan:view:cache',
//'artisan:event:cache',
//'artisan:migrate',
'deploy:publish',
'deploy:build',
'artisan:publish:livewire',
'deploy:livewire:storage',
'deploy:supervisor',
'artisan:optimize',
]);
desc('Syncs database credentials to .env');
task('env:db', function () {
$envFile = '{{deploy_path}}/shared/.env';
// Ensure the file exists before editing
if (! test("[ -f $envFile ]")) {
throw new \RuntimeException('The .env file was not found in {{deploy_path}}/shared/.env. Run deploy:shared first.');
}
$dbConfig = [
'DB_DATABASE' => get('db_name'),
'DB_USERNAME' => get('db_user'),
'DB_PASSWORD' => get('db_password'),
];
foreach ($dbConfig as $key => $value) {
// Escape special characters for the sed command
$val = addslashes($value);
// 1. Check if key exists: if yes, replace line.
// 2. If no: append to end of file.
run("grep -q '^$key=' $envFile &&
sed -i 's|^$key=.*|$key=$val|' $envFile ||
echo '$key=$val' >> $envFile");
}
info('Database credentials updated in .env');
});
desc('Configures supervisor for the project');
task('deploy:supervisor', function () {
set('remote_user', get('provision_user'));
// 2. Diff and Update Configuration
$workerConf = parse(file_get_contents(__DIR__ . '/supervisor/worker.conf'));
$workerPath = '/etc/supervisor/conf.d/{{domain}}-worker.conf';
run('mkdir -p /etc/supervisor/conf.d');
if (test("[ -f $workerPath ]")) {
run("echo \"$workerConf\" > /tmp/worker.conf.new");
$diff = run("diff -U5 --color=always $workerPath /tmp/worker.conf.new", no_throw: true);
if (empty($diff)) {
run('rm /tmp/worker.conf.new');
} else {
info('Found worker Configuration changes');
writeln("\n".$diff);
$answer = askChoice(' Which worker config to save? ', ['old', 'new'], 1); // Changed default to 'new'
if ($answer === 'old') {
run('rm /tmp/worker.conf.new');
} else {
run("mv /tmp/worker.conf.new $workerPath");
}
}
} else {
run("echo \"$workerConf\" > /tmp/worker.conf");
run("mv /tmp/worker.conf $workerPath");
}
// 3. Reload Supervisor
run('supervisorctl reread');
run('supervisorctl update');
// Instead of restarting EVERYTHING using all, just restart this domain's group
// This assumes your worker.conf has a [program:{{domain}}-worker] or [group:{{domain}}]
run('supervisorctl restart {{domain}}-worker:*');
// 4. Show Status
run('supervisorctl status');
});