Skip to content

Commit a968944

Browse files
MarkDeMariaMarkDeMaria
authored and
MarkDeMaria
committed
Allow editing of build hooks on build configuration page
-Single-select tag for Command, Script, and Args, Command+Args, Script+Args -Whatever option is currently-selected upon hitting 'Save' will overwrite anything else. For example, if post commit has a command in it, and you hit save on the Args page, the command will be deleted and the args saved. -Checkbox shows/hides the build hook editor. Leaving it unchcked and selecting "Save" with anything saved in the post commit section of the YAML will be deleted, as the user has indicated they do not wish to have any build hooks -Alterations to edit-command directive to allow for a 'type' arg to be passed through. Will replace relevant wording. For example, 'argument.' If no type provided, defaults to 'command.'
1 parent 865715f commit a968944

File tree

10 files changed

+761
-55
lines changed

10 files changed

+761
-55
lines changed

app/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ <h1>JavaScript Required</h1>
140140
<script src="bower_components/ace-builds/src-min-noconflict/mode-yaml.js"></script>
141141
<script src="bower_components/ace-builds/src-min-noconflict/theme-dreamweaver.js"></script>
142142
<script src="bower_components/ace-builds/src-min-noconflict/theme-eclipse.js"></script>
143+
<script src="bower_components/ace-builds/src-min-noconflict/mode-sh.js"></script>
143144
<script src="bower_components/angular-ui-ace/ui-ace.js"></script>
144145
<script src="bower_components/clipboard/dist/clipboard.js"></script>
145146
<script src="bower_components/ansi_up/ansi_up.js"></script>

app/scripts/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ window.OPENSHIFT_CONSTANTS = {
5151
"builds": "architecture/core_concepts/builds_and_image_streams.html#builds",
5252
"image-streams": "architecture/core_concepts/builds_and_image_streams.html#image-streams",
5353
"storage": "architecture/additional_concepts/storage.html",
54+
"build-hooks": "dev_guide/builds.html#build-hooks",
5455
// default should remain last, add new links above
5556
"default": "welcome/index.html"
5657
},

app/scripts/controllers/edit/buildConfig.js

