-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathEnvoy.blade.php.example
92 lines (85 loc) · 2.86 KB
/
Envoy.blade.php.example
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
{{--
# envoy run deploy --env=staging --branch=develop
# 1. 克隆远程仓库
# 2. 安装Composer依赖
# 3. 创建符号链接
# 4. 删除历史部署目录(适用DEV环境)
--}}
@servers(['ecs' => ['[email protected]']])
@setup
$repository = '[email protected]:project/mp.git';
$staging_repository = '[email protected]:project/mp.git';
$releases_dir = '/var/www/project/releases';
$app_dir = '/var/www/project';
$release = date('YmdHis');
$new_release_dir = $releases_dir .'/'. $release;
$branch = isset($branch) ? $branch : "develop";
$env = isset($env) ? $env : "staging";
$user = 'apache';
$current = $app_dir . '/current';
$runtime = $app_dir . '/runtime';
$link_rumtime = $new_release_dir . '/runtime';
@endsetup
@story('deploy')
clone_repository
run_composer
update_symlinks
clear_cache
change_permission
@endstory
@task('clone_repository', ['on' => ['ecs'], 'parallel' => true])
echo 'Cloning repository'
git config --global user.email "[email protected]"
git config --global user.name "Deployer"
[ -d {{ $releases_dir }} ] || mkdir {{ $releases_dir }}
@if ($env == 'staging')
git clone -b {{ $branch }} {{ $staging_repository }} {{ $new_release_dir }}
@else
git clone --depth 1 {{ $repository }} {{ $new_release_dir }}
cd {{ $new_release_dir }}
git reset --hard {{ $commit }}
@endif
@endtask
@task('run_composer', ['on' => ['ecs'], 'parallel' => true])
echo "Starting deployment ({{ $release }})"
cd {{ $new_release_dir }}
composer install --prefer-dist --no-scripts -q -o
@endtask
@task('update_symlinks', ['on' => ['ecs'], 'parallel' => true])
echo "Linking runtime directory"
cd {{ $new_release_dir }}
rm -rf {{ $link_rumtime }}
[ -d {{ $runtime }} ] || mkdir {{ $runtime }}
ln -nfs {{ $runtime }} {{ $link_rumtime }}
echo 'Linking .env file'
@if ($env == 'staging')
cp .env.sandbox .env
@endif
@if ($env == 'production')
cp .env.production .env
@endif
echo 'Linking current release'
ln -nfs {{ $new_release_dir }} {{ $current }}
@endtask
@task('clear_cache', ['on' => ['ecs'], 'parallel' => true])
echo 'Clearing cache'
cd {{ $new_release_dir }}
php think clear
php think migrate:run
php think optimize:autoload
php think optimize:config
php think optimize:route
@if ($env == 'staging')
echo 'Removing earlier app'
cd {{ $releases_dir }}
shopt -s extglob
rm -rf !({{ $release }})
@endif
@endtask
@task('change_permission', ['on' => ['ecs'], 'parallel' => true])
echo 'Changing permission'
chown -R {{ $user }}:{{ $user }} {{ $new_release_dir }}
chown -R {{ $user }}:{{ $user }} {{ $current }}
chown -R {{ $user }}:{{ $user }} {{ $runtime }}
chmod -R 777 {{ $runtime }}
@endtask