-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.php
137 lines (118 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
<?php
namespace Deployer;
require 'recipe/common.php';
/**
* Run a craft command.
*
* Supported options:
*
* @param string $command The craft command (with cli options if any).
* @param array $options The options that define the behaviour of the command.
* @return callable A function that can be used as a task.
*/
function craft($command, $options = [])
{
return function() use ($command, $options) {
if (! test('[ -s {{release_path}}/.env ]')) {
throw new \Exception('Your .env file is empty! Cannot proceed.');
}
$output = run("cd {{release_path}} && {{bin/php}} craft $command");
if (in_array('showOutput', $options)) {
writeln("<info>$output</info>");
}
};
}
/*
|--------------------------------------------------------------------------
| Setup Deploy
|--------------------------------------------------------------------------
*/
set('application', 'My New Website');
set('repository', '/path/to/github/repository'); // github repository
set('allow_anonymous_stats', false);
set('git_tty', false);
set('strategy', 'upload');
set('shared_dirs', [
'storage',
'web/images',
'web/uploads',
// or any other directory
]);
set('shared_files', [
'.env',
// or any other file
]);
set('writable_dirs', [
'storage',
'storage/runtime',
'storage/logs',
'storage/rebrand',
'web/cpresources',
'web/images',
'web/uploads',
// or any other directory
]);
/*
|--------------------------------------------------------------------------
| Upload Options
|--------------------------------------------------------------------------
*/
set('upload_options', function () {
$options = [
'--exclude=.git',
'--exclude=node_modules',
];
return compact('options');
});
/*
|--------------------------------------------------------------------------
| Upload Task
|--------------------------------------------------------------------------
*/
desc('Upload a given folder to your hosts');
task('upload', function () {
$configs = array_merge_recursive(get('upload_options'), [
'options' => ['--delete']
]);
upload( __DIR__ . '/', '{{release_path}}', $configs);
});
/*
|--------------------------------------------------------------------------
| Migrate Task
|--------------------------------------------------------------------------
| This task handle the migration of the craft database using the default
| enviroment options. This ensure there will not be errors loading
| the website before any updated is completed.
*/
desc('Execute craft migrate');
task('craft:migrate', craft('migrate/all'))->once();
/*
|--------------------------------------------------------------------------
| Server Setup
|--------------------------------------------------------------------------
*/
host('my.host.name')
->user('root') // remote server username
->set('deploy_path', '/path/to/remote')
->set('branch', 'master');
/*
|--------------------------------------------------------------------------
| Deploy
|--------------------------------------------------------------------------
*/
desc('Upload Strategy');
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'upload',
'deploy:shared',
'deploy:writable',
'craft:migrate',
'deploy:symlink',
'deploy:unlock',
'cleanup',
'success'
]);