Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// customize the healthcheck to speed up the ecs rolling update
fargatesvc.targetGroup.configureHealthCheck({
interval: Duration.seconds(5),
healthyHttpCodes: '200',
healthyThresholdCount: 2,
unhealthyThresholdCount: 3,
timeout: Duration.seconds(4),
})
// CodePipeline
const codePipeline = new codepipeline.Pipeline(this, 'CoffeeShopPipeline', {
pipelineName: 'CoffeeShopPipeline',
});
const sourceOutputEcr = new codepipeline.Artifact();
const sourceOutputCodeCommit = new codepipeline.Artifact();
const sourceActionECR = new codepipeline_actions.EcrSourceAction({
actionName: 'ECR',
repository: this.ecrRepository,
imageTag: 'latest', // optional, default: 'latest'
output: sourceOutputEcr,
});
const codecommitRepo = new codecommit.Repository(this, 'GitRepo', {
repositoryName: CODECOMMIT_REPO_NAME
});
const sourceActionCodeCommit = new codepipeline_actions.CodeCommitSourceAction({
actionName: 'CodeCommit',
// repository: codecommit.Repository.fromRepositoryName(this, 'GitRepo', CODECOMMIT_REPO_NAME),
repository: codecommitRepo,
output: sourceOutputCodeCommit,
public constructor(parent: App, name: string, props?: StackProps) {
super(parent, name, props);
const repository = new Repository(this, 'Repository', {
repositoryName: 'MyRepositoryName',
description: 'Some description.', // optional property
});
const sourceArtifact = new Artifact();
const sourceAction = new CodeCommitSourceAction({
actionName: 'CodeCommit',
repository,
output: sourceArtifact,
branch: 'master',
});
const checkAction = new CodepipelineCheckParameterAction({
actionName: 'Check',
parameterName: '/test',
regExp: /^The.*Spain$/,
logParameter: true,
});
new Pipeline(this, 'MyPipeline', {
fargatesvc.targetGroup.setAttribute('deregistration_delay.timeout_seconds', '30')
// customize the healthcheck to speed up the ecs rolling update
fargatesvc.targetGroup.configureHealthCheck({
interval: Duration.seconds(5),
healthyHttpCodes: '200',
healthyThresholdCount: 2,
unhealthyThresholdCount: 3,
timeout: Duration.seconds(4),
})
// CodePipeline
const codePipeline = new codepipeline.Pipeline(this, 'CoffeeShopPipeline', {
pipelineName: 'CoffeeShopPipeline',
});
const sourceOutputEcr = new codepipeline.Artifact();
const sourceOutputCodeCommit = new codepipeline.Artifact();
const sourceActionECR = new codepipeline_actions.EcrSourceAction({
actionName: 'ECR',
repository: this.ecrRepository,
imageTag: 'latest', // optional, default: 'latest'
output: sourceOutputEcr,
});
const codecommitRepo = new codecommit.Repository(this, 'GitRepo', {
repositoryName: CODECOMMIT_REPO_NAME
});
const sourceActionCodeCommit = new codepipeline_actions.CodeCommitSourceAction({
actionName: 'CodeCommit',
// repository: codecommit.Repository.fromRepositoryName(this, 'GitRepo', CODECOMMIT_REPO_NAME),
repository: codecommitRepo,
moduleName,
stageName,
moduleBuildProject,
moduleDeployProject,
pipelineRole,
...rest
} = props
super(scope, id, {
pipelineName: `${moduleName}_${stageName}_pipeline`,
artifactBucket: artifactsBucket,
role: pipelineRole,
...rest
})
const sourceOutputArtifact = new Artifact()
const sourceAction = new S3SourceAction({
bucket: artifactsBucket,
bucketKey: `${stageName}_module_pipelines/module_source/${moduleName}.zip`,
output: sourceOutputArtifact,
trigger: S3Trigger.EVENTS, // Use EVENTS instead of POLL to avoid triggering. We won't set up CloudTrail for S3.
actionName: `${moduleName}_src`,
role: pipelineRole
})
this.addStage({
stageName: 'Source',
actions: [sourceAction]
})
const environmentVars = {
CROSS_ACCOUNT_ID: {
const moduleBuildOutputArtifact = new Artifact()
const moduleBuildAction = new CodeBuildAction({
actionName: 'Build',
input: sourceOutputArtifact,
outputs: [moduleBuildOutputArtifact],
project: moduleBuildProject,
role: pipelineRole,
environmentVariables: environmentVars
})
this.addStage({
stageName: 'Build',
actions: [moduleBuildAction]
})
const moduleDeployOutputArtifact = new Artifact()
const moduleDeployAction = new CodeBuildAction({
actionName: 'Deploy',
input: moduleBuildOutputArtifact,
outputs: [moduleDeployOutputArtifact],
project: moduleDeployProject,
role: pipelineRole,
environmentVariables: environmentVars
})
this.addStage({
stageName: 'Deploy',
actions: [moduleDeployAction]
})
}
}
addDeployStage(
stageName: StageName,
orchestratorCodeBuildRole: Role,
sourceOutputArtifact: Artifact
) {
const orchestratorDeployStagingProject = new OrchestratorDeployProject(
this,
`${stageName}OrchestratorDeploy`,
{
stageName,
role: orchestratorCodeBuildRole
}
)
const deployOutputArtifact = new Artifact()
const deployAction = new CodeBuildAction({
actionName: stageName,
input: sourceOutputArtifact,
outputs: [deployOutputArtifact],
project: orchestratorDeployStagingProject
})
this.addStage({
stageName: `${stageName}Deploy`,
actions: [deployAction]
})
}
}
}
)
const integrationTestOutputArtifact = new Artifact()
const integrationTestAction = new CodeBuildAction({
actionName: 'integration_tests',
input: sourceOutputArtifact,
outputs: [integrationTestOutputArtifact],
project: integrationTestProject
})
const e2eTestProject = new E2ETestProject(this, `e2eTests`, {
stageName: StageName.stg
})
const e2eTestOutputArtifact = new Artifact()
const e2eTestAction = new CodeBuildAction({
actionName: 'e2e_tests',
input: sourceOutputArtifact,
outputs: [e2eTestOutputArtifact],
project: e2eTestProject
})
this.addStage({
stageName: 'Test',
actions: [integrationTestAction, e2eTestAction]
})
}
]
}
},
artifacts: {
files: '**/*'
}
},
environment: defaultEnvironment,
role: resources.codeBuildRole
}
)
const checkChangesAction = new CodeBuildAction({
actionName: 'check-changes',
input: resources.sourceAction.output,
output: new Artifact(),
project: resources.checkChangesProject
})
resources.checkChangesAction = checkChangesAction
resources.pipeline.addStage({
name: 'check_changes',
actions: [checkChangesAction]
})
}
}
constructor(scope: Construct, resources: any) {
super(scope, 'sourceStage')
const pipeline: Pipeline = resources.pipeline
const tokenSecret = SecretValue.secretsManager('CICD', {
jsonField: 'GitHubPersonalAccessToken'
})
const sourceAction = new codePipelineActions.GitHubSourceAction({
actionName: 'SourceAction',
owner: config.sourceRepoOwner,
repo: config.sourceRepoName,
branch: config.sourceBranch,
oauthToken: tokenSecret,
output: new Artifact()
})
resources.sourceAction = sourceAction
pipeline.addStage({ name: 'source', actions: [sourceAction] })
}
}