Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions examples/tm-pipeline/bin/tm-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { TmPipelineStack } from '../lib/tm-pipeline-stack';
import { AwsSolutionsChecks } from 'cdk-nag';
import { Aspects } from 'aws-cdk-lib';

const app = new cdk.App();
Aspects.of(app).add(new AwsSolutionsChecks({ verbose: true }))

new TmPipelineStack(app, 'CdkPipelinecdkStack', {
/* If you don't specify 'env', this stack will be environment-agnostic.
* Account/Region-dependent features and context lookups will not work,
Expand All @@ -21,4 +19,4 @@ new TmPipelineStack(app, 'CdkPipelinecdkStack', {
// env: { account: '123456789012', region: 'us-east-1' },

/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
});
34 changes: 26 additions & 8 deletions examples/tm-pipeline/lib/tm-pipeline-stack.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
import * as cdk from 'aws-cdk-lib';
import * as codepipeline_actions from 'aws-cdk-lib/aws-codepipeline-actions';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as pipelines from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
import { TmPipeline } from '../../../src';
// import * as sqs from 'aws-cdk-lib/aws-sqs';

export class TmPipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// The code that defines your stack goes here
new TmPipeline(this, 'PipelineCdk', {
pipelineName: 'PipelineCdk',
// ** Pipeline with CodeCommit source **
new TmPipeline(this, 'PipelineCdkCodeCommit', {
pipelineName: 'PipelineCdkCodeCommit',
repoName: 'cdk-constructs',
repoBranch: 'main',
primaryOutputDirectory: 'examples/cdk-pipelinecdk/cdk.out',
synthCommand: [ 'cd examples/cdk-pipelinecdk',
'npm install',
'cdk synth',
'find . -iname cdk.out',
synthCommand: [ 'cd examples/cdk-pipelinecdk',
'npm install',
'cdk synth',
'find . -iname cdk.out',
'pwd']
});

// ** Pipeline with GitHub source **
const githubSource = pipelines.CodePipelineSource.gitHub("toumoro/cdk-constructs", "main");

new TmPipeline(this, 'PipelineCdkGithub', {
pipelineName: 'PipelineCdkGithub',
source: githubSource,
primaryOutputDirectory: 'examples/tm-pipeline/cdk.out',
synthCommand: [ 'cd examples/tm-pipeline',
'npm install',
'cdk synth',
'find . -iname cdk.out',
'pwd']
});

}
}
44 changes: 32 additions & 12 deletions src/pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,38 @@ import { Construct } from 'constructs';
// https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.pipelines-readme.html

// Define the properties for the Pipeline construct

export interface TmPipelineProps {
/**
* The name of the pipeline.
*/
readonly pipelineName: string;
/**
* The name of the repository.
*/
readonly repoName: string;
/**
* The branch of the repository to use.
*/
readonly repoBranch: string;
/**
* The command to run in the synth step.
*/
readonly synthCommand?: Array<string>;
readonly synthCommand?: string[];
/**
* The primary output directory.
*/
readonly primaryOutputDirectory?: string;

/*
* The name of the repository.
* This is used only if the source is not provided.
*/
readonly repoName?: string;
/**
* The branch of the repository to use.
* This is used only if the source is not provided.
*/
readonly repoBranch?: string;

/*
* The source of the pipeline.
* This is used if repoName and repoBranch are not provided.
*/
readonly source?: pipelines.CodePipelineSource;

}

/**
Expand All @@ -47,13 +58,22 @@ export class TmPipeline extends Construct {
constructor(scope: Construct, id: string, props: TmPipelineProps) {
super(scope, id);

// Define a CodeCommit repository
const repository = codecommit.Repository.fromRepositoryName(this, props.repoName, props.repoName);
// If the source is not provided, use the CodeCommit source
let input: pipelines.CodePipelineSource;
if (props.source) {
input = props.source;
} else if (props.repoName && props.repoBranch) {
// Define a CodeCommit repository
const repository = codecommit.Repository.fromRepositoryName(this, props.repoName, props.repoName);
input = pipelines.CodePipelineSource.codeCommit(repository, props.repoBranch);
} else {
throw new Error('You must provide either source or both repoName and repoBranch');
}

// Create a pipeline
this.pipeline = new pipelines.CodePipeline(this, props.pipelineName, {
synth: new pipelines.ShellStep('Synth', {
input: pipelines.CodePipelineSource.codeCommit(repository, props.repoBranch),
input: input,
// Commands to run in the synth step
installCommands: ['npm install', 'npm ci', 'npm install -g aws-cdk'],
commands: props.synthCommand ?? ['npm install', 'npm ci', 'npm install -g aws-cdk', 'cdk synth'],
Expand Down
Loading