Skip to content

Commit

Permalink
feat(gce): Support new artifact model for deploy SG (#7178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy Louie committed Jul 4, 2019
1 parent c93b4d0 commit ecb2dd1
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class ArtifactIconService {
}
}

ArtifactIconService.registerType(ArtifactTypePatterns.CUSTOM_OBJECT, unknownArtifactPath);
ArtifactIconService.registerType(ArtifactTypePatterns.DOCKER_IMAGE, require('./icons/docker-image-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.KUBERNETES, require('./icons/kubernetes-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.EMBEDDED_BASE64, require('./icons/embedded-base64-artifact.svg'));
Expand Down
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/artifact/ArtifactTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface IArtifactTypePatterns {

export const ArtifactTypePatterns: IArtifactTypePatterns = {
BITBUCKET_FILE: /bitbucket\/file/,
CUSTOM_OBJECT: /custom\/object/,
DOCKER_IMAGE: /docker\/image/,
EMBEDDED_BASE64: /embedded\/base64/,
GCS_OBJECT: /gcs\/object/,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import * as React from 'react';
import { cloneDeep, extend } from 'lodash';

import { ArtifactTypePatterns } from 'core/artifact';
import { IArtifactEditorProps, IArtifactKindConfig } from 'core/domain';
import { StageConfigField } from 'core/pipeline';
import { SpelText } from 'core/widgets';

import { ArtifactEditor } from '../ArtifactEditor';
import { singleFieldArtifactEditor } from '../singleFieldArtifactEditor';

const TYPE = 'custom/object';

export const CustomMatch: IArtifactKindConfig = {
label: 'Custom',
typePattern: ArtifactTypePatterns.CUSTOM_OBJECT,
type: TYPE,
description: 'A custom-defined artifact.',
key: 'custom',
isDefault: false,
isMatch: true,
editCmp: singleFieldArtifactEditor('name', TYPE, 'Reference', '', ''),
};

export const CustomDefault: IArtifactKindConfig = {
label: 'Custom',
typePattern: ArtifactTypePatterns.CUSTOM_OBJECT,
type: TYPE,
description: 'A custom-defined artifact.',
key: 'default.custom',
isDefault: true,
isMatch: false,
editCmp: class extends ArtifactEditor {
constructor(props: IArtifactEditorProps) {
super(props, TYPE);
}

private onTypeChanged = (type: string) => {
this.updateArtifact({ type });
};

private onNameChanged = (name: string) => {
this.updateArtifact({ name });
};

private onVersionChanged = (version: string) => {
this.updateArtifact({ version });
};

private onLocationChanged = (location: string) => {
this.updateArtifact({ location });
};

private onReferenceChanged = (reference: string) => {
this.updateArtifact({ reference });
};

private updateArtifact = (changes: any) => {
const clonedArtifact = cloneDeep(this.props.artifact);
extend(clonedArtifact, changes);
this.props.onChange(clonedArtifact);
};

public render() {
return (
<>
<StageConfigField label="Type">
<SpelText
placeholder=""
value={this.props.artifact.type}
onChange={this.onTypeChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
<StageConfigField label="Name">
<SpelText
placeholder=""
value={this.props.artifact.name}
onChange={this.onNameChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
<StageConfigField label="Version">
<SpelText
placeholder=""
value={this.props.artifact.version}
onChange={this.onVersionChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
<StageConfigField label="Location">
<SpelText
placeholder=""
value={this.props.artifact.location}
onChange={this.onLocationChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
<StageConfigField label="Reference">
<SpelText
placeholder=""
value={this.props.artifact.reference}
onChange={this.onReferenceChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
</>
);
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module(CUSTOM_ARTIFACT, [])
.config(() => {
Registry.pipeline.registerCustomArtifactKind({
label: 'Custom',
description: 'A custom-defined artifact.',
description: 'A custom-defined artifact. (Deprecated)',
key: 'custom',
customKind: true,
isDefault: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IArtifactKindConfig } from 'core/domain';

import { Base64Match, Base64Default } from './base64/Base64ArtifactEditor';
import { BitbucketMatch, BitbucketDefault } from './bitbucket/BitbucketArtifactEditor';
import { CustomMatch, CustomDefault } from './custom/CustomArtifactEditor';
import { DockerMatch, DockerDefault } from './docker/DockerArtifactEditor';
import { GcsMatch, GcsDefault } from './gcs/GcsArtifactEditor';
import { GithubMatch, GithubDefault } from './github/GithubArtifactEditor';
Expand All @@ -19,6 +20,8 @@ export const artifactKindConfigs: IArtifactKindConfig[] = [
Base64Default,
BitbucketMatch,
BitbucketDefault,
CustomMatch,
CustomDefault,
DockerMatch,
DockerDefault,
GcsMatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class DeployInitializerController implements IController {
viewState.hideClusterNamePreview = baseCommand.viewState.hideClusterNamePreview || false;
viewState.templatingEnabled = true;
viewState.imageSourceText = baseCommand.viewState.imageSourceText;
viewState.pipeline = baseCommand.viewState.pipeline;
viewState.stage = baseCommand.viewState.stage;
Object.assign(command, baseCommand.viewState.overrides || {});
Object.assign(baseCommand, command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ module.exports = angular
const expectedArtifacts = ExpectedArtifactService.getExpectedArtifactsAvailableToStage(currentStage, pipeline);
return $q.when({
viewState: {
pipeline,
expectedArtifacts: expectedArtifacts,
requiresTemplateSelection: true,
stage: currentStage,
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

const angular = require('angular');
import { Observable, Subject } from 'rxjs';
import { extend } from 'lodash';

import { IMAGE_READER, ExpectedArtifactSelectorViewController, NgGCEImageArtifactDelegate } from '@spinnaker/core';
import {
ArtifactTypePatterns,
ExpectedArtifactSelectorViewController,
excludeAllTypesExcept,
IMAGE_READER,
NgGCEImageArtifactDelegate,
} from '@spinnaker/core';

module.exports = angular
.module('spinnaker.google.serverGroup.configure.wizard.basicSettings.controller', [
Expand Down Expand Up @@ -85,6 +92,38 @@ module.exports = angular

this.imageSources = ['artifact', 'priorStage'];

this.excludedImageArtifactTypes = excludeAllTypesExcept(ArtifactTypePatterns.CUSTOM_OBJECT);

this.onImageArtifactEdited = artifact => {
$scope.$applyAsync(() => {
$scope.command.imageArtifactId = null;
$scope.command.imageArtifact = artifact;
});
};

this.onImageArtifactSelected = expectedArtifact => {
this.onChangeImageArtifactId(expectedArtifact.id);
};

this.onChangeImageArtifactId = artifactId => {
$scope.$applyAsync(() => {
$scope.command.imageArtifactId = artifactId;
$scope.command.imageArtifact = null;
});
};

this.onImageArtifactAccountSelected = accountName => {
$scope.$applyAsync(() => {
$scope.command.imageAccountName = accountName;
});
};

this.updatePipeline = changes => {
$scope.$applyAsync(() => {
extend($scope.$parent.pipeline, changes);
});
};

const gceImageDelegate = new NgGCEImageArtifactDelegate($scope);
$scope.gceImageArtifact = {
showCreateArtifactForm: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,25 @@
help-field-key="gce.image.source"
>
</image-source-selector>
<stage-config-field
label="Expected Artifact"
help-key="gce.image.artifact"
field-columns="8"
<stage-artifact-selector-delegate
ng-if="command.imageSource === 'artifact'"
artifact="command.imageArtifact"
excluded-artifact-type-patterns="basicSettingsCtrl.excludedImageArtifactTypes"
expected-artifact-id="command.imageArtifactId"
field-columns="7"
help-key="'gce.image.artifact'"
label="'Expected Artifact'"
on-artifact-edited="basicSettingsCtrl.onImageArtifactEdited"
on-expected-artifact-selected="basicSettingsCtrl.onImageArtifactSelected"
pipeline="command.viewState.pipeline"
selected-artifact-account="command.imageAccountName"
selected-artifact-id="command.imageArtifactId"
set-artifact-account="basicSettingsCtrl.onImageArtifactAccountSelected"
set-artifact-id="basicSettingsCtrl.onChangeImageArtifactId"
stage="command.viewState.stage"
update-pipeline="basicSettingsCtrl.updatePipeline"
>
<expected-artifact-selector-react
expected-artifacts="command.viewState.expectedArtifacts"
selected="gceImageArtifact.delegate.getSelectedExpectedArtifact()"
on-change="gceImageArtifact.controller.onArtifactChange"
on-request-create="gceImageArtifact.controller.onRequestCreate"
offered-artifact-types="gceImageArtifact.delegate.getOfferedArtifactTypes()"
requesting-new="gceImageArtifact.showCreateArtifactForm"
>
</expected-artifact-selector-react>
</stage-config-field>
<expected-artifact-editor-react
ng-if="gceImageArtifact.showCreateArtifactForm"
kinds="gceImageArtifact.delegate.getSupportedArtifactKinds()"
sources="gceImageArtifact.delegate.getExpectedArtifactSources()"
on-save="gceImageArtifact.controller.onArtifactCreated"
show-accounts="false"
>
</expected-artifact-editor-react>
</stage-artifact-selector-delegate>
</div>
<div class="form-group" ng-if="!command.viewState.disableImageSelection">
<div class="col-md-3 sm-label-right">
Expand Down

0 comments on commit ecb2dd1

Please sign in to comment.