-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
210 lines (200 loc) · 6.98 KB
/
Copy pathdeploy.php
File metadata and controls
210 lines (200 loc) · 6.98 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
namespace Deployer;
use Dotenv\Dotenv;
use Illuminate\Support\Str;
require 'recipe/laravel.php';
require 'recipe/provision/databases.php';
require 'recipe/provision/php.php';
require 'recipe/provision/user.php';
require 'recipe/provision/website.php';
require 'contrib/npm.php';
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Config
set('repository', 'git@bitbucket.org:jkdev11/cms.git');
add('shared_files', []);
add('shared_dirs', []);
add('writable_dirs', []);
// Hosts
host($_ENV['APP_URL'])
->set('domain', $_ENV['APP_URL'])
->set('deploy_path', $_ENV['REMOTE_DEPLOY_PATH'])
->set('remote_user', $_ENV['REMOTE_USERNAME'])
->set('sudo_password', $_ENV['REMOTE_PASSWORD'])
->set('db_type', $_ENV['DB_CONNECTION'])
->set('db_name', $_ENV['DB_DATABASE'])
->set('db_user', $_ENV['DB_USERNAME'])
->set('db_password', $_ENV['DB_PASSWORD'])
->set('php_version', $_ENV['PHP_VERSION'])
->set('node_version', $_ENV['NODE_VERSION'])
->set('public_path', 'public');
// Tasks
task('cms:info:branch', function () {
$branch = get('branch');
info('Git branch: ' . $branch);
});
desc('Node version 24');
task('cms:provision:update_node', function () {
run("curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -");
});
desc('Supervisor');
task('cms:provision:install_supervisor', function () {
run('apt-get install -y supervisor', env: ['DEBIAN_FRONTEND' => 'noninteractive'], timeout: 900);
});
task('cms:env:reverb', function () {
cd('{{release_or_current_path}}');
$appId = random_int(100_000, 999_999);
$reverbAppId = 'REVERB_APP_ID=' . $appId;
run('echo ' . $reverbAppId . ' | tee -a .env', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
$appKey = Str::lower(Str::random(20));
$reverbAppKey = 'REVERB_APP_KEY=' . $appKey;
run('echo ' . $reverbAppKey . ' | tee -a .env', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
$appSecret = Str::lower(Str::random(20));
$reverbAppSecret = 'REVERB_APP_SECRET=' . $appSecret;
run('echo ' . $reverbAppSecret . ' | tee -a .env', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
});
task('cms:supervisor:horizon:config', function () {
cd('{{release_or_current_path}}');
if (test('[ -e horizon.conf ] && [ ! -e /etc/supervisor/conf.d/horizon.conf ]')) {
run('sudo cp horizon.conf /etc/supervisor/conf.d/horizon.conf');
}
});
task('cms:supervisor:horizon:start', function () {
cd('{{release_or_current_path}}');
if (test('[ -e /etc/supervisor/conf.d/horizon.conf ]')) {
run('sudo supervisorctl reread');
run('sudo supervisorctl update');
run('sudo supervisorctl start horizon');
}
});
task('cms:supervisor:reverb:config', function () {
cd('{{release_or_current_path}}');
if (test('[ -e reverb.conf ] && [ ! -e /etc/supervisor/conf.d/reverb.conf ]')) {
run('sudo cp reverb.conf /etc/supervisor/conf.d/reverb.conf');
}
});
task('cms:supervisor:reverb:start', function () {
cd('{{release_or_current_path}}');
if (test('[ -e /etc/supervisor/conf.d/reverb.conf ]')) {
run('sudo supervisorctl reread');
run('sudo supervisorctl update');
run('sudo supervisorctl start reverb');
}
});
desc('Add swap space for low RAM VPS');
task('cms:add_swapfile', function () {
set('remote_user', get('provision_user'));
run('fallocate -l 1G /swapfile', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run('chmod 600 /swapfile', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run('mkswap /swapfile', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run('swapon /swapfile', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run('cp /etc/fstab /etc/fstab.bak', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run("echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab", env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run('echo vm.swappiness=10 | tee -a /etc/sysctl.conf', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
run('echo vm.vfs_cache_pressure=50 | tee -a /etc/sysctl.conf', env: ['DEBIAN_FRONTEND' => 'noninteractive']);
});
task('cms:permission_seed', artisan('permission:seed'));
task('cms:install_seed', artisan('install:seed'));
desc('Installation and seeding. Run once instead of vendor/bin/dep deploy.');
task('installcms', [
'ask:installcms',
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:env',
'cms:env:reverb',
'deploy:shared',
'deploy:writable',
'deploy:vendors',
'artisan:storage:link',
'artisan:optimize',
'artisan:migrate',
'cms:supervisor:horizon:config',
'cms:supervisor:horizon:start',
'cms:supervisor:reverb:config',
'cms:supervisor:reverb:start',
'deploy:symlink',
'deploy:unlock',
'deploy:cleanup',
'deploy:success',
'artisan:reload',
'artisan:key:generate',
'cms:permission_seed',
'cms:install_seed',
]);
task('ask:installcms', function () {
if (!askConfirmation("Are you sure you want to run 'installcms'? This command should only be run once.")) {
throw error("Aborting 'installcms'");
}
});
desc('Importing site from csv and seeding. Run once instead of vendor/bin/dep deploy.');
task('importcms', [
'ask:installcms',
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:env',
'cms:env:reverb',
'deploy:shared',
'deploy:writable',
'deploy:vendors',
'artisan:storage:link',
'artisan:optimize',
'artisan:migrate',
'cms:supervisor:horizon:config',
'cms:supervisor:horizon:start',
'cms:supervisor:reverb:config',
'cms:supervisor:reverb:start',
'deploy:symlink',
'deploy:unlock',
'deploy:cleanup',
'deploy:success',
'artisan:reload',
'artisan:key:generate',
'cms:permission_seed',
]);
task('ask:importcms', function () {
if (!askConfirmation("Are you sure you want to run 'importcms'? This command should only be run once.")) {
throw error("Aborting 'importcms'");
}
});
task('ask:provision', function () {
if (!askConfirmation("Are you sure you want to run 'provision'? This command should only be run once.")) {
throw error("Aborting 'provision'");
}
});
desc('Deploy script.');
task('updatecms', [
'deploy:info',
'deploy:setup',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:env',
'deploy:shared',
'deploy:writable',
'deploy:vendors',
'artisan:storage:link',
'artisan:optimize',
'artisan:migrate',
'npm:install',
'npm:build',
'deploy:symlink',
'deploy:unlock',
'deploy:cleanup',
'deploy:success',
'artisan:queue:restart',
'artisan:horizon:terminate',
'artisan:reverb:restart',
'artisan:reload',
]);
before('provision', 'ask:provision');
after('provision:configure', 'cms:info:branch');
before('provision:update', 'cms:provision:update_node');
before('provision:update', 'cms:provision:install_supervisor');
after('provision', 'cms:add_swapfile');
after('deploy:failed', 'deploy:unlock');