+79-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ angular.module('openshiftConsole')
5555
"title": "Inline"
5656
}];
5757
$scope.view = {
58-
advancedOptions: false
58+
advancedOptions: false,
59+
hasHooks: false
5960
};
6061
$scope.breadcrumbs = [
6162
{
@@ -117,6 +118,79 @@ angular.module('openshiftConsole')
117118
"SerialLatestOnly"
118119
];
119120

121+
$scope.buildHookTypes = [{
122+
id: "command",
123+
label: "Command"
124+
}, {
125+
id: "script",
126+
label: "Shell Script"
127+
}, {
128+
id: "args",
129+
label: "Arguments to default image entry point"
130+
}, {
131+
id: "commandArgs",
132+
label: "Command with arguments"
133+
}, {
134+
id: "scriptArgs",
135+
label: "Shell script with arguments"
136+
}];
137+
138+
$scope.buildHookSelection = {
139+
type: {}
140+
};
141+
142+
var getInitialBuildHookSelection = function() {
143+
var hasArgs = !_.isEmpty(_.get($scope, 'buildConfig.spec.postCommit.args'));
144+
var hasCommand = !_.isEmpty(_.get($scope, 'buildConfig.spec.postCommit.command'));
145+
var hasScript = !!_.get($scope, 'buildConfig.spec.postCommit.script');
146+
$scope.view.hasHooks = hasArgs || hasCommand || hasScript;
147+
148+
var id;
149+
150+
if (hasArgs && hasCommand) {
151+
id = 'commandArgs';
152+
} else if (hasArgs && hasScript) {
153+
id = 'scriptArgs';
154+
} else if (hasArgs) {
155+
id = 'args';
156+
} else if (hasScript) {
157+
id = 'script';
158+
} else {
159+
id = 'command';
160+
}
161+
162+
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: id });
163+
};
164+
165+
var clearIncompatibleBuildHookFields = function() {
166+
if (!$scope.view.hasHooks) {
167+
delete $scope.updatedBuildConfig.spec.postCommit.command;
168+
delete $scope.updatedBuildConfig.spec.postCommit.args;
169+
delete $scope.updatedBuildConfig.spec.postCommit.script;
170+
} else {
171+
switch ($scope.buildHookSelection.type.id) {
172+
case "script":
173+
delete $scope.updatedBuildConfig.spec.postCommit.command;
174+
delete $scope.updatedBuildConfig.spec.postCommit.args;
175+
break;
176+
case "command":
177+
delete $scope.updatedBuildConfig.spec.postCommit.script;
178+
delete $scope.updatedBuildConfig.spec.postCommit.args;
179+
break;
180+
case "args":
181+
delete $scope.updatedBuildConfig.spec.postCommit.script;
182+
delete $scope.updatedBuildConfig.spec.postCommit.command;
183+
break;
184+
case "scriptArgs":
185+
delete $scope.updatedBuildConfig.spec.postCommit.command;
186+
break;
187+
case "commandArgs":
188+
delete $scope.updatedBuildConfig.spec.postCommit.script;
189+
break;
190+
}
191+
}
192+
};
193+
120194
AlertMessageService.getAlerts().forEach(function(alert) {
121195
$scope.alerts[alert.name] = alert.data;
122196
});
@@ -143,6 +217,8 @@ angular.module('openshiftConsole')
143217
// success
144218
function(buildConfig) {
145219
$scope.buildConfig = buildConfig;
220+
getInitialBuildHookSelection();
221+
146222
$scope.updatedBuildConfig = angular.copy($scope.buildConfig);
147223
$scope.buildStrategy = buildStrategy($scope.updatedBuildConfig);
148224
$scope.strategyType = $scope.buildConfig.spec.strategy.type;
@@ -180,7 +256,7 @@ angular.module('openshiftConsole')
180256
}
181257

182258
if (imageOptions.type === "ImageStreamImage") {
183-
isimage = (imageData.namespace || buildConfig.metadata.namespace) + "/" + imageData.name;
259+
isimage = (imageData.namespace || buildConfig.metadata.namespace) + "/" + imageData.name;
184260
} else {
185261
isimage = "";
186262
}
@@ -414,6 +490,7 @@ angular.module('openshiftConsole')
414490

