Skip to content

Commit

Permalink
feat(appengine): Enable new artifacts workflow in deploy SG (#7147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy Louie committed Jun 26, 2019
1 parent aca6626 commit a9a927b
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AccountService,
StorageAccountReader,
Application,
IArtifact,
IBuildTrigger,
IExpectedArtifact,
IGitTrigger,
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface IAppengineServerGroupCommand {
interestingHealthProviderNames: string[];
fromArtifact: boolean;
expectedArtifactId: string;
expectedArtifact?: IArtifact;
sourceType: string;
containerImageUrl?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { set } from 'lodash';

import {
ArtifactTypePatterns,
excludeAllTypesExcept,
ExpectedArtifactSelectorViewController,
IArtifact,
IExpectedArtifact,
IPipeline,
NgAppEngineDeployArtifactDelegate,
} from '@spinnaker/core';

Expand All @@ -17,6 +21,7 @@ interface IAppengineBasicSettingsScope extends IScope {

class AppengineServerGroupBasicSettingsCtrl implements IController {
public static $inject = ['$scope', '$state', '$controller', '$uibModalStack'];

constructor(
public $scope: IAppengineBasicSettingsScope,
$state: StateService,
Expand Down Expand Up @@ -104,6 +109,39 @@ class AppengineServerGroupBasicSettingsCtrl implements IController {
}
}

public readonly excludedGcsArtifactTypes = excludeAllTypesExcept(ArtifactTypePatterns.GCS_OBJECT);
public readonly excludedContainerArtifactTypes = excludeAllTypesExcept(ArtifactTypePatterns.DOCKER_IMAGE);

public onExpectedArtifactEdited = (artifact: IArtifact): void => {
this.$scope.$applyAsync(() => {
this.$scope.command.expectedArtifactId = null;
this.$scope.command.expectedArtifact = artifact;
});
};

public onExpectedArtifactSelected = (expectedArtifact: IExpectedArtifact): void => {
this.onChangeExpectedArtifactId(expectedArtifact.id);
};

public onChangeExpectedArtifactId = (artifactId: string): void => {
this.$scope.$applyAsync(() => {
this.$scope.command.expectedArtifactId = artifactId;
this.$scope.command.expectedArtifact = null;
});
};

public onExpectedArtifactAccountSelected = (accountName: string): void => {
this.$scope.$applyAsync(() => {
this.$scope.command.storageAccountName = accountName;
});
};

public updatePipeline = (changes: Partial<IPipeline>): void => {
this.$scope.$applyAsync(() => {
extend(this.$scope.$parent.pipeline, changes);
});
};

private findAccountInBackingData(): IAppengineAccount {
return this.$scope.command.backingData.accounts.find((account: IAppengineAccount) => {
return this.$scope.command.credentials === account.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,49 +89,31 @@
<div class="radio radio-inline">
<label> <input type="radio" ng-model="command.fromArtifact" ng-value="false" /> via text input </label>
</div>
<div class="radio radio-inline">
<div class="radio radio-inline" ng-if="command.viewState.pipeline">
<label>
<input type="radio" ng-model="command.fromArtifact" ng-value="true" /> via pipeline artifact
</label>
</div>
</div>
</div>

<div class="form-group row" ng-if="command.fromArtifact">
<label class="col-md-3 sm-label-right">Artifact Account</label>
<div class="col-md-7">
<select
class="form-control input-sm"
ng-options="option for option in command.backingData.storageAccounts"
ng-model="command.storageAccountName"
>
<option value="">Select...</option>
</select>
</div>
</div>

<stage-config-field label="Expected Artifact" field-columns="7" ng-if="command.fromArtifact">
<expected-artifact-selector-react
expected-artifacts="command.backingData.expectedArtifacts"
selected="gcsArtifactDelegate.getSelectedExpectedArtifact()"
on-change="gcsArtifactController.onArtifactChange"
on-request-create="gcsArtifactController.onRequestCreate"
offered-artifact-types="gcsArtifactDelegate.getOfferedArtifactTypes()"
requesting-new="showCreateArtifactForm"
>
</expected-artifact-selector-react>
</stage-config-field>
<expected-artifact-editor-react
ng-if="showCreateArtifactForm"
kinds="gcsArtifactDelegate.getSupportedArtifactKinds()"
sources="gcsArtifactDelegate.getExpectedArtifactSources()"
on-save="gcsArtifactController.onArtifactCreated"
show-accounts="false"
single-column="true"
<stage-artifact-selector-delegate
ng-if="command.fromArtifact"
artifact="command.expectedArtifact"
excluded-artifact-type-patterns="basicSettingsCtrl.excludedGcsArtifactTypes"
expected-artifact-id="command.expectedArtifactId"
field-columns="7"
label="'Expected Artifact'"
on-artifact-edited="basicSettingsCtrl.onExpectedArtifactEdited"
on-expected-artifact-selected="basicSettingsCtrl.onExpectedArtifactSelected"
pipeline="command.viewState.pipeline"
selected-artifact-account="command.storageAccountName"
selected-artifact-id="command.expectedArtifactId"
set-artifact-account="basicSettingsCtrl.onExpectedArtifactAccountSelected"
set-artifact-id="basicSettingsCtrl.onChangeExpectedArtifactId"
stage="command.viewState.stage"
update-pipeline="basicSettingsCtrl.updatePipeline"
>
</expected-artifact-editor-react>

</stage-artifact-selector-delegate>
<div class="form-group" ng-if="!command.fromArtifact">
<div class="col-md-3 sm-label-right">
GCS URL
Expand Down Expand Up @@ -218,36 +200,31 @@
<div class="radio radio-inline">
<label> <input type="radio" ng-model="command.fromArtifact" ng-value="false" /> via text input </label>
</div>
<div class="radio radio-inline">
<div class="radio radio-inline" ng-if="command.viewState.pipeline">
<label>
<input type="radio" ng-model="command.fromArtifact" ng-value="true" /> via pipeline artifact
</label>
</div>
</div>
</div>

<stage-config-field label="Expected Artifact" field-columns="7" ng-if="command.fromArtifact">
<expected-artifact-selector-react
expected-artifacts="command.backingData.expectedArtifacts"
selected="containerArtifactDelegate.getSelectedExpectedArtifact()"
on-change="containerArtifactController.onArtifactChange"
on-request-create="containerArtifactController.onRequestCreate"
offered-artifact-types="containerArtifactDelegate.getOfferedArtifactTypes()"
requesting-new="showCreateArtifactForm"
>
</expected-artifact-selector-react>
</stage-config-field>
<expected-artifact-editor-react
ng-if="showCreateArtifactForm"
kinds="containerArtifactDelegate.getSupportedArtifactKinds()"
sources="containerArtifactDelegate.getExpectedArtifactSources()"
on-save="containerArtifactController.onArtifactCreated"
show-accounts="false"
single-column="true"
<stage-artifact-selector-delegate
ng-if="command.fromArtifact"
artifact="command.expectedArtifact"
excluded-artifact-type-patterns="basicSettingsCtrl.excludedContainerArtifactTypes"
expected-artifact-id="command.expectedArtifactId"
field-columns="7"
label="'Expected Artifact'"
on-artifact-edited="basicSettingsCtrl.onExpectedArtifactEdited"
on-expected-artifact-selected="basicSettingsCtrl.onExpectedArtifactSelected"
pipeline="command.viewState.pipeline"
selected-artifact-account="command.storageAccountName"
selected-artifact-id="command.expectedArtifactId"
set-artifact-account="basicSettingsCtrl.onExpectedArtifactAccountSelected"
set-artifact-id="basicSettingsCtrl.onChangeExpectedArtifactId"
stage="command.viewState.stage"
update-pipeline="basicSettingsCtrl.updatePipeline"
>
</expected-artifact-editor-react>

</stage-artifact-selector-delegate>
<div class="form-group" ng-if="!command.fromArtifact">
<div class="col-md-3 sm-label-right">
Image URL
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/artifact/artifact.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EXPECTED_ARTIFACT_EDITOR_COMPONENT_REACT } from './react/ExpectedArtifa
import { EXPECTED_ARTIFACT_MULTI_SELECTOR_COMPONENT } from './expectedArtifactMultiSelector.component';
import { IMAGE_SOURCE_SELECTOR_COMPONENT } from './imageSourceSelector.component';
import { EXECUTION_ARTIFACT_TAB } from './artifactTab';
import { STAGE_ARTIFACT_SELECTOR_DELEGATE } from './stageArtifactSelectorDelegate';

export const ARTIFACT_MODULE = 'spinnaker.core.artifact';
module(ARTIFACT_MODULE, [
Expand All @@ -13,4 +14,5 @@ module(ARTIFACT_MODULE, [
EXPECTED_ARTIFACT_SELECTOR_COMPONENT_REACT,
EXPECTED_ARTIFACT_EDITOR_COMPONENT_REACT,
IMAGE_SOURCE_SELECTOR_COMPONENT,
STAGE_ARTIFACT_SELECTOR_DELEGATE,
]);
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

export interface IPreRewriteArtifactSelectorProps {
excludedArtifactTypePatterns?: RegExp[];
fieldColumns?: number;
helpKey?: string;
label: string;
selectedArtifactId: string;
Expand Down Expand Up @@ -170,12 +171,19 @@ export class PreRewriteStageArtifactSelector extends React.Component<
}

public render() {
const { excludedArtifactTypePatterns, helpKey, label, selectedArtifactId, setArtifactAccount } = this.props;
const {
excludedArtifactTypePatterns,
fieldColumns,
helpKey,
label,
selectedArtifactId,
setArtifactAccount,
} = this.props;
const { accountsForArtifact, allArtifactAccounts, showCreateArtifactForm } = this.state;

return (
<>
<StageConfigField helpKey={helpKey} label={label || 'Artifact'}>
<StageConfigField helpKey={helpKey} label={label || 'Artifact'} fieldColumns={fieldColumns}>
<ExpectedArtifactSelector
excludedArtifactTypes={excludedArtifactTypePatterns}
expectedArtifacts={this.state.expectedArtifacts}
Expand All @@ -195,12 +203,15 @@ export class PreRewriteStageArtifactSelector extends React.Component<
</StageConfigField>
)}
{this.state.showCreateArtifactForm && (
<ExpectedArtifactEditor
accounts={allArtifactAccounts}
kinds={this.getKinds()}
onSave={this.saveCreatedArtifact}
sources={this.getSources()}
/>
<StageConfigField label="" fieldColumns={fieldColumns}>
<ExpectedArtifactEditor
accounts={allArtifactAccounts}
fieldColumns={fieldColumns}
kinds={this.getKinds()}
onSave={this.saveCreatedArtifact}
sources={this.getSources()}
/>
</StageConfigField>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { PreRewriteStageArtifactSelector, IPreRewriteArtifactSelectorProps } fro
interface IStageArtifactSelectorDelegateProps {
helpKey?: string;
label: string;
fieldColumns?: number;
}

export const StageArtifactSelectorDelegate = (
props: IStageArtifactSelectorProps & IPreRewriteArtifactSelectorProps & IStageArtifactSelectorDelegateProps,
) => {
return SETTINGS.feature['artifactsRewrite'] ? (
<StageConfigField label={props.label} helpKey={props.helpKey}>
<StageConfigField label={props.label} helpKey={props.helpKey} fieldColumns={props.fieldColumns}>
<StageArtifactSelector {...props} />
</StageConfigField>
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module } from 'angular';
import { react2angular } from 'react2angular';
import { StageArtifactSelectorDelegate } from './react/StageArtifactSelectorDelegate';

export const STAGE_ARTIFACT_SELECTOR_DELEGATE = 'spinnaker.core.artifact.stageArtifactSelectorDelegate';

module(STAGE_ARTIFACT_SELECTOR_DELEGATE, []).component(
'stageArtifactSelectorDelegate',
react2angular(StageArtifactSelectorDelegate, [
'artifact',
'excludedArtifactTypePatterns',
'expectedArtifactId',
'fieldColumns',
'helpKey',
'label',
'onArtifactEdited',
'onExpectedArtifactSelected',
'pipeline',
'selectedArtifactAccount',
'selectedArtifactId',
'setArtifactAccount',
'setArtifactId',
'stage',
'updatePipeline',
]),
);

0 comments on commit a9a927b

Please sign in to comment.