show drone logs
This commit is contained in:
parent
9ad3cf1aef
commit
908bdb59cb
@ -83,6 +83,97 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
|
||||
'build' => $build
|
||||
];
|
||||
},
|
||||
'fetchLogs' => function ($build) {
|
||||
$settings = $this->app->storage->findOne('drone/settings') ?? FALSE;
|
||||
|
||||
if (!$settings || !isset($settings['url'],
|
||||
$settings['owner'],
|
||||
$settings['project'],
|
||||
$settings['target'],
|
||||
$settings['token']) || !$settings['active']) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$url = trim($settings['url'], "/") . '/api/repos/' . $settings['owner'] . '/' . $settings['project'] . '/builds/'. $build;
|
||||
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json',
|
||||
'Authorization: Bearer ' . $settings['token']
|
||||
];
|
||||
|
||||
$logstr = "";
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$b = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$b = json_decode($b);
|
||||
|
||||
$colors = [
|
||||
'/\\033?\[(?:0;)?30m(.*?)\\033?\[0m/s' => '<span class="black">$1</span>',
|
||||
'/\\033?\[(?:0;)?31m(.*?)\\033?\[0m/s' => '<span class="red">$1</span>',
|
||||
'/\\033?\[(?:0;)?32m(.*?)\\033?\[0m/s' => '<span class="green">$1</span>',
|
||||
'/\\033?\[(?:0;)?33m(.*?)\\033?\[0m/s' => '<span class="brown">$1</span>',
|
||||
'/\\033?\[(?:0;)?34m(.*?)\\033?\[0m/s' => '<span class="blue">$1</span>',
|
||||
'/\\033?\[(?:0;)?35m(.*?)\\033?\[0m/s' => '<span class="purple">$1</span>',
|
||||
'/\\033?\[(?:0;)?36m(.*?)\\033?\[0m/s' => '<span class="cyan">$1</span>',
|
||||
'/\\033?\[(?:0;)?37m(.*?)\\033?\[0m/s' => '<span class="light-gray">$1</span>',
|
||||
|
||||
'/\\033?\[1;30m(.*?)\\033?\[0m/s' => '<span class="dark-gray">$1</span>',
|
||||
'/\\033?\[1;31m(.*?)\\033?\[0m/s' => '<span class="light-red">$1</span>',
|
||||
'/\\033?\[1;32m(.*?)\\033?\[0m/s' => '<span class="light-green">$1</span>',
|
||||
'/\\033?\[1;33m(.*?)\\033?\[0m/s' => '<span class="yellow">$1</span>',
|
||||
'/\\033?\[1;34m(.*?)\\033?\[0m/s' => '<span class="light-blue">$1</span>',
|
||||
'/\\033?\[1;35m(.*?)\\033?\[0m/s' => '<span class="light-purple">$1</span>',
|
||||
'/\\033?\[1;36m(.*?)\\033?\[0m/s' => '<span class="light-cyan">$1</span>',
|
||||
'/\\033?\[1;37m(.*?)\\033?\[0m/s' => '<span class="white">$1</span>',
|
||||
|
||||
'/\\033?\[0m/s' => '',
|
||||
];
|
||||
|
||||
foreach ($b->stages as $stage) {
|
||||
foreach ($stage->steps as $step) {
|
||||
|
||||
$logstr .= '<div class="stagename">Stage: '.$stage->name.'</div>';
|
||||
$logstr .= '<h2 class="'.$step->status.'">'.$step->name.'</h2><br>';
|
||||
|
||||
$step_url = $url . '/logs/' . $stage->number . '/' . $step->number;
|
||||
$ch = curl_init($step_url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$logs = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$logs = json_decode($logs);
|
||||
|
||||
foreach ($logs as $l) {
|
||||
if (preg_match('/^\\+/', $l->out)) {
|
||||
$logstr .= '<h3>'.htmlspecialchars($l->out).'</h3>';
|
||||
} else {
|
||||
$logstr .= preg_replace(array_keys($colors), $colors, htmlspecialchars($l->out));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'out' => $logstr
|
||||
];
|
||||
},
|
||||
|
||||
|
||||
'createDeploy' => function ($fromBuild) {
|
||||
$settings = $this->app->storage->findOne('drone/settings');
|
||||
|
@ -1,7 +1,56 @@
|
||||
<style>
|
||||
.uk-modal-details .uk-modal-dialog {
|
||||
.uk-modal-details .uk-modal-dialog, .uk-modal-logs .uk-modal-dialog {
|
||||
height: 85%;
|
||||
}
|
||||
|
||||
.uk-modal-logs pre {
|
||||
color: #d3d3d3;
|
||||
background-color: #333;
|
||||
}
|
||||
|
||||
.black { color: #000; }
|
||||
.red { color: #FF0000; }
|
||||
.green { color: #008000; }
|
||||
.brown { color: #A52A2A; }
|
||||
.blue { color: #0000FF; }
|
||||
.purple { color: #800080; }
|
||||
.cyan { color: #00FFFF; }
|
||||
.light-gray { color: #D3D3D3; }
|
||||
.dark-gray { color: #A9A9A9; }
|
||||
.light-red { color: #f55; }
|
||||
.light-green { color: #90EE90; }
|
||||
.yellow { color: #FFFF00; }
|
||||
.light-blue { color: #ADD8E6; }
|
||||
.light-purple { color: #9370DB; }
|
||||
.light-cyan { color: #E0FFFF; }
|
||||
.white { color: #fff; }
|
||||
|
||||
pre {
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
pre h2 {
|
||||
color: black;
|
||||
display: inline-block;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
font-size: 1.5em;
|
||||
background-color: #d3d3d3;
|
||||
}
|
||||
pre h2.success {
|
||||
background-color: #60cc60;
|
||||
}
|
||||
|
||||
pre h2.failure {
|
||||
background-color: #ff3333;
|
||||
}
|
||||
|
||||
.stagename {
|
||||
float: right;
|
||||
font-size: 0.8em;
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div>
|
||||
@ -42,6 +91,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="uk-modal uk-modal-logs uk-height-viewport">
|
||||
<div class="uk-modal-dialog uk-modal-dialog-large">
|
||||
<a href="" class="uk-modal-close uk-close"></a>
|
||||
<h3>{ deploy && deploy.title }</h3>
|
||||
<div class="uk-margin uk-flex uk-flex-middle" if="{deploy}">
|
||||
<pre style="display: inline-block;"></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="uk-form uk-clearfix" show="{!loading}">
|
||||
<table class="uk-table uk-table-tabbed uk-table-striped uk-margin-top" if="{ !loading && deploys.length }">
|
||||
<thead>
|
||||
@ -52,6 +111,9 @@
|
||||
<th class="uk-text-small uk-link-muted uk-noselect" width="50">
|
||||
@lang('Build') #
|
||||
</th>
|
||||
<th class="uk-text-small uk-link-muted uk-noselect" width="50">
|
||||
@lang('Event')
|
||||
</th>
|
||||
<th class="uk-text-small uk-link-muted uk-noselect" width="450">
|
||||
@lang('Title')
|
||||
</th>
|
||||
@ -64,6 +126,9 @@
|
||||
<th class="uk-text-small uk-link-muted uk-noselect" width="90">
|
||||
@lang('Deploy time')
|
||||
</th>
|
||||
<th class="uk-text-small uk-link-muted uk-noselect" width="50">
|
||||
@lang('Log')
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -77,10 +142,12 @@
|
||||
</a>
|
||||
</td>
|
||||
<td>{ deploy.number }</td>
|
||||
<td>{ deploy.event }: { deploy.message }</td>
|
||||
<td>{ deploy.event }</td>
|
||||
<td>{ deploy.message }</td>
|
||||
<td><span class="uk-badge uk-badge-outline uk-text-muted">{ deploy.created_at }</span></td>
|
||||
<td><span class="uk-badge uk-badge-outline uk-text-muted">{ deploy.updated_at }</span></td>
|
||||
<td><span if="{deploy.deploy_time}">{ deploy.deploy_time }s</span></td>
|
||||
<td><a onclick="{ showdeployLog }"><img src="@url('assets:app/media/icons/text.svg')" style="height: 25px;"></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -99,6 +166,7 @@
|
||||
this.on('mount', function() {
|
||||
$this.loading = false;
|
||||
$this.modal = UIkit.modal(App.$('.uk-modal-details', this.root), {modal:true});
|
||||
$this.modalLogs = UIkit.modal(App.$('.uk-modal-logs', this.root), {modal:true});
|
||||
if ($this.building) {
|
||||
setTimeout(function() {
|
||||
$this.fetchData();
|
||||
@ -113,11 +181,29 @@
|
||||
editor = $this.refs.codemirror.editor;
|
||||
editor.setValue(JSON.stringify($this.deploy, null, 2), true);
|
||||
editor.setOption("readOnly", true);
|
||||
editor.setOption("mode", "javascript");
|
||||
editor.setSize($this.modal.dialog[0].clientWidth - 50, $this.modal.dialog[0].clientHeight - 70);
|
||||
editor.refresh();
|
||||
$this.trigger('ready');
|
||||
}
|
||||
|
||||
showdeployLog(e) {
|
||||
$this.deploy = e.item.deploy;
|
||||
App.callmodule('drone:fetchLogs', $this.deploy['number'], 'manage.view').then(function(data) {
|
||||
if (data && data.result && data.result.out) {
|
||||
area = App.$('.uk-modal-logs pre');
|
||||
area.html(data.result.out);
|
||||
$this.modalLogs.show();
|
||||
area.css('width', $this.modalLogs.dialog[0].clientWidth - 50);
|
||||
area.css('height', $this.modalLogs.dialog[0].clientHeight - 70);
|
||||
$this.trigger('ready');
|
||||
} else {
|
||||
App.ui.notify(App.i18n.get("Cannot fetch logs from Drone! Try again later."), "danger");
|
||||
}
|
||||
$this.update();
|
||||
});
|
||||
}
|
||||
|
||||
createDeploy() {
|
||||
if ($this.building) {
|
||||
App.ui.notify(App.i18n.get("A deploy is already in progress, please wait until finishes."), "warning");
|
||||
@ -135,6 +221,7 @@
|
||||
editor = $this.refs.codemirror.editor;
|
||||
editor.setValue(JSON.stringify(data, null, 2), true);
|
||||
editor.setOption("readOnly", true);
|
||||
editor.setOption("mode", "javascript");
|
||||
editor.setSize($this.modal.dialog[0].clientWidth - 50, $this.modal.dialog[0].clientHeight - 70);
|
||||
editor.refresh();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user