config now in settings
This commit is contained in:
parent
311e8e49ba
commit
71edd8bbf3
42
Controller/Settings.php
Normal file
42
Controller/Settings.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drone\Controller;
|
||||||
|
|
||||||
|
use \Cockpit\AuthController;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings controller class.
|
||||||
|
*/
|
||||||
|
class Settings extends AuthController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default index controller.
|
||||||
|
*/
|
||||||
|
public function index() {
|
||||||
|
if (!$this->app->module('cockpit')->hasaccess('drone', 'manage.settings')) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$drone = $this->app->storage->findOne('drone/settings');
|
||||||
|
|
||||||
|
return $this->render('drone:views/settings/index.php', compact('drone'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save() {
|
||||||
|
if ($data = $this->param('drone', false)) {
|
||||||
|
|
||||||
|
$data['_modified'] = time();
|
||||||
|
|
||||||
|
if (!isset($data['_id'])) {
|
||||||
|
$data['_created'] = $data['_modified'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->app->storage->save('drone/settings', $data);
|
||||||
|
|
||||||
|
return json_encode($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
23
README.md
23
README.md
@ -13,20 +13,17 @@ It provides an integration with Drone CI promote feature to trigger a pipeline r
|
|||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
1. Ensure that from your Drone account you have an access token and permissions to promote a build for the project and branch, you want to use.
|
1. Ensure that from your Drone account you have an access token and permissions to promote a build for the project and branch, you want to use.
|
||||||
2. Edit Cockpit config/config.yaml and add a new entry for drone like below:
|
2. Go to "Settings - Drone Deploys" and add a your drone configuration like below as following
|
||||||
|
|
||||||
```yaml
|
|
||||||
drone:
|
|
||||||
url: https://YOUR.DRONE.SERVER
|
|
||||||
token: <your drone access token>
|
|
||||||
owner: <the owner of the git repository>
|
|
||||||
project: <the git project>
|
|
||||||
branch: <the branch in your git repository for the deployment>
|
|
||||||
target: <the target condition used in your drone pipeline>
|
|
||||||
build: <the build number used as base for deployment> # leave empty and the addon will use the latest successfull build based on a push event
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
| |
|
||||||
|
| --- | ---
|
||||||
|
| URL: | your drone server url, pe. https://YOUR.DRONE.SERVER
|
||||||
|
| Token: | your drone access token
|
||||||
|
| Owner: | the owner of the git repository
|
||||||
|
| Project: | the git project
|
||||||
|
| Branch: | the branch in your git repository for the deployment
|
||||||
|
| Target: | the target condition used in your drone pipeline
|
||||||
|
| Build: | the build number used as base for deployment, leave empty and the addon will use the latest successfull build based on a push event
|
||||||
|
|
||||||
### Permissions
|
### Permissions
|
||||||
|
|
||||||
|
19
admin.php
19
admin.php
@ -9,10 +9,22 @@
|
|||||||
$this("acl")->addResource('drone', [
|
$this("acl")->addResource('drone', [
|
||||||
'manage.view',
|
'manage.view',
|
||||||
'manage.deploy',
|
'manage.deploy',
|
||||||
|
'manage.settings'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add menu entry to settings
|
||||||
|
*/
|
||||||
|
$this->on('cockpit.view.settings.item', function () {
|
||||||
|
if ($this->module('cockpit')->hasaccess('drone', 'manage.settings')) {
|
||||||
|
$this->renderView("drone:views/partials/settings.php");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$app->on('admin.init', function () use ($app) {
|
$app->on('admin.init', function () use ($app) {
|
||||||
if ($app->config['drone']) {
|
$settings = $app->storage->findOne('drone/settings');
|
||||||
|
if ($settings && $settings['active']) {
|
||||||
// Bind admin routes.
|
// Bind admin routes.
|
||||||
$this->bindClass('Drone\\Controller\\Admin', 'drone/deploys');
|
$this->bindClass('Drone\\Controller\\Admin', 'drone/deploys');
|
||||||
|
|
||||||
@ -26,4 +38,9 @@ $app->on('admin.init', function () use ($app) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($app->module('cockpit')->hasaccess('drone', 'manage.settings')) {
|
||||||
|
// Add settings
|
||||||
|
$this->bindClass('Drone\\Controller\\Settings', 'drone/settings');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -10,13 +10,13 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
|
|||||||
// Extend addon functions.
|
// Extend addon functions.
|
||||||
$this->module('drone')->extend([
|
$this->module('drone')->extend([
|
||||||
'fetchDeploys' => function ($limit = 50) {
|
'fetchDeploys' => function ($limit = 50) {
|
||||||
$settings = $this->app->config['drone'] ?? FALSE;
|
$settings = $this->app->storage->findOne('drone/settings') ?? FALSE;
|
||||||
|
|
||||||
if (!$settings || !isset($settings['url'],
|
if (!$settings || !isset($settings['url'],
|
||||||
$settings['owner'],
|
$settings['owner'],
|
||||||
$settings['project'],
|
$settings['project'],
|
||||||
$settings['target'],
|
$settings['target'],
|
||||||
$settings['token'])) {
|
$settings['token']) || !$settings['active']) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,13 +85,13 @@ if (COCKPIT_ADMIN && !COCKPIT_API_REQUEST) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'createDeploy' => function ($fromBuild) {
|
'createDeploy' => function ($fromBuild) {
|
||||||
$settings = $this->app->config['drone'];
|
$settings = $this->app->storage->findOne('drone/settings');
|
||||||
|
|
||||||
if (!$fromBuild || !$settings || !isset($settings['url'],
|
if (!$fromBuild || !$settings || !isset($settings['url'],
|
||||||
$settings['owner'],
|
$settings['owner'],
|
||||||
$settings['project'],
|
$settings['project'],
|
||||||
$settings['target'],
|
$settings['target'],
|
||||||
$settings['token'])) {
|
$settings['token']) || !$settings['active']) {
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
"error" => "missing settings"
|
"error" => "missing settings"
|
||||||
|
18
views/partials/settings.php
Normal file
18
views/partials/settings.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Drone Aside settings entry view.
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="uk-panel uk-panel-space uk-panel-box uk-panel-card">
|
||||||
|
|
||||||
|
<img src="@url('drone:icon.svg')" width="50" height="50" alt="@lang('Drone Deploys')" />
|
||||||
|
|
||||||
|
<div class="uk-text-truncate uk-margin">
|
||||||
|
@lang('Drone Deploys')
|
||||||
|
</div>
|
||||||
|
<a class="uk-position-cover" href="@route('/drone/settings')"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
105
views/settings/index.php
Normal file
105
views/settings/index.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<div>
|
||||||
|
<ul class="uk-breadcrumb">
|
||||||
|
<li><a href="@route('/settings')">@lang('Settings')</a></li>
|
||||||
|
<li class="uk-active"><span>@lang('Drone Deploys')</span></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-margin-top" riot-view>
|
||||||
|
|
||||||
|
<form class="uk-form" onsubmit="{ submit }">
|
||||||
|
|
||||||
|
<div class="uk-grid">
|
||||||
|
|
||||||
|
<div class="uk-grid-margin uk-width-medium-2-3">
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('URL')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.url" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('Token')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.token" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('Owner')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.owner" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('Project')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.project" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('Branch')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.branch" placeholder="@lang('Default'): master">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('Target')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.target" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-form-row">
|
||||||
|
<label class="uk-text-small">@lang('Build')</label>
|
||||||
|
<input class="uk-width-1-1 uk-form-large" type="text" bind="drone.build" placeholder="@lang('Default'): @lang('empty for last successfull build')">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<cp-actionbar>
|
||||||
|
<div class="uk-container uk-container-center">
|
||||||
|
<button class="uk-button uk-button-large uk-button-primary">@lang('Save')</button>
|
||||||
|
<a class="uk-button uk-button-large uk-button-link" href="@route('/settings')">@lang('Cancel')</a>
|
||||||
|
</div>
|
||||||
|
</cp-actionbar>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-grid-margin uk-width-medium-1-3">
|
||||||
|
|
||||||
|
<div class="uk-panel">
|
||||||
|
|
||||||
|
<div class="uk-margin">
|
||||||
|
<label class="uk-text-small">@lang('Status')</label>
|
||||||
|
<div class="uk-margin-small-top">
|
||||||
|
<field-boolean bind="drone.active" label="false"></field-boolean>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uk-margin" if="{drone._id}">
|
||||||
|
<label class="uk-text-small">@lang('Last Modified')</label>
|
||||||
|
<div class="uk-margin-small-top uk-text-muted"><i class="uk-icon-calendar uk-margin-small-right"></i> { App.Utils.dateformat( new Date( 1000 * drone._modified )) }</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="view/script">
|
||||||
|
var $this = this;
|
||||||
|
|
||||||
|
this.mixin(RiotBindMixin);
|
||||||
|
|
||||||
|
this.drone = {{ json_encode($drone) }};
|
||||||
|
|
||||||
|
submit(e) {
|
||||||
|
if(e) e.preventDefault();
|
||||||
|
App.request('/drone/settings/save', {drone: this.drone}).then(function(data) {
|
||||||
|
if (data) {
|
||||||
|
App.ui.notify("Saving successful", "success");
|
||||||
|
$this.drone = data;
|
||||||
|
$this.update();
|
||||||
|
} else {
|
||||||
|
App.ui.notify("Saving failed.", "danger");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user