1 | <?php |
||
2 | namespace Deployer; |
||
3 | |||
4 | require_once __DIR__ . '/common.php'; |
||
5 | |||
6 | |||
7 | /** |
||
8 | * Symfony Configuration |
||
9 | */ |
||
10 | |||
11 | // Symfony build set |
||
12 | set('symfony_env', 'prod'); |
||
13 | |||
14 | // Symfony shared dirs |
||
15 | set('shared_dirs', ['app/logs']); |
||
16 | |||
17 | // Symfony shared files |
||
18 | set('shared_files', ['app/config/parameters.yml']); |
||
19 | |||
20 | // Symfony writable dirs |
||
21 | set('writable_dirs', ['app/cache', 'app/logs']); |
||
22 | |||
23 | // Clear paths |
||
24 | set('clear_paths', ['web/app_*.php', 'web/config.php']); |
||
25 | |||
26 | // Assets |
||
27 | set('assets', ['web/css', 'web/images', 'web/js']); |
||
28 | |||
29 | // Requires non symfony-core package `kriswallsmith/assetic` to be installed |
||
30 | set('dump_assets', false); |
||
31 | |||
32 | // Environment vars |
||
33 | set('env', function () { |
||
34 | return [ |
||
35 | 'SYMFONY_ENV' => get('symfony_env') |
||
36 | ]; |
||
37 | }); |
||
38 | |||
39 | set('composer_options', function () { |
||
40 | $debug = get('symfony_env') === 'dev'; |
||
41 | return sprintf('{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction %s --optimize-autoloader --no-suggest', (!$debug ? '--no-dev' : '')); |
||
42 | }); |
||
43 | |||
44 | |||
45 | // Adding support for the Symfony3 directory structure |
||
46 | set('bin_dir', 'app'); |
||
47 | set('var_dir', 'app'); |
||
48 | |||
49 | // Symfony console bin |
||
50 | set('bin/console', function () { |
||
51 | return sprintf('{{release_path}}/%s/console', trim(get('bin_dir'), '/')); |
||
52 | }); |
||
53 | |||
54 | // Symfony console opts |
||
55 | set('console_options', function () { |
||
56 | $options = '--no-interaction --env={{symfony_env}}'; |
||
57 | return get('symfony_env') !== 'prod' ? $options : sprintf('%s --no-debug', $options); |
||
58 | }); |
||
59 | |||
60 | // Migrations configuration file |
||
61 | set('migrations_config', ''); |
||
62 | |||
63 | |||
64 | /** |
||
65 | * Create cache dir |
||
66 | */ |
||
67 | task('deploy:create_cache_dir', function () { |
||
68 | // Set cache dir |
||
69 | set('cache_dir', '{{release_path}}/' . trim(get('var_dir'), '/') . '/cache'); |
||
70 | |||
71 | // Remove cache dir if it exist |
||
72 | run('if [ -d "{{cache_dir}}" ]; then rm -rf {{cache_dir}}; fi'); |
||
73 | |||
74 | // Create cache dir |
||
75 | run('mkdir -p {{cache_dir}}'); |
||
76 | |||
77 | // Set rights |
||
78 | run("chmod -R g+w {{cache_dir}}"); |
||
79 | })->desc('Create cache dir'); |
||
80 | |||
81 | |||
82 | /** |
||
83 | * Normalize asset timestamps |
||
84 | */ |
||
85 | task('deploy:assets', function () { |
||
86 | $assets = implode(' ', array_map(function ($asset) { |
||
87 | return "{{release_path}}/$asset"; |
||
88 | }, get('assets'))); |
||
89 | |||
90 | run(sprintf('find %s -exec touch -t %s {} \';\' &> /dev/null || true', $assets, date('YmdHi.s'))); |
||
91 | })->desc('Normalize asset timestamps'); |
||
92 | |||
93 | |||
94 | /** |
||
95 | * Install assets from public dir of bundles |
||
96 | */ |
||
97 | task('deploy:assets:install', function () { |
||
98 | run('{{bin/php}} {{bin/console}} assets:install {{console_options}} {{release_path}}/web'); |
||
99 | })->desc('Install bundle assets'); |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Dump all assets to the filesystem |
||
104 | */ |
||
105 | task('deploy:assetic:dump', function () { |
||
106 | if (get('dump_assets')) { |
||
107 | run('{{bin/php}} {{bin/console}} assetic:dump {{console_options}}'); |
||
108 | } |
||
109 | })->desc('Dump assets'); |
||
110 | |||
111 | /** |
||
112 | * Clear Cache |
||
113 | */ |
||
114 | task('deploy:cache:clear', function () { |
||
115 | run('{{bin/php}} {{bin/console}} cache:clear {{console_options}} --no-warmup'); |
||
116 | })->desc('Clear cache'); |
||
117 | |||
118 | /** |
||
119 | * Warm up cache |
||
120 | */ |
||
121 | task('deploy:cache:warmup', function () { |
||
122 | run('{{bin/php}} {{bin/console}} cache:warmup {{console_options}}'); |
||
123 | })->desc('Warm up cache'); |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Migrate database |
||
128 | */ |
||
129 | task('database:migrate', function () { |
||
130 | $options = '{{console_options}} --allow-no-migration'; |
||
131 | if (get('migrations_config') !== '') { |
||
132 | $options = sprintf('%s --configuration={{release_path}}/{{migrations_config}}', $options); |
||
133 | } |
||
134 | |||
135 | run(sprintf('{{bin/php}} {{bin/console}} doctrine:migrations:migrate %s', $options)); |
||
136 | })->desc('Migrate database'); |
||
137 | |||
138 | |||
139 | /** |
||
140 | * Main task |
||
141 | */ |
||
142 | task('deploy', [ |
||
143 | 'deploy:info', |
||
144 | 'deploy:setup', |
||
145 | 'deploy:lock', |
||
146 | 'deploy:release', |
||
147 | 'deploy:update_code', |
||
148 | 'deploy:clear_paths', |
||
149 | 'deploy:create_cache_dir', |
||
150 | 'deploy:shared', |
||
151 | 'deploy:assets', |
||
152 | 'deploy:vendors', |
||
153 | 'deploy:assets:install', |
||
154 | 'deploy:assetic:dump', |
||
155 | 'deploy:cache:clear', |
||
156 | 'deploy:cache:warmup', |
||
157 | 'deploy:writable', |
||
158 | 'deploy:symlink', |
||
159 | 'deploy:unlock', |
||
160 | 'deploy:cleanup', |
||
161 | ])->desc('Deploy your project'); |
||
162 | |||
163 | // Display success message on completion |
||
164 | after('deploy', 'success'); |
||
165 |