Skip to content
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

pipelines: Codepipeline.add_wave does not keep the stages sperated #31023

Open
SpielerNogard opened this issue Aug 5, 2024 · 2 comments
Open
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. effort/small Small work item – less than a day of effort p3

Comments

@SpielerNogard
Copy link

Describe the bug

I added an wave to my pipeline to deploy multiple stages in paralell. Every Stage has its own Approval step in pre of it. But if i approve an single Stage the stage dont gets deployed

Expected Behavior

I expect if i press on the manual approval of the stage, to deploy the stage

Current Behavior

Bildschirmfoto 2024-08-05 um 11 23 16

I pressed the manual approval of an Stage and the deployment does not continue

Reproduction Steps

from typing import Literal

import aws_cdk
import aws_cdk.aws_codebuild as codebuild
from aws_cdk import aws_codecommit as codecommit, aws_iam as iam, pipelines
from constructs import Construct

ACCOUNT_ID = ""
REPO_ARN = ""
PIPELINE_NAME = ""


class Services(aws_cdk.Stage):
    def __init__(
        self,
        scope: aws_cdk.Stack,  # object of type Pipeline
        id_: str,
        branch: str,
        env: aws_cdk.Environment,
    ):
        super().__init__(scope=scope, id=id_, env=env)
        self.branch = branch
        aws_cdk.Stack(
            scope=self,
            id="EmptyTestStack",
        )


class PipelineStack(aws_cdk.Stack):
    def __init__(self, scope: Construct, id: str, branch: str, **kwargs):
        super().__init__(scope, id, **kwargs)
        self.branch = branch
        pipeline = self._create_pipeline(branch=branch)
        self._add_stages(pipeline=pipeline, id_suffix="Lab", branch=branch)

    def _add_stages(
        self,
        pipeline: pipelines.CodePipeline,
        id_suffix: Literal["Lab"],
        branch: str,
    ) -> None:
        wave = pipeline.add_wave(
            f"TestStage-{id_suffix}",
        )

        deployments = [
            {"account": ACCOUNT_ID, "region": "eu-central-1"},
            {"account": ACCOUNT_ID, "region": "us-east-1"},
        ]

        for deployment in deployments:
            services = Services(
                self,
                f"Services-{id_suffix}-{deployment['account']}--{deployment['region']}",
                branch,
                env=aws_cdk.Environment(
                    account=deployment["account"], region=deployment["region"]
                ),
            )
            wave.add_stage(
                stage=services,
                pre=[
                    pipelines.ManualApprovalStep(
                        f'Approve-Services-{deployment["account"]}-{deployment["region"]}'
                    )
                ],
            )

    def _create_pipeline(self, branch: str) -> pipelines.CodePipeline:
        repository = codecommit.Repository.from_repository_arn(
            scope=self,
            id="TestRepo",
            repository_arn=(REPO_ARN),
        )
        self.synth_input = pipelines.CodePipelineSource.code_commit(
            repository=repository,
            branch=branch,
        )
        synth = pipelines.CodeBuildStep(
            id="Synth",
            build_environment=codebuild.BuildEnvironment(
                build_image=codebuild.LinuxBuildImage.STANDARD_7_0, privileged=True
            ),
            input=self.synth_input,
            partial_build_spec=codebuild.BuildSpec.from_object(
                {
                    "version": "0.2",
                    "phases": {
                        "install": {
                            "runtime-versions": {"python": "3.11"},
                        }
                    },
                }
            ),
            install_commands=[],
            commands=["cdk synth"],
            role_policy_statements=[
                iam.PolicyStatement(
                    effect=iam.Effect.ALLOW,
                    resources=["*"],
                    actions=[
                        "codeartifact:GetAuthorizationToken",
                        "codeartifact:GetRepositoryEndpoint",
                        "codeartifact:PublishPackageVersion",
                        "codeartifact:PutPackageMetadata",
                        "codeartifact:ReadFromRepository",
                        "codeartifact:ListPackageVersions",
                        "ssm:*",
                        "ecr:*",
                    ],
                ),
                iam.PolicyStatement(
                    effect=iam.Effect.ALLOW,
                    resources=["*"],
                    actions=["sts:GetServiceBearerToken"],
                    conditions={
                        "StringEquals": {
                            "sts:AWSServiceName": "codeartifact.amazonaws.com"
                        }
                    },
                ),
            ],
            primary_output_directory="cdk.out",
        )
        return pipelines.CodePipeline(
            scope=self,
            id="Pipeline",
            pipeline_name=PIPELINE_NAME,
            synth=synth,
            cross_account_keys=True,
            docker_enabled_for_synth=True,
            self_mutation=True,
        )

Possible Solution

Every Stage should be kept seperate

Additional Information/Context

No response

CDK CLI Version

2.142.1 (build ed4e152)

Framework Version

No response

Node.js Version

v22.3.0

OS

Mac OS Sonoma 14.5 (23F79)

Language

Python

Language Version

3.12

Other information

No response

@SpielerNogard SpielerNogard added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 5, 2024
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Aug 5, 2024
@pahud
Copy link
Contributor

pahud commented Aug 5, 2024

image

Looks like it may require all the 3 to be approved? Have you tried to approve them all?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Aug 5, 2024
@SpielerNogard
Copy link
Author

SpielerNogard commented Aug 6, 2024

Yes once i approve all 3 it works. But exactly this is my problem. I only want to approve one and only deploy this stage and the others later.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. effort/small Small work item – less than a day of effort p3
Projects
None yet
Development

No branches or pull requests

2 participants