-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.php
148 lines (125 loc) · 3.41 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
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
<?php
namespace Deployer;
use Deployer\Task\Context;
require 'recipe/silverstripe.php';
// Project Info
set('org', '__OrgName__');
set('application', '__ApplicationName__');
// Historic releases
set('keep_releases', 3);
// Project repository
set('repository', '[email protected]:{{org}}/{{application}}.git');
// Deployment Info
set('default_stage', 'dev');
set('branch_dev', 'dev');
set('branch_live', 'master');
set('deploy_live_user', '__LiveUserName_');
set('deploy_dev_user', '__DevUserName_');
set('ssh_port_dev', 22);
set('ssh_port_live', 22);
// Silverstripe shared dirs
set(
'shared_dirs',
[
'public/assets',
'silverstripe-cache'
]
);
// Which folders are writable
set(
'writable_dirs',
[
'themes',
'public/assets',
'silverstripe-cache'
]
);
// Silverstripe shared files
set(
'shared_files',
[
'.env'
]
);
// Setup dev server deployment
host('__DevServer__')
->stage('dev')
->port(get('ssh_port_dev'))
->stage(get('branch_dev'))
->user(get('deploy_dev_user'))
->set('deploy_path', '/path/to/{{application}}')
->identityFile('~/.ssh/id_rsa');
// Setup live server deployment
host('__LiveServer__')
->stage('live')
->port(get('ssh_port_live'))
->stage(get('branch_live'))
->user(get('deploy_live_user'))
->set('deploy_path', '/path/to/{{application}}')
->identityFile('~/.ssh/id_rsa');
// Disable composer --no-dev on dev
task(
'composer:config',
function () {
$stage = Context::get()->getHost()->getConfig()->get('stage');
if ($stage == "dev") {
set(
'composer_options',
'{{composer_action}} --verbose --no-progress --no-interaction --optimize-autoloader'
);
}
}
);
before('deploy:vendors', 'composer:config');
// Reload PHP-FPM
task(
'reload:php-fpm',
function () {
run('sudo /bin/systemctl restart php74-fpm.service');
}
);
// Purge Cache
task(
'silverstripe:purge-cache',
function () {
run('rm -fR ~/{{application}}/shared/silverstripe-cache/*');
}
);
after('deploy', 'reload:php-fpm');
after('deploy', 'silverstripe:purge-cache');
// Tasks
// Thanks to @kinglozzer / BigFork for this!
desc('Populate .env file');
task(
'silverstripe:create_dotenv',
function () {
$envPath = "{{deploy_path}}/shared/.env";
if (test("[ -f {$envPath} ]")) {
return;
}
$dbServer = ask('Please enter the database server', 'localhost');
$dbUser = ask('Please enter the database username');
$dbPass = str_replace("'", "\\'", askHiddenResponse('Please enter the database password'));
$dbName = ask('Please enter the database name', get('application'));
$dbPrefix = Context::get()->getHost()->getConfig()->get('stage') === 'stage' ? '_stage_' : '';
$baseURL = ask('Please enter the baseURL');
$type = Context::get()->getHost()->getConfig()->get('stage');
$contents = <<<ENV
SS_DATABASE_CLASS='MySQLPDODatabase'
SS_DATABASE_USERNAME='{$dbUser}'
SS_DATABASE_PASSWORD='{$dbPass}'
SS_DATABASE_SERVER='{$dbServer}'
SS_DATABASE_NAME='{$dbName}'
SS_DATABASE_PREFIX='{$dbPrefix}'
SS_BASE_URL='{$baseURL}'
SS_ENVIRONMENT_TYPE='{$type}'
ENV;
$command = <<<BASH
cat >{$envPath} <<EOL
$contents
EOL
BASH;
run("$command");
}
)->setPrivate();
before('deploy:vendors', 'silverstripe:create_dotenv');