Skip to content

Commit

Permalink
feat(git/repo): add git/repo artifact support in kustomize bake manif…
Browse files Browse the repository at this point in the history
…est (#7572)

* feat(git/repo): add git/repo artifact support in kustomize bake manifest

* Update app/scripts/modules/core/src/pipeline/config/stages/bakeManifest/kustomize/BakeKustomizeConfigForm.tsx

Co-Authored-By: Maggie Neterval <mneterval@google.com>

* Update app/scripts/modules/core/src/pipeline/config/stages/bakeManifest/kustomize/BakeKustomizeConfigForm.tsx

Co-Authored-By: Maggie Neterval <mneterval@google.com>

* Update app/scripts/modules/core/src/pipeline/config/triggers/artifacts/gitrepo/GitRepoArtifactEditor.tsx

Co-Authored-By: Maggie Neterval <mneterval@google.com>
  • Loading branch information
2 people authored and mergify[bot] committed Oct 29, 2019
1 parent 98d4c9a commit f882544
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ArtifactIconService.registerType(ArtifactTypePatterns.KUBERNETES, require('./ico
ArtifactIconService.registerType(ArtifactTypePatterns.EMBEDDED_BASE64, require('./icons/embedded-base64-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.GCS_OBJECT, require('./icons/gcs-file-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.GITHUB_FILE, require('./icons/github-file-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.GIT_REPO, require('./icons/git-repo-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.GITLAB_FILE, require('./icons/gitlab-file-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.BITBUCKET_FILE, require('./icons/bitbucket-file-artifact.svg'));
ArtifactIconService.registerType(ArtifactTypePatterns.S3_OBJECT, require('./icons/s3-object-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 @@ -9,6 +9,7 @@ export const ArtifactTypePatterns: IArtifactTypePatterns = {
EMBEDDED_BASE64: /embedded\/base64/,
GCS_OBJECT: /gcs\/object/,
GITHUB_FILE: /github\/file/,
GIT_REPO: /git\/repo/,
GITLAB_FILE: /gitlab\/file/,
GCE_MACHINE_IMAGE: /gce\/image/,
JENKINS_FILE: /jenkins\/file/,
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/modules/core/src/artifact/icons/git-repo-artifact.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/scripts/modules/core/src/help/help.contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ const helpContents: { [key: string]: string } = {
'pipeline.config.expectedArtifact.defaultGitlab.reference': `
<p>The Gitlab API file url the artifact lives under. The domain name may change if you're running your own Gitlab server. The repository and path to files must be URL encoded.</p>
<p>An example is <code>https://gitlab.com/api/v4/projects/$ORG%2F$REPO/repository/files/path%2Fto%2Ffile.yml/raw</code>. See <a href="https://www.spinnaker.io/reference/artifacts/types/gitlab-file/#fields">our docs</a> for more info.</p>`,
'pipeline.config.expectedArtifact.gitrepo.url': '<p>The location of your Git repository.</p>',
'pipeline.config.expectedArtifact.gitrepo.branch': '<p>The branch of the repository you want to use.</p>',
'pipeline.config.expectedArtifact.gitrepo.checkoutSubpath':
'<p>Check this if you want to specify a subpath; doing so will reduce the size of the generated artifact.</p>',
'pipeline.config.expectedArtifact.gitrepo.subpath': `
<p>The subpath within the Git repository you desire to checkout.</p>
<p>e.g.: <b>examples/wordpress/mysql/</b></p>`,
'pipeline.config.expectedArtifact.helm.account': `
<p>The account contains url the charts can be found</p>`,
'pipeline.config.expectedArtifact.helm.name': `
Expand Down Expand Up @@ -258,8 +265,12 @@ const helpContents: { [key: string]: string } = {
'pipeline.config.bake.manifest.expectedArtifact': '<p>This is the template you want to render.</p>',
'pipeline.config.bake.manifest.overrideExpressionEvaluation':
'<p>Explicitly evaluate SpEL expressions in overrides just prior to manifest baking. Can be paired with the "Skip SpEL evaluation" option in the Deploy Manifest stage when baking a third-party manifest artifact with expressions not meant for Spinnaker to evaluate as SpEL.</p>',
'pipeline.config.bake.manifest.templateRenderer': '<p>This is the engine used for rendering your manifest.</p>',
'pipeline.config.bake.manifest.helm.rawOverrides':
'Use <i>--set</i> instead of <i>--set-string</i> when injecting override values. Values injected using <i>--set</i> will be converted to primitive types by Helm.',
'pipeline.config.bake.manifest.kustomize.filePath': `
<p>This is the relative path to the kustomization.yaml file within your Git repo.</p>
<p>e.g.: <b>examples/wordpress/mysql/kustomization.yaml</b></p>`,
'pipeline.config.haltPipelineOnFailure':
'Immediately halts execution of all running stages and fails the entire execution.',
'pipeline.config.haltBranchOnFailure':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';

import { IFormikStageConfigInjectedProps } from 'core/pipeline';
import { StageArtifactSelectorDelegate } from 'core/artifact';
import { IFormikStageConfigInjectedProps, StageConfigField } from 'core/pipeline';
import { StageArtifactSelectorDelegate, ArtifactTypePatterns, excludeAllTypesExcept } from 'core/artifact';
import { IArtifact, IPipeline } from 'core/domain';
import { TextInput } from 'core/presentation';

interface IBakeKustomizeConfigFormProps {
updatePipeline: (pipeline: IPipeline) => void;
Expand All @@ -27,10 +28,10 @@ export class BakeKustomizeConfigForm extends React.Component<
return (
<div className="form-horizontal clearfix">
<div className="container-fluid form-horizontal">
<h4>Kustomize File</h4>
<h4>Kustomize Options</h4>
<StageArtifactSelectorDelegate
artifact={this.getInputArtifact().artifact}
excludedArtifactTypePatterns={[]}
excludedArtifactTypePatterns={excludeAllTypesExcept(ArtifactTypePatterns.GIT_REPO)}
expectedArtifactId={this.getInputArtifact().id}
helpKey="pipeline.config.bake.manifest.expectedArtifact"
label="Expected Artifact"
Expand All @@ -56,6 +57,14 @@ export class BakeKustomizeConfigForm extends React.Component<
this.props.formik.setFieldValue('inputArtifact.artifact', null);
}}
/>
<StageConfigField label="Kustomize File" helpKey="pipeline.config.bake.manifest.kustomize.filePath">
<TextInput
onChange={(e: React.ChangeEvent<any>) => {
this.props.formik.setFieldValue('kustomizeFilePath', e.target.value);
}}
value={stage.kustomizeFilePath}
/>
</StageConfigField>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { cloneDeep, get } from 'lodash';
import * as React from 'react';

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

const TYPE = 'git/repo';

interface IGitRepoArtifactEditorState {
includesSubPath: boolean;
}

class GitRepoArtifactEditor extends React.Component<IArtifactEditorProps, IGitRepoArtifactEditorState> {
public constructor(props: IArtifactEditorProps) {
super(props);
const { artifact } = this.props;
this.state = {
includesSubPath: get(artifact, 'metadata.subPath', '') !== '',
};
}

private onIncludesSubPathChange = (event: any) => {
this.setState({ includesSubPath: event.target.checked });
};

private onReferenceChanged = (reference: string) => {
const clonedArtifact = cloneDeep(this.props.artifact);
clonedArtifact.reference = reference;
this.props.onChange(clonedArtifact);
};

private onVersionChanged = (version: string) => {
const clonedArtifact = cloneDeep(this.props.artifact);
clonedArtifact.version = version;
this.props.onChange(clonedArtifact);
};

private onSubPathChanged = (subPath: string) => {
const clonedArtifact = cloneDeep(this.props.artifact);
const metadata = get(clonedArtifact, 'metadata', {}) as any;
metadata.subPath = subPath;
clonedArtifact.metadata = metadata;
this.props.onChange(clonedArtifact);
};

public render() {
const { artifact } = this.props;

return (
<>
<StageConfigField label="URL" helpKey="pipeline.config.expectedArtifact.gitrepo.url">
<SpelText
placeholder="https or ssh to your git repo"
value={artifact.reference}
onChange={this.onReferenceChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
<StageConfigField label="Branch" helpKey="pipeline.config.expectedArtifact.gitrepo.branch">
<SpelText
placeholder="master"
value={artifact.version}
onChange={this.onVersionChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
<StageConfigField label="Checkout subpath" helpKey="pipeline.config.expectedArtifact.gitrepo.checkoutSubpath">
<CheckboxInput checked={this.state.includesSubPath} onChange={this.onIncludesSubPathChange} />
</StageConfigField>
{this.state.includesSubPath && (
<StageConfigField label="Subpath" helpKey="pipeline.config.expectedArtifact.gitrepo.subpath">
<SpelText
placeholder="path/to/subdirectory"
value={get(artifact, 'metadata.subPath', '')}
onChange={this.onSubPathChanged}
pipeline={this.props.pipeline}
docLink={true}
/>
</StageConfigField>
)}
</>
);
}
}

export const GitRepoMatch: IArtifactKindConfig = {
label: 'GitRepo',
description: 'A Git repository.',
key: 'gitrepo',
typePattern: ArtifactTypePatterns.GIT_REPO,
type: TYPE,
isDefault: false,
isMatch: true,
editCmp: GitRepoArtifactEditor,
};

export const GitRepoDefault: IArtifactKindConfig = {
label: 'GitRepo',
typePattern: ArtifactTypePatterns.GIT_REPO,
type: TYPE,
description: 'A Git repository.',
key: 'default.gitrepo',
isDefault: true,
isMatch: false,
editCmp: GitRepoArtifactEditor,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CustomMatch, CustomDefault } from './custom/CustomArtifactEditor';
import { DockerMatch, DockerDefault } from './docker/DockerArtifactEditor';
import { GcsMatch, GcsDefault } from './gcs/GcsArtifactEditor';
import { GithubMatch, GithubDefault } from './github/GithubArtifactEditor';
import { GitRepoMatch, GitRepoDefault } from './gitrepo/GitRepoArtifactEditor';
import { GitlabMatch, GitlabDefault } from './gitlab/GitlabArtifactEditor';
import { HelmMatch, HelmDefault } from './helm/HelmArtifactEditor';
import { HttpMatch, HttpDefault } from './http/HttpArtifactEditor';
Expand All @@ -28,6 +29,8 @@ export const artifactKindConfigs: IArtifactKindConfig[] = [
GcsDefault,
GithubMatch,
GithubDefault,
GitRepoMatch,
GitRepoDefault,
GitlabMatch,
GitlabDefault,
HelmMatch,
Expand Down

0 comments on commit f882544

Please sign in to comment.