Skip to content

Commit

Permalink
feat(gcb): add Google Cloud Build stage (spinnaker#6774)
Browse files Browse the repository at this point in the history
* refactor(core): move yamlEditor from kubernetes to core module

* feat(gcb): add Google Cloud Build stage
  • Loading branch information
maggieneterval authored Mar 28, 2019
1 parent 98ea524 commit 50b74f2
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/scripts/modules/core/src/ci/igor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ export class IgorService {
.one(job)
.get();
}

public static getGcbAccounts(): IPromise<String[]> {
return API.one('gcb')
.one('accounts')
.get();
}
}
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ export * from './validation';

export * from './widgets';

export * from './yamlEditor';

export * from './core.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as React from 'react';
import Select, { Option } from 'react-select';

import { IgorService, IStageConfigProps, StageConfigField, YamlEditor, yamlDocumentsToString } from '@spinnaker/core';

export interface IGoogleCloudBuildStageConfigState {
googleCloudBuildAccounts: string[];
rawBuildDefinitionYaml: string;
}

export class GoogleCloudBuildStageConfig extends React.Component<IStageConfigProps, IGoogleCloudBuildStageConfigState> {
public constructor(props: IStageConfigProps) {
super(props);
this.state = {
googleCloudBuildAccounts: [],
rawBuildDefinitionYaml: props.stage.buildDefinition ? yamlDocumentsToString([props.stage.buildDefinition]) : '',
};
}

public componentDidMount = (): void => {
if (this.props.stage.isNew) {
this.props.updateStageField({ application: this.props.application.name });
}
this.fetchGoogleCloudBuildAccounts();
};

private onYamlChange = (rawYaml: string, yamlDocs: any): void => {
this.setState({ rawBuildDefinitionYaml: rawYaml });
const buildDefinition = Array.isArray(yamlDocs) && yamlDocs.length > 0 ? yamlDocs[0] : null;
this.props.updateStageField({ buildDefinition });
};

private onAccountChange = (accountOption: Option) => {
this.props.updateStageField({ account: accountOption.value });
};

private getAccountOptions = (): Option[] => {
return this.state.googleCloudBuildAccounts.map(account => ({
label: account,
value: account,
}));
};

private fetchGoogleCloudBuildAccounts = () => {
IgorService.getGcbAccounts().then((googleCloudBuildAccounts: string[]) => {
this.setState({
googleCloudBuildAccounts,
});
});
};

public render() {
return (
<div>
<StageConfigField label="Account">
<Select
clearable={false}
onChange={this.onAccountChange}
options={this.getAccountOptions()}
value={this.props.stage.account}
/>
</StageConfigField>
<StageConfigField label="Build Config">
<YamlEditor value={this.state.rawBuildDefinitionYaml} onChange={this.onYamlChange} />
</StageConfigField>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ExecutionArtifactTab } from 'core/artifact';
import { ExecutionDetailsTasks } from 'core/pipeline';
import { Registry } from 'core/registry';

import { GoogleCloudBuildStageConfig } from './GoogleCloudBuildStageConfig';

Registry.pipeline.registerStage({
label: 'Google Cloud Build',
description: 'Trigger a build in GCB (Google Cloud Build)',
key: 'googleCloudBuild',
producesArtifacts: true,
component: GoogleCloudBuildStageConfig,
executionDetailsSections: [ExecutionDetailsTasks, ExecutionArtifactTab],
validators: [{ type: 'requiredField', fieldName: 'account' }],
});
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/pipeline/pipeline.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { STAGE_SUMMARY_COMPONENT } from './details/stageSummary.component';
import { PRODUCES_ARTIFACTS } from './config/stages/producesArtifacts/producesArtifacts.component';
import { ARTIFACT_LIST } from './status/artifactList.component';
import { PIPELINE_TEMPLATES_V2_STATES_CONFIG } from './config/templates/v2/pipelineTemplateV2.states';
import './config/stages/googleCloudBuild/googleCloudBuildStage';

import './pipeline.less';
import 'angular-ui-sortable';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AceEditor, { Annotation } from 'react-ace';
import { $log } from 'ngimport';
import { loadAll, YAMLException } from 'js-yaml';

import { yamlStringToDocuments } from 'kubernetes/v2/manifest/editor/yaml/yamlEditorUtils';
import { yamlStringToDocuments } from './yamlEditorUtils';

import 'brace/theme/textmate';
import 'brace/mode/yaml';
Expand Down Expand Up @@ -59,7 +59,7 @@ export class YamlEditor extends React.Component<IYamlEditorProps> {
mode="yaml"
theme="textmate"
name="yaml-editor"
style={{ width: 'inherit' }}
style={{ width: 'auto' }}
onChange={this.handleChange}
fontSize={12}
showGutter={true}
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/modules/core/src/yamlEditor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './yamlEditor.component';
export * from './yamlEditorUtils';
export * from './YamlEditor';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { yamlStringToDocuments, yamlDocumentsToString } from 'kubernetes/v2/manifest/editor/yaml/yamlEditorUtils';
import { yamlStringToDocuments, yamlDocumentsToString } from './yamlEditorUtils';

describe('YAML editor utils', () => {
describe('yamlStringToDocuments', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module } from 'angular';

import { CloudProviderRegistry, STAGE_ARTIFACT_SELECTOR_COMPONENT_REACT } from '@spinnaker/core';
import { CloudProviderRegistry, STAGE_ARTIFACT_SELECTOR_COMPONENT_REACT, YAML_EDITOR_COMPONENT } from '@spinnaker/core';

import '../logo/kubernetes.logo.less';
import { KUBERNETES_MANIFEST_BASIC_SETTINGS } from './manifest/wizard/basicSettings.component';
Expand Down Expand Up @@ -37,7 +37,6 @@ import { KUBERNETES_ANNOTATION_CUSTOM_SECTIONS } from './manifest/annotationCust
import { KUBERNETES_V2_RESOURCE_STATES } from './resources/resources.state';
import { KUBERNETES_COPY_FROM_TEMPLATE_BUTTON } from './pipelines/stages/deployManifest/CopyFromTemplateButton';
import { KUBERNETES_MANIFEST_IMAGE_DETAILS } from 'kubernetes/v2/manifest/manifestImageDetails.component';
import { YAML_EDITOR_COMPONENT } from './manifest/editor/yaml/yamlEditor.component';
import { JSON_EDITOR_COMPONENT } from './manifest/editor/json/jsonEditor.component';
import { ManifestWizard } from 'kubernetes/v2/manifest/wizard/ManifestWizard';
import { KUBERNETES_ENABLE_MANIFEST_STAGE } from 'kubernetes/v2/pipelines/stages/traffic/enableManifest.stage';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as React from 'react';
import { FormikProps } from 'formik';
import { dump } from 'js-yaml';

import { Application } from '@spinnaker/core';
import { Application, YamlEditor } from '@spinnaker/core';

import { YamlEditor } from 'kubernetes/v2/manifest/editor/yaml/YamlEditor';
import { IKubernetesManifestCommandData } from 'kubernetes/v2/manifest/manifestCommandBuilder.service';

export interface IManifestBasicSettingsProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IExpectedArtifact,
ArtifactTypePatterns,
SETTINGS,
yamlDocumentsToString,
} from '@spinnaker/core';

import {
Expand All @@ -17,7 +18,6 @@ import {
} from 'kubernetes/v2/manifest/manifestCommandBuilder.service';

import { IManifestBindArtifact } from './ManifestBindArtifactsSelector';
import { yamlDocumentsToString } from '../../../manifest/editor/yaml/yamlEditorUtils';

export class KubernetesV2DeployManifestConfigCtrl implements IController {
public state = {
Expand Down

0 comments on commit 50b74f2

Please sign in to comment.