forked from Catrobat/Catroweb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.php
170 lines (140 loc) · 4.21 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
namespace Deployer;
use Symfony\Component\Dotenv\Dotenv;
require 'recipe/symfony3.php';
require 'recipe/slack.php';
// Load .env file
(new Dotenv(true))->load('.env');
(new Dotenv(true))->load('.env.local');
// Project name
set('application', getenv('APP_NAME'));
set('repository', getenv('DEPLOY_GIT'));
set('git_tty', false);
// Slack Data
set('slack_webhook', getenv(('SLACK_WEBHOOK')));
set('slack_text', 'Web-Team deploying `{{branch}}` to *{{target}}*');
set('slack_success_text', 'Deploy to *{{target}}* successful');
set('slack_success_color', '#4BB543');
// Symfony build set
set('symfony_env', 'prod');
// Symfony shared dirs
set('shared_dirs',
[
'var/log',
'var/sessions',
'public/resources'
]);
// Shared files between deploys
add('shared_files',
[
'.env.local',
'.env.prod.local',
'.env.dev.local'
]);
// Symfony writable dirs
set('writable_dirs',
[
'var/cache',
'var/log',
'var/sessions'
]);
// Symfony executable and variable directories
set('bin_dir', 'bin');
set('var_dir', 'var');
set('web_dir', 'public');
set('public_dir', 'public');
set('allow_anonymous_stats', false);
// Hosts
host(getenv('DEPLOY_SHARE'))
->stage('share')
->set('symfony_env', 'prod')
->set('branch', 'release/v3.4.3')
->set('composer_options','install --verbose --prefer-dist --optimize-autoloader')
->set('deploy_path', '/var/www/share/');
host(getenv('DEPLOY_WEBTEST'))
->stage('web-test')
->set('symfony_env', 'dev')
->set('branch', getenv('DEPLOY_WEBTEST_BRANCH'))
->set('composer_options','install --verbose --prefer-dist --optimize-autoloader')
->set('deploy_path', '/var/www/share/');
host(getenv('DEPLOY_POREVIEW'))
->stage('po-review')
->set('symfony_env', 'dev')
->set('branch', getenv('DEPLOY_POREVIEW_BRANCH'))
->set('composer_options','install --verbose --prefer-dist --optimize-autoloader')
->set('deploy_path', '/var/www/share/');
host(getenv('DEPLOY_CATBLOCKS'))
->stage('catblocks')
->set('symfony_env', 'dev')
->set('branch', getenv('DEPLOY_CATBLOCKS_BRANCH'))
->set('composer_options','install --verbose --prefer-dist --optimize-autoloader')
->set('deploy_path', '/var/www/share/');
host(getenv('DEPLOY_ANDROID'))
->stage('android')
->set('symfony_env', 'prod')
->set('branch', getenv('DEPLOY_ANDROID_BRANCH'))
->set('composer_options','install --verbose --prefer-dist --optimize-autoloader --no-dev')
->set('deploy_path', '/var/www/share/');
// Tasks
// Manually define this task because deployer uses the old symfony structure with web instead of
// public. Change this when deployer gets updated.
task('install:assets', function () {
run('{{bin/php}} {{bin/console}} assets:install --symlink --relative public');
});
// For such sudo commands to work, the server must allow those commands without a password
// change the sudoers file if needed!
task('restart:nginx', function () {
run('sudo /usr/sbin/service nginx restart');
});
task('restart:php-fpm', function () {
run('sudo /usr/sbin/service php7.4-fpm restart');
});
task('install:npm', function () {
cd('{{release_path}}');
run('npm install');
});
task('deploy:grunt', function () {
cd('{{release_path}}');
run('grunt');
});
task('deploy:jwt', function () {
cd('{{release_path}}');
run('sh docker/app/init-jwt-config.sh');
});
/**
* Main task
*/
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:clear_paths',
'deploy:create_cache_dir',
'deploy:shared',
'deploy:assets',
'deploy:vendors',
'deploy:assetic:dump',
'install:assets',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:writable',
'deploy:symlink',
'database:migrate',
'install:npm',
'deploy:grunt',
'deploy:jwt',
'restart:nginx',
'restart:php-fpm',
'deploy:unlock',
'slack:notify:success',
'cleanup',
])->desc('Deploy Catroweb!');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release.
// should maybe not be done automatically. we can do that no problem but that is not that nice.
//before('deploy:symlink', 'database:migrate');
before('deploy:prepare', 'slack:notify');
after('deploy:failed', 'slack:notify:failure');