forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymfony.php
156 lines (119 loc) · 3.74 KB
/
symfony.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
149
150
151
152
153
154
155
156
<?php
namespace Deployer;
require_once __DIR__ . '/common.php';
/**
* Symfony Configuration
*/
// Symfony build set
set('symfony_env', 'prod');
// Symfony shared dirs
set('shared_dirs', ['app/logs']);
// Symfony shared files
set('shared_files', ['app/config/parameters.yml']);
// Symfony writable dirs
set('writable_dirs', ['app/cache', 'app/logs']);
// Clear paths
set('clear_paths', ['web/app_*.php', 'web/config.php']);
// Assets
set('assets', ['web/css', 'web/images', 'web/js']);
// Requires non symfony-core package `kriswallsmith/assetic` to be installed
set('dump_assets', false);
// Environment vars
set('env', function () {
return [
'SYMFONY_ENV' => get('symfony_env')
];
});
set('composer_options', function () {
$debug = get('symfony_env') === 'dev';
return sprintf('--verbose --prefer-dist --no-progress --no-interaction %s --optimize-autoloader --no-suggest', (!$debug ? '--no-dev' : ''));
});
// Adding support for the Symfony3 directory structure
set('bin_dir', 'app');
set('var_dir', 'app');
// Symfony console bin
set('bin/console', function () {
return sprintf('{{release_path}}/%s/console', trim(get('bin_dir'), '/'));
});
// Symfony console opts
set('console_options', function () {
$options = '--no-interaction --env={{symfony_env}}';
return get('symfony_env') !== 'prod' ? $options : sprintf('%s --no-debug', $options);
});
// Migrations configuration file
set('migrations_config', '');
/**
* Create cache dir
*/
task('deploy:create_cache_dir', function () {
// Set cache dir
set('cache_dir', '{{release_path}}/' . trim(get('var_dir'), '/') . '/cache');
// Remove cache dir if it exist
run('if [ -d "{{cache_dir}}" ]; then rm -rf {{cache_dir}}; fi');
// Create cache dir
run('mkdir -p {{cache_dir}}');
// Set rights
run("chmod -R g+w {{cache_dir}}");
})->desc('Create cache dir');
/**
* Normalize asset timestamps
*/
task('deploy:assets', function () {
$assets = implode(' ', array_map(function ($asset) {
return "{{release_path}}/$asset";
}, get('assets')));
run(sprintf('find %s -exec touch -t %s {} \';\' &> /dev/null || true', $assets, date('YmdHi.s')));
})->desc('Normalize asset timestamps');
/**
* Install assets from public dir of bundles
*/
task('deploy:assets:install', function () {
run('{{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web');
})->desc('Install bundle assets');
/**
* Dump all assets to the filesystem
*/
task('deploy:assetic:dump', function () {
if (get('dump_assets')) {
run('{{bin/php}} {{bin/console}} assetic:dump {{console_options}}');
}
})->desc('Dump assets');
/**
* Clear Cache
*/
task('deploy:cache:clear', function () {
run('{{bin/php}} {{bin/console}} cache:clear {{console_options}} --no-warmup');
})->desc('Clear cache');
/**
* Warm up cache
*/
task('deploy:cache:warmup', function () {
run('{{bin/php}} {{bin/console}} cache:warmup {{console_options}}');
})->desc('Warm up cache');
/**
* Migrate database
*/
task('database:migrate', function () {
$options = '{{console_options}} --allow-no-migration';
if (get('migrations_config') !== '') {
$options = sprintf('%s --configuration={{release_path}}/{{migrations_config}}', $options);
}
run(sprintf('{{bin/php}} {{bin/console}} doctrine:migrations:migrate %s', $options));
})->desc('Migrate database');
/**
* Main task
*/
task('deploy', [
'deploy:prepare',
'deploy:clear_paths',
'deploy:create_cache_dir',
'deploy:assets',
'deploy:vendors',
'deploy:assets:install',
'deploy:assetic:dump',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:publish',
])->desc('Deploy your project');
// Display success message on completion
after('deploy', 'success');