-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
99 lines (76 loc) · 2.47 KB
/
deploy.php
File metadata and controls
99 lines (76 loc) · 2.47 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
<?php
namespace Deployer;
require 'recipe/common.php';
require 'contrib/npm.php';
require 'contrib/slack.php';
define('BASEPATH', __DIR__);
require __DIR__ . '/vendor/autoload.php';
use Dotenv\Dotenv;
$dotenv = Dotenv::createUnsafeImmutable(__DIR__);
if (file_exists(__DIR__.'/.env')) {
$dotenv->load();
} else {
exit('Please create an .env file to continue');
}
// Project name
set('application', getenv('APPLICATION'));
// Project repository
set('repository', getenv('REPOSITORY'));
set('git_tty', true);
set('allow_anonymous_stats', false);
set('keep_releases', 5);
set('slack_webhook', getenv('SLACK_WEBHOOK'));
set('slack_text', '_{{user}}_ deploying `{{target}}` to *{{host}}*');
set('slack_success_text', 'Deploy to *{{host}}* successful');
set('slack_failure_text', 'Deploy to *{{host}}* failed');
set('slack_color', '#50b2fc');
set('slack_success_color', '#55c7b4');
set('slack_failure_color', '#c27fec');
// Shared files/dirs between deploys
add('shared_files', ['.env']);
add('shared_dirs', []);
// Writable dirs by web server
add('writable_dirs', []);
// Hosts
host('stage')
->setRemoteUser(getenv('DEPLOY_STAGE_USER'))
->setHostname(getenv('DEPLOY_STAGE_IP'))
->set('branch', 'develop')
->set('deploy_path', '/var/www/{{application}}')
->set('host', 'stage');
host('prod')
->setRemoteUser(getenv('DEPLOY_PROD_USER'))
->setHostname(getenv('DEPLOY_PROD_IP'))
->set('branch', 'main')
->set('deploy_path', '/var/www/{{application}}')
->set('host', 'prod');
task(
'git:tag',
function () {
$host = get('host');
if ($host !== 'prod') {
return;
}
$date = runLocally('date +"%y%m%d%H%M"');
$release = get('release_name');
$release_tag = 'v-'.$date.'-'.$release;
$branch = get('branch', 'unknown');
$message = 'Deployed branch '.$branch.' to '.$host;
runLocally("git tag $release_tag -m '{$message}'");
runLocally('git push origin --tags');
}
)->desc('Create release tag');
task(
'npm:production',
function () {
run('cd {{release_path}} && npm install && npm run build');
}
);
before('deploy', 'slack:notify');
after('deploy:success', 'slack:notify:success');
after('deploy:success', 'git:tag');
after('deploy:failed', 'slack:notify:failure');
// after('deploy:update_code', 'npm:install');
after('deploy:update_code', 'npm:production');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');