-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.php
103 lines (81 loc) · 2.74 KB
/
deploy.php
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
<?php
namespace Deployer;
require 'recipe/laravel.php';
require 'contrib/npm.php';
require 'contrib/cachetool.php';
// Config
set('bin/php', function () {
return '/usr/bin/php'; // change
});
set('application', 'eKartar');
set('repository', 'https://github.com/yukebrillianth/eKartar.git');
set('keep_releases', 5);
set('ssh_multiplexing', true);
add('shared_files', ['.env']);
add('shared_dirs', ['storage']);
add('writable_dirs', []);
set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
set('writable_mode', 'chmod');
set('writable_chmod_mode', '0775');
set('cachetool', '/var/run/php/php8.3-fpm.sock');
// Hosts
host('production')
->setHostname("yukebrillianth-34394.portmap.host")
->set('remote_user', 'deployer')
->set('port', 34394)
->set('branch', 'main')
->set('deploy_path', '/var/www/html/ekartar');
// Hooks
task('deploy:secrets', function () {
file_put_contents(__DIR__ . '/.env', getenv('DOT_ENV'));
upload('.env', get('deploy_path') . '/shared');
});
// NVM source location
set('nvm', 'source $HOME/.nvm/nvm.sh');
// Must be called in every run command related to npm
// Note: do not separate run command, as it is accounted as different shell session
set('use_nvm', function () {
return '{{nvm}} && node --version && nvm use --lts --latest-npm';
});
task('npm:ci', function () {
run('{{use_nvm}} && cd {{release_path}} && npm ci');
});
task('npm:build:prod', function () {
run('{{use_nvm}} && cd {{release_path}} && npm run build');
});
desc('Build assets');
task('deploy:build', [
'npm:ci',
'npm:build:prod'
]);
task('db:migrate', artisan('migrate:install'));
task('backup:run', artisan('backup:run'));
task('backup:restore', artisan('backup:restore', ['--disk=b2', '--connection=pgsql']));
task('icon:cache', artisan('icons:cache'));
task('deploy', [
'deploy:prepare',
'deploy:secrets', // Deploy secrets
'deploy:vendors',
'deploy:shared',
'deploy:build',
'artisan:horizon:terminate',
'artisan:storage:link',
'icon:cache',
'artisan:view:cache',
'artisan:config:cache',
'artisan:route:cache',
'artisan:event:cache',
'artisan:optimize',
'deploy:publish',
]);
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release. Uncomment below code if you want to migrate after deploy
// before('deploy:symlink', 'artisan:migrate');
after('deploy:cleanup', 'artisan:cache:clear');
after('deploy:cleanup', 'artisan:optimize');
after('deploy:cleanup', 'artisan:horizon:purge');
// Clear OPcache
after('deploy:symlink', 'cachetool:clear:opcache');
// handle queue restarts
after('deploy:symlink', 'artisan:queue:restart');