-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.php
51 lines (36 loc) · 1.54 KB
/
deploy.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
<?php
namespace Deployer;
use Symfony\Component\Console\Input\InputOption;
require 'recipe/symfony.php';
option('artifact-url', null, InputOption::VALUE_REQUIRED, 'The URL to get build artifacts from');
option('circleci-token', null, InputOption::VALUE_REQUIRED, 'The personal Circle CI API token to use');
set('application', 'reliquary');
set('deploy_path', '~/{{application}}');
set('repository', 'git@github.com:johnnoel/reliquary.git');
add('shared_files', []);
add('shared_dirs', []);
add('writable_dirs', []);
host('67.207.69.0')
->setRemoteUser('johnnoel-uk')
;
task('deploy:update_code', function () {
$artifactUrl = input()->getOption('artifact-url');
$circleCiToken = input()->getOption('circleci-token');
if (!is_string($artifactUrl) || !is_string($circleCiToken)) {
throw new \InvalidArgumentException('Either artifact-url or circleci-token not provided');
}
$header = escapeshellarg('Circle-Token: ' . $circleCiToken);
$url = escapeshellarg($artifactUrl);
$jsonRaw = run('curl -sH ' . $header . ' ' . $url);
$json = json_decode($jsonRaw, true);
if (!is_array($json) || count($json) === 0) {
throw new \InvalidArgumentException('Invalid JSON returned: ' . $jsonRaw);
}
$url = escapeshellarg($json[0]['url'] . '?' . http_build_query([
'circle-token' => $circleCiToken,
]));
run('wget -qO reliquary.tar.bz2 ' . $url);
run('tar xjf reliquary.tar.bz2 -C {{release_path}}');
});
task('deploy:vendors', function () { });
after('deploy:failed', 'deploy:unlock');