-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.php
More file actions
160 lines (120 loc) · 3.69 KB
/
deploy.php
File metadata and controls
160 lines (120 loc) · 3.69 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* Keep this version number to manage file versions in projects
*
* @version 1.4
*/
namespace Deployer;
require 'recipe/laravel.php';
require 'contrib/rsync.php';
/* ----------------------------------
* Configs
*/
$applicationName = 'GitLab deployment automation';
$github_oauth_token = '66ef4719f8d2c3894631d12cd9d71fab27300eae';
/* ----------------------------------
* Gitlab CI/CD variables
*/
// prepare variables from environment CI_ENV
$IDENTITY_FILE = '~/.ssh/id_rsa';
$CI_REPOSITORY_URL = getenv('CI_REPOSITORY_URL');
$CI_COMMIT_REF_NAME = getenv('CI_COMMIT_REF_NAME');
$BIN_PHP = getenv('BIN_PHP');
$BIN_COMPOSER = getenv('BIN_COMPOSER');
$DEPLOY_BASE_DIR = getenv('DEPLOY_BASE_DIR');
$DEPLOY_SERVER = getenv('DEPLOY_SERVER');
$DEPLOY_USER = getenv('DEPLOY_USER');
$SSH_PORT = getenv('SSH_PORT');
/*CI_ENV*/ // - do not remote this comment. Uses for replacement.
/* ----------------------------------
* Configs
*/
set('application', $applicationName);
// github token
set('github_oauth_token', $github_oauth_token);
// Project git repository url
set('repository', $CI_REPOSITORY_URL);
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', false);
set('allow_anonymous_stats', false);
set('keep_releases', 1);
set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader');
/* ----------------------------------
* rsync settings
*/
set('rsync_src', __DIR__ . '/public');
set('rsync_dest', '{{release_path}}/public');
set('rsync', [
'exclude' => [],
'exclude-file' => false,
'include' => [],
'include-file' => false,
'filter' => [],
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'rz', // Recursive, with compress
'options' => [],
'timeout' => 60,
]);
/* ----------------------------------
* Hosts settings
*/
host($DEPLOY_SERVER)
->setHostname($DEPLOY_SERVER)
->setLabels(['stage' => $CI_COMMIT_REF_NAME])
->setPort(intval($SSH_PORT))
->set('remote_user', $DEPLOY_USER)
->set('branch', $CI_COMMIT_REF_NAME)
->set('deploy_path', $DEPLOY_BASE_DIR)
->set('http_user', $DEPLOY_USER)
->set('bin/php', $BIN_PHP)
->set('bin/composer', $BIN_COMPOSER)
->setIdentityFile($IDENTITY_FILE)
->setSshArguments([
'-o UserKnownHostsFile=/dev/null',
'-o StrictHostKeyChecking=no',
'-o IdentitiesOnly=yes',
]);
/* ----------------------------------
* Main deploy tasks
*/
// Hooks
after('deploy:failed', 'deploy:unlock');
// Additional tasks
before('deploy:shared', 'rsync');
before('artisan:migrate', function () {
$releaseNumber = intval(get('release_name'));
// 3 attempts to successfully deploy and migrate
if ($releaseNumber > 3) {
invoke('artisan:migrate:status');
}
});
task('artisan:app:configure-telegram', artisan('app:configure-telegram'));
// if project uses Telescope, recommended prune old entries
//after('artisan:migrate', 'artisan:telescope:prune');
// Maintenance mode
//after('deploy:vendors', 'artisan:down');
//after('deploy:unlock', 'artisan:up');
/*
* Note:
* `deploy` task copied from `recipe/laravel.php` file
* and removed tasks for caching
*/
desc('Deploys your project');
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'artisan:storage:link',
// remove all cached files or run
'artisan:optimize:clear',
// or call individually only needed
/* 'artisan:cache:clear', */
/* 'artisan:config:clear', */
/* 'artisan:event:clear', */
/* 'artisan:optimize:clear', */
/* 'artisan:route:clear', */
/* 'artisan:view:clear', */
'artisan:migrate',
'artisan:app:configure-telegram',
'deploy:publish',
]);