forked from papertank/envoy-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvoy.blade.php
74 lines (63 loc) · 1.98 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
@include('envoy.config.php');
@servers(['web' => $ssh])
@setup
if ( ! isset($ssh) ) {
throw new Exception('SSH login username/host is not set');
}
if ( ! isset($repo) ) {
throw new Exception('Git repository is not set');
}
if ( ! isset($path) ) {
throw new Exception('Path is not set');
}
if ( substr($path, 0, 1) !== '/' ) {
throw new Exception('Careful - your path does not begin with /');
}
$now = new DateTime();
$date = $now->format('YmdHis');
$env = isset($env) ? $env : "production";
$branch = isset($branch) ? $branch : "master";
$path = rtrim($path, '/');
$release = $path.'/'.$date;
@endsetup
@task('init')
cd {{ $path }};
git clone {{ $repo }} --branch={{ $branch }} --depth=1 {{ $release }};
echo "Repository cloned";
mv {{ $release }}/storage {{ $path }}/storage;
ln -s {{ $path }}/storage {{ $release }}/storage;
echo "Storage directory set up";
cp {{ $release }}/.env.example {{ $path }}/.env;
ln -s {{ $path }}/.env {{ $release }}/.env;
echo "Environment file set up";
cd {{ $release }};
composer install --no-interaction;
php artisan migrate --env={{ $env }} --force --no-interaction;
ln -s {{ $release }} {{ $path }}/current;
echo "Initial deployment ({{ $date }}) complete";
@endtask
@macro('deploy_cleanup')
deploy
cleanup
@endmacro
@task('deploy')
cd {{ $path }};
git clone {{ $repo }} --branch={{ $branch }} --depth=1 {{ $release }};
echo "Repository cloned";
rm -rf {{ $release }}/storage;
ln -s {{ $path }}/storage {{ $release }}/storage;
echo "Storage directory set up";
ln -s {{ $path }}/.env {{ $release }}/.env;
echo "Environment file set up";
cd {{ $release }};
composer install --no-interaction;
php artisan migrate --env={{ $env }} --force --no-interaction;
rm {{ $path }}/current;
ln -s {{ $release }} {{ $path }}/current;
echo "Deployment ({{ $date }}) complete";
@endtask
@task('cleanup')
cd {{ $path }};
find . -maxdepth 1 -name "20*" -mmin +2880 | head -n 5 | xargs rm -Rf;
echo "Cleaned up old deploments";
@endtask