-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
138 lines (106 loc) · 3.84 KB
/
Copy pathdeploy.php
File metadata and controls
138 lines (106 loc) · 3.84 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
<?php
require_once "recipe/common.php";
// Loading servers configuration file
serverList('servers.yml');
// Re-define composer options to ignore php version
env('composer_options', 'install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress --no-interaction --ignore-platform-reqs');
// Re-define used php version
env('bin/php', function () {
return run('which php5.5-cli')->toString();
});
// Re-define composer paths
env('bin/composer', function () {
$releasePath = run("cd {{release_path}} && pwd -P")->toString();
if (commandExist('composer')) {
$composer = run('which composer')->toString();
}
if (empty($composer)) {
run("cd " . $releasePath . " && curl -sS https://getcomposer.org/installer | {{bin/php}}");
$composer = '{{bin/php}} ' . $releasePath . '/composer.phar';
}
return $composer;
});
// Set default deployment stage
set('default_stage', 'staging');
// Set directories to copy
set('upload_dirs', [
'public/index.php',
'public/.htaccess',
'public/js/main.min.js',
'public/img/',
'public/css/main.css',
'module/',
'config/application.config.php',
'config/modules.config.php',
'config/autoload/global.php',
'data/language/en_GB.po',
'composer.json',
]);
// Set shared directories to copy
set('cache_dirs', [
'data/cache',
]);
// Set writables directories to copy
set('writable_dirs', get('cache_dirs'));
// By default, we don't have sudo capabilities
set('writable_use_sudo', false);
// Define uploading deployment task
task('deploy:upload_dirs', function() {
$files = get('upload_dirs');
$releasePath = env('release_path');
foreach ($files as $file)
{
upload($file, "{$releasePath}/{$file}");
}
});
// Create database configuration file
task('deploy:config', function() {
$templateFilename = __DIR__ . "/config/autoload/local.php.template";
$targetFilename = __DIR__ . "/config/autoload/local.php";
$remoteFilename = "config/autoload/local.php";
$releasePath = env('release_path');
// Get the database config
$config = env('database');
// Load the template file
writeLn("Loading template configuration file <info>" . $templateFilename . "</info>.");
$template = file_get_contents($templateFilename);
// Replace entries in the template file
$template = str_replace("@@DSN@@", $config['dsn'], $template);
$template = str_replace("@@USERNAME@@", $config['username'], $template);
$template = str_replace("@@PASSWORD@@", $config['password'], $template);
// Write the non templated file
file_put_contents($targetFilename, $template);
// Upload config file to server
upload($targetFilename, "{$releasePath}/{$remoteFilename}");
// Remove created file
runLocally("rm -f " . $targetFilename);
})->desc('Installing database configuration file');
// Create cache diretories
task('deploy:cache_dirs', function() {
$files = get('cache_dirs');
$releasePath = env('release_path');
foreach ($files as $file)
{
run('cd {{release_path}} && if [ ! -d ' . $file . ' ]; then mkdir -p ' . $file . '; fi');
}
})->desc('Create cache diretories');
// Re-define symlink deployment task
task('deploy:symlink', function () {
$releasePath = run("cd {{release_path}} && pwd -P")->toString();
run("cd {{deploy_path}} && ln -sfn " . $releasePath . " current"); // Atomic override symlink.
run("cd {{deploy_path}} && rm release"); // Remove release link.
})->desc('Creating symlink to release');
// Define production deployment task
task('deploy', [
'deploy:prepare',
'deploy:release',
'deploy:upload_dirs',
'deploy:cache_dirs',
'deploy:config',
'deploy:writable',
'deploy:vendors',
'deploy:symlink',
'current',
])->desc('Deploy application.');
// Display message on successful deployment
after('deploy', 'success');