-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathEnvoy.blade.php
140 lines (103 loc) · 3.23 KB
/
Envoy.blade.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
@setup
require __DIR__.'/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
try {
$dotenv->load();
$dotenv->required(['DEPLOY_USER', 'DEPLOY_SERVER', 'DEPLOY_BASE_DIR', 'DEPLOY_REPO'])->notEmpty();
} catch ( Exception $e ) {
echo $e->getMessage();
}
$repo = env('DEPLOY_REPO');
if (!isset($baseDir)) {
$baseDir = env('DEPLOY_BASE_DIR');
}
$branchOrTag = env('CI_COMMIT_TAG');
if (!$branchOrTag) {
$branchOrTag = env('CI_COMMIT_BRANCH', 'master');
}
function logMessage($message) {
return "echo '\033[32m" .$message. "\033[0m';\n";
}
@endsetup
@servers(['prod' => env('DEPLOY_USER').'@'.env('DEPLOY_SERVER')])
@task('rollback', ['on' => 'prod', 'confirm' => true])
{{ logMessage("Rolling back") }}
cd {{ $baseDir }}
git reset --hard HEAD~1
{{ logMessage("Updating composer") }}
rm -rf vendor
composer install --no-interaction --quiet --prefer-dist --optimize-autoloader
{{ logMessage("Updating assets") }}
rm -rf node_modules
npm install --silent --no-progress > /dev/null
npm run prod --silent --no-progress > /dev/null
{{ logMessage("Deleting node_modules folder") }}
rm -rf node_modules
{{ logMessage("Building cache") }}
php {{ $baseDir }}/artisan optimize
{{ logMessage("Rollback complete") }}
@endtask
@story('deploy', ['on' => 'prod'])
git
composer
migrate
npm_install
npm_run_prod
set_permissions
reload_services
cache
@endstory
@task('git')
{{ logMessage("Cloning repository") }}
cd {{ $baseDir }}
git fetch origin
git reset --hard origin/{{ $branchOrTag }}
@endtask
@task('composer')
{{ logMessage("Running composer") }}
cd {{ $baseDir }}
rm -rf vendor
composer install --no-interaction --quiet --prefer-dist --optimize-autoloader
@endtask
@task('npm_install')
{{ logMessage("NPM install") }}
cd {{ $baseDir }}
rm -rf node_modules
npm install --silent --no-progress > /dev/null
@endtask
@task('npm_run_prod')
{{ logMessage("NPM run prod") }}
cd {{ $baseDir }}
npm run prod --silent --no-progress > /dev/null
@endtask
@task('set_permissions')
# Set dir permissions
{{ logMessage("Set permissions") }}
sudo chown -R root:www-data {{ $baseDir }}
sudo chmod -R ug+rwx {{ $baseDir }}/storage {{ $baseDir }}/bootstrap/cache
@endtask
@task('cache')
{{ logMessage("Building cache") }}
php {{ $baseDir }}/artisan optimize
@endtask
@task('migrate', ['on' => 'prod', 'confirm' => true])
{{ logMessage("Running migrations") }}
php {{ $baseDir }}/artisan migrate --force
@endtask
@task('migrate_rollback', ['on' => 'prod', 'confirm' => true])
{{ logMessage("Rolling back migrations") }}
php {{ $baseDir }}/artisan migrate:rollback --force
@endtask
@task('migrate_status', ['on' => 'prod'])
php {{ $baseDir }}/artisan migrate:status
@endtask
@task('reload_services', ['on' => 'prod'])
# Reload Services
{{ logMessage("Restarting service supervisor") }}
sudo supervisorctl restart all
{{ logMessage("Reloading php") }}
sudo systemctl reload php7.3-fpm
@endtask
@finished
echo "Envoy deployment script finished.\r\n";
@endfinished