415491
$scope.save = function() {
416492
$scope.disableInputs = true;
493+
clearIncompatibleBuildHookFields();
417494
// Update Configuration
418495
buildStrategy($scope.updatedBuildConfig).forcePull = $scope.options.forcePull;
419496

app/scripts/directives/editCommand.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ angular.module('openshiftConsole')
66
restrict: 'E',
77
scope: {
88
args: '=',
9+
type: '@',
910
isRequired: '='
1011
},
1112
templateUrl: 'views/directives/_edit-command.html',

app/views/directives/_edit-command.html

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ng-form name="form">
2-
<p ng-hide="input.args.length"><em>No command set.</em></p>
2+
<p ng-hide="input.args.length"><em>No {{type || 'command'}} set.</em></p>
33
<p ng-show="input.args.length" as-sortable ng-model="input.args" class="command-args">
44
<span ng-repeat="arg in input.args" as-sortable-item class="form-group">
55
<span class="input-group">
@@ -25,23 +25,23 @@
2525
<span as-sortable-item-handle class="input-group-addon action-button drag-handle">
2626
<i class="fa fa-bars" aria-hidden="true"></i>
2727
</span>
28-
<a href="" ng-click="removeArg($index)" class="input-group-addon action-button remove-arg" title="Remove Argument">
29-
<span class="sr-only">Remove Argument</span>
28+
<a href="" ng-click="removeArg($index)" class="input-group-addon action-button remove-arg" title="Remove Item">
29+
<span class="sr-only">Remove Item</span>
3030
<i class="pficon pficon-close" aria-hidden="true"></i>
3131
</a>
3232
</span>
3333
</span>
3434
</p>
3535
<div class="form-group">
36-
<label class="sr-only" ng-attr-for="{{id}}-add-arg">Add Argument</label>
36+
<label class="sr-only" ng-attr-for="{{id}}-add-arg">Add {{type || 'Command'}}</label>
3737
<!-- Single-line entry -->
3838
<span ng-show="!multiline" class="input-group">
3939
<input type="text"
4040
ng-model="nextArg"
4141
name="nextArg"
4242
ng-attr-id="{{id}}-add-arg"
4343
on-enter="addArg()"
44-
placeholder="Add argument"
44+
placeholder="Add {{type || 'command'}}"
4545
class="form-control"
4646
autocorrect="off"
4747
autocapitalize="off"
@@ -64,7 +64,7 @@
6464
name="nextArg"
6565
rows="10"
6666
ng-attr-id="{{id}}-add-arg"
67-
placeholder="Add argument"
67+
placeholder="Add {{type || 'command'}}"
6868
class="form-control"
6969
autocorrect="off"
7070
autocapitalize="off"
@@ -81,14 +81,19 @@
8181
</span>
8282
</div>
8383
<div class="help-block">
84-
Enter the command to run inside the container. The command is considered successful if its exit code is 0.
85-
Drag and drop command arguments to reorder them.
84+
<div ng-if="!type">
85+
Enter the command to run inside the container. The command is considered successful if its exit code is 0.
86+
Drag and drop command arguments to reorder them.
87+
</div>
88+
<div ng-if="type">
89+
Enter the arguments that will be appended to the container's command. Drag and drop arguments to reorder them.
90+
</div>
8691
</div>
8792
<div class="mar-top-sm mar-bottom-md">
8893
<a href="" ng-click="multiline = !multiline">Switch to {{multiline ? 'Single-line' : 'Multiline'}} Editor</a>
8994
<span ng-show="input.args.length">
9095
<span class="action-divider">|</span>
91-
<a href="" ng-click="clear()" role="button">Clear Command</a>
96+
<a href="" ng-click="clear()" role="button">Clear {{ (type || 'Command') | sentenceCase }}</a>
9297
</span>
9398
</div>
9499
<!-- Add a hidden input to help with form validation. -->

app/views/edit/build-config.html

+68-7
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ <h3>Source Configuration</h3>
115115
<div ui-ace="{
116116
mode: 'dockerfile',
117117
theme: 'dreamweaver',
118-
onLoad: aceLoaded,
119118
rendererOptions: {
120119
fadeFoldWidgets: true,
121120
showPrintMargin: false
@@ -275,7 +274,6 @@ <h3 ng-class="{ 'with-divider': !sources.none }">Jenkins Pipeline Configuration<
275274
<div ui-ace="{
276275
mode: 'groovy',
277276
theme: 'eclipse',
278-
onLoad: aceLoaded,
279277
rendererOptions: {
280278
fadeFoldWidgets: true,
281279
showPrintMargin: false
@@ -416,8 +414,6 @@ <h3 class="with-divider">Image Configuration</h3>
416414
</dl>
417415
</div>
418416

419-
420-
421417
<div ng-if="!(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
422418
<h3 class="with-divider">Environment Variables<span class="help action-inline">
423419
<a href="">
@@ -523,8 +519,8 @@ <h3 class="with-divider">Run Policy
523519
{{type | sentenceCase}}
524520
</ui-select-choices>
525521
</ui-select>
526-
527522
</div>
523+
528524
<div ng-switch="updatedBuildConfig.spec.runPolicy">
529525
<div class="help-block" ng-switch-when="Serial">Builds triggered from this Build Configuration will run one at the time, in the order they have been triggered.</div>
530526
<div class="help-block" ng-switch-when="Parallel">Builds triggered from this Build Configuration will run all at the same time. The order in which they will finish is not guaranteed.</div>
@@ -533,8 +529,73 @@ <h3 class="with-divider">Run Policy
533529
</div>
534530
</div>
535531

536-
<div>
537-
<a href="" ng-click="view.advancedOptions = !view.advancedOptions" role="button">{{view.advancedOptions ? 'Hide' : 'Show'}} Advanced Options</a>
532+
<div ng-if="view.advancedOptions && !(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
533+
<h3 class="with-divider">Build Hooks
534+
<span class="help action-inline">
535+
<a href="{{'build-hooks' | helpLink}}" aria-hidden="true" target="_blank"><span class="learn-more-inline">Learn More&nbsp;<i class="fa fa-external-link"></i></span></a>
536+
</span>
537+
</h3>
538+
539+
<div class="checkbox">
540+
<label>
541+
<input type="checkbox" ng-model="view.hasHooks" id="enable-build-hooks">
542+
Run build hooks after image is built
543+
</label>
544+
<div class="help-block">
545+
Build hooks allow you to run commands at the end of the build to verify the image.
546+
</div>
547+
</div>
548+
549+
<div ng-show="view.hasHooks">
550+
<div class="form-group">
551+
<h4>Hook Types</h4>
552+
<ui-select
553+
ng-model="buildHookSelection.type"
554+
title="Choose a type of build hook">
555+
<ui-select-match>{{$select.selected.label}}</ui-select-match>
556+
<ui-select-choices repeat="type in buildHookTypes">
557+
{{type.label}}
558+
</ui-select-choices>
559+
</ui-select>
560+
</div>
561+
562+
<fieldset>
563+
<div ng-show="buildHookSelection.type.id === 'script' || buildHookSelection.type.id === 'scriptArgs'">
564+
<h4>Script</h4>
565+
<div
566+
ui-ace="{
567+
mode: 'sh',
568+
theme: 'eclipse',
569+
rendererOptions: {
570+
fadeFoldWidgets: true,
571+
showPrintMargin: false
572+
}
573+
}"
574+
ng-model="updatedBuildConfig.spec.postCommit.script"
575+
class="ace-bordered ace-inline mar-top-md">
576+
</div>
577+
</div>
578+
579+
<div ng-show="buildHookSelection.type.id === 'command' || buildHookSelection.type.id === 'commandArgs'">
580+
<h4>Command</h4>
581+
<edit-command
582+
args="updatedBuildConfig.spec.postCommit.command">
583+
</edit-command>
584+
</div>
585+
586+
<div ng-show="buildHookSelection.type.id === 'args' || buildHookSelection.type.id === 'commandArgs' || buildHookSelection.type.id === 'scriptArgs' ">
587+
<h4>Arguments</h4>
588+
<edit-command
589+
args="updatedBuildConfig.spec.postCommit.args"
590+
type="argument">
591+
</edit-command>
592+
</div>
593+
</fieldset>
594+
</div>
595+
</div>
596+
597+
<div class="gutter-top">
598+
<a href="" ng-click="view.advancedOptions = !view.advancedOptions" role="button">{{view.advancedOptions ? 'Hide' : 'Show'}} advanced options</a>
538599
</div>
539600
<div class="buttons gutter-top-bottom">
540601
<button

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
"src-min-noconflict/mode-groovy.js",
106106
"src-min-noconflict/mode-yaml.js",
107107
"src-min-noconflict/theme-dreamweaver.js",
108-
"src-min-noconflict/theme-eclipse.js"
108+
"src-min-noconflict/theme-eclipse.js",
109+
"src-min-noconflict/mode-sh.js"
109110
]
110111
}
111112
}

0 commit comments

Comments
 (0)