-
Notifications
You must be signed in to change notification settings - Fork 0
/
Envoy.blade.php
89 lines (73 loc) · 2.3 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
@servers([ 'remote' => 'fuelmonitor@ymoq.de'])
@setup
if ( ! isset($repo) )
{
throw new Exception('--repo must be specified');
}
if ( ! isset($base_dir) )
{
throw new Exception('--base_dir must be specified');
}
$branch = isset($branch) ? $branch : 'master';
$repo_array = explode('/', $repo);
$repo_name = array_pop($repo_array);
$repo = 'https://api.github.com/repos/' . $repo . '/tarball/' . $branch;
$release_dir = $base_dir . '/source';
$current_dir = $base_dir . '/webroot';
$release = date('YmdHis');
$env = isset($env) ? $env : 'staging';
@endsetup
@macro('deploy', [ 'on' => 'remote', ])
fetch_repo
run_composer
update_symlinks
link_config
update_permissions
clean_old_releases
@endmacro
@task('fetch_repo')
[ -d {{ $release_dir }} ] || mkdir {{ $release_dir }};
cd {{ $release_dir }};
# Make the release dir
mkdir {{ $release }};
# Download the tarball
echo 'Fetching project tarball from {{ $repo }}';
curl -H "Authorization: token {{ $token }}" -sLo {{ $release }}.tar.gz {{ $repo }};
# Extract the tarball
echo 'Extracting tarball';
tar --strip-components=1 -zxf {{ $release }}.tar.gz -C {{ $release }};
# Purge temporary files
echo 'Purging temporary files';
rm -rf {{ $release }}.tar.gz;
@endtask
@task('run_composer')
echo 'Installing composer dependencies';
cd {{ $release_dir }}/{{ $release }};
composer install --prefer-dist --no-scripts -q -o;
@endtask
@task('update_symlinks')
echo 'Updating symlinks';
# Symlink the latest release to the current directory
echo 'Linking current release';
ln -nfs source/{{ $release }} {{ $current_dir }};
@endtask
@task('link_config')
echo 'Linking config files into new version workspace';
cp -rs {{ $base_dir }}/configs/*.json {{ $current_dir }};
@endtask
@task('update_permissions')
cd {{ $release_dir }}/{{ $release }};
echo 'Updating directory permissions';
find . -type d -exec chmod 775 {} \;
echo 'Updating file permissions';
find . -type f -exec chmod 664 {} \;
@endtask
@task('clean_old_releases')
echo 'Purging old releases';
# This will list our releases by modification time and delete all but the 5 most recent.
ls -dt {{ $release_dir }}/* | tail -n +8 | xargs -d '\n' rm -rf;
@endtask
@task('update_version')
echo 'Updating version number';
sed -ie "s/\"version\"\(.*\):.*$/\"version\"\1: {{ $build }}/g" preferences-*.json;
@endtask