-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(codepeline): ECR cannot trigger on multiple tags #20897
Conversation
The current ECR source action docs seem to indicate you can make it trigger on more than one tag at a time (or even all tags). This is not true, so stop advertising that feature. Fixes #20594.
It's worth pointing out that if you trigger on import {
aws_codebuild,
aws_codepipeline,
aws_codepipeline_actions,
aws_ec2,
aws_ecr,
aws_ecs,
aws_ssm,
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Namer } from 'multi-convention-namer';
// import { ServicePrincipals } from 'cdk-constants';
export interface CouplerPipelineProps {
/**
* The AWS account hosting the ECR.
*/
readonly account: string;
/**
* A string containing a python re which will be used to identify the tag to put
* in the `imagedefinitions.json` file that will be handed off to the EcsDeployAction.
* Typically you want SemVer tags. But...
*
* @default '^v\\d+\\.\\d+\\.\\d+'
*/
readonly immutableTagPattern?: string;
/**
* The AWS region hosting the ECR.
*/
readonly region: string;
/**
* When referencing the ECS Cluster, we can optionally provide the list of
* securityGroups it is in. We haven't seen a need for this yet.
*
* @default []
*/
readonly securityGroups?: aws_ec2.ISecurityGroup[];
/**
* Which docker tag should we watch for pushes?
* This will be used by the EcrSourceAction to filter.
* Until we get a proper resolution to https://github.com/aws/aws-cdk/issues/20594
*
* @default 'latest'
*/
readonly triggerTag?: string;
/**
* The VPC in which the ECS Cluster resides.
*/
readonly vpc: aws_ec2.IVpc;
/**
* The Repository which to connect it to. If omitted it will make certain
* assumptions about the repo.
* @default - service specific repository pulled from ssm params
*/
readonly repository?: aws_ecr.IRepository;
}
export class CouplerPipeline extends Construct {
constructor(scope: Construct, id: Namer, props: CouplerPipelineProps) {
super(scope, id.addSuffix(['coupler']).pascal);
const immutableTagPattern = props.immutableTagPattern ?? '^v\\d+\\.\\d+\\.\\d+';
const imageInput = new aws_codepipeline.Artifact('Image');
const updateInput = new aws_codepipeline.Artifact('ImageDefinitions');
const repository =
props.repository ??
aws_ecr.Repository.fromRepositoryAttributes(this, 'Repository', {
repositoryArn: aws_ssm.StringParameter.valueForStringParameter(
this,
`/${id.pascal}/${id.addSuffix(['repository']).pascal}/${id.pascal}/repositoryArn`,
),
repositoryName: id.kebab,
});
const cluster = aws_ecs.Cluster.fromClusterAttributes(this, 'Cluster', {
clusterName: id.kebab,
securityGroups: props.securityGroups ?? [],
vpc: props.vpc,
});
const service = aws_ecs.FargateService.fromFargateServiceAttributes(this, 'Service', {
cluster,
serviceName: id.pascal,
});
new aws_codepipeline.Pipeline(this, id.pascal, {
pipelineName: id.pascal,
stages: [
{
stageName: 'Received',
actions: [
new aws_codepipeline_actions.EcrSourceAction({
actionName: 'Image',
imageTag: props.triggerTag ?? 'latest',
repository,
output: imageInput,
}),
],
},
{
stageName: 'GenerateImageDefinitions',
actions: [
new aws_codepipeline_actions.CodeBuildAction({
environmentVariables: {
ECR_REPO_URI: { value: `${props.account}.dkr.ecr.${props.region}.amazonaws.com/${id.kebab}` },
},
input: imageInput,
outputs: [updateInput],
actionName: 'GenerateImageDefinitions',
project: new aws_codebuild.Project(this, 'GenerateImageDefinitions', {
buildSpec: aws_codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
build: {
commands: [
'cat imageDetail.json',
//https://stackoverflow.com/a/57015190
`TAG=$(cat imageDetail.json | python -c "import re, sys, json; p=re.compile('${immutableTagPattern}'); tags=json.load(sys.stdin)['ImageTags']; print([s for s in tags if p.match(s)][0])")`,
'echo "${ECR_REPO_URI}:${TAG}"',
`printf '[{\"name\":\"${id.kebab}\",\"imageUri\":\"%s\"}]' $ECR_REPO_URI:$TAG > imagedefinitions.json`,
'pwd; ls -al; cat imagedefinitions.json',
],
},
},
artifacts: { files: ['imagedefinitions.json'] },
}),
}),
}),
],
},
{
stageName: 'UpdateFargate',
actions: [
new aws_codepipeline_actions.EcsDeployAction({
actionName: 'Deploy',
input: updateInput,
service,
}),
],
},
],
});
}
} |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
The current ECR source action docs seem to indicate you can make it trigger on more than one tag at a time (or even all tags). This is not true, so stop advertising that feature. Fixes aws#20594. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
The current ECR source action docs seem to indicate you can make it
trigger on more than one tag at a time (or even all tags). This is
not true, so stop advertising that feature.
Fixes #20594.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license