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

Create repo in stack A and ref it to codepipeline in stack B throws 'cyclic reference' #5727

Closed
codyfy opened this issue Jan 9, 2020 · 13 comments
Labels
@aws-cdk/aws-codecommit Related to AWS CodeCommit @aws-cdk/aws-codepipeline Related to AWS CodePipeline bug This issue is a bug. cross-stack Related to cross-stack resource sharing effort/medium Medium work item – several days of effort p1

Comments

@codyfy
Copy link

codyfy commented Jan 9, 2020

❓ General Issue

The Question

Stack A has a CodeCommit repo. I want the CodePipeline in Stack B to use this repo. This throws Adding this dependency (cdk-repo -> cdk-pipe/CodePipeline/Resource.Ref) would create a cyclic reference.

I just had a very similar problem #5657 where I manually needed to hard code the artifact bucket. However, this time the resource mentioned in the error is hardcoded. So I am unsure if this me not understanding how this is supposed to work or if this is unexpected behavior.

Code

Here is a repo with an example of what I try to do.

app.py

#!/usr/bin/env python3

from aws_cdk import core

from cdk_repopipe.cdk_repo_stack import RepoStack
from cdk_repopipe.cdk_pipe_stack import PipelineStack


app = core.App()
repo_stack = RepoStack(app, "cdk-repo")
pipe_stack = PipelineStack(app, "cdk-pipe", repo_stack.repo)

app.synth()

repo.py

from aws_cdk import (
    core,
    aws_codecommit as codecommit
)


class RepoStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here
        self.repo = codecommit.Repository(self, "my-repo", repository_name="test-repo")

pipeline.py

from aws_cdk import (
    core,
    aws_codecommit as codecommit,
    aws_codebuild as codebuild,
    aws_codepipeline as codepipeline,
    aws_autoscaling as autoscaling,
    aws_codepipeline_actions as codepipeline_actions,
    aws_codedeploy as codedeploy,
    aws_ec2 as ec2,
    aws_s3 as s3
)


class PipelineStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, repo: codecommit.Repository, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Pipeline
        artifactBucket = s3.Bucket(self, 'PipelineBucket',
            bucket_name="bucket-name")

        pipeline = codepipeline.Pipeline(self, "CodePipeline",
            artifact_bucket=s3.Bucket.from_bucket_attributes(self, 'ImportedBucket',
            bucket_name="bucket-name")
        )
        
        # Source
        source_output = codepipeline.Artifact()
        source_action = codepipeline_actions.CodeCommitSourceAction(
            action_name="Source",
            repository=repo,
            output=source_output
        )        
        pipeline.add_stage(stage_name="Source", actions=[source_action])


        # Deploy
        deploy_application = codedeploy.ServerApplication(self, "CodeDeployApplication", 
            application_name="application-name"
        )

        deployment_group = codedeploy.ServerDeploymentGroup(self, "DeploymentGroup",
            application=deploy_application,
        )
        
        deploy_action = codepipeline_actions.CodeDeployServerDeployAction(
            action_name="deploy",
            input=source_output,
            deployment_group=deployment_group
        )
        pipeline.add_stage(stage_name="Deploy", actions=[ deploy_action ])

Environment

  • CDK CLI Version: aws-cli/1.14.44 Python/3.6.9 Linux/5.0.0-37-generic botocore/1.13.13
  • Module Version: 1.19.0 (build 5597bbe)
  • OS: Ubuntu 18.04.3 LTS
  • Language: Python

Other information

The repo has to be in a different stack so it can be used by prod and dev stacks

@codyfy codyfy added the needs-triage This issue or PR still needs to be triaged. label Jan 9, 2020
@SomayaB SomayaB added cross-stack Related to cross-stack resource sharing guidance Question that needs advice or information. @aws-cdk/aws-codecommit Related to AWS CodeCommit @aws-cdk/aws-codepipeline Related to AWS CodePipeline labels Jan 13, 2020
@markusl
Copy link
Contributor

markusl commented Jan 22, 2020

@skinny85 I'm also encountering the same issue. Is there any workaround for this behavior until a proper fix is implemented?

@skinny85
Copy link
Contributor

Hey @codyfy and @markusl ,

yes - there should be a simple answer to this! The cycle is because of a CloudWatch Event that is added to the repository that triggers the pipeline. If you change the source action to use polling instead:

        source_action = codepipeline_actions.CodeCommitSourceAction(
            # rest of the properties as above...
            trigger=codepipeline_actions.CodeCommitTrigger.POLL,
        )

this will remove the cycle.

Let me know if this works!

Thanks,
Adam

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 19, 2020
@mikestopcontinues
Copy link

Also, you can reference the repo by name, and add a manual dependency from the Pipeline stack to the stack with the repo:

// App
const repositoryName = 'Repo';
const app = new App();

// CommonStack
const commonStack = new Stack(app, 'CommonStack', stackProps);
commonStack.repo = new Repository(commonStack, 'CommonCodeRepo', {repositoryName});

// PipelineStack
const pipeStack = new Stack(app, 'PipelineStack', stackProps);
pipeStack.addDependency(commonStack);
pipeStack.repo = Repository.fromRepositoryName(pipeStack, 'SourceRepo', repositoryName);

@skinny85
Copy link
Contributor

Yes, this is excellent advice @mikestopcontinues!

@SomayaB SomayaB added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Mar 30, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Apr 3, 2020

Closing for now since this looks to have been resolved. Feel free to reopen if that's not the case.

@SomayaB SomayaB closed this as completed Apr 3, 2020
@ccurrie-amzn
Copy link
Contributor

I'd like to request that this be re-opened. If I take the OP's code and replace the direct use of the repository with codecommit.Repository.fromRepositoryArn(self, "ImportedRepository", repository.repositoryArn), the reference and the cycle are not created. Is there a barrier to the pipeline or the source action detecting that the repository is from a different stack, and "doing the right thing" in this case?

@skinny85
Copy link
Contributor

Re-opening as per @ccurrie-amzn 's request.

@skinny85 skinny85 reopened this Oct 15, 2020
@skinny85 skinny85 added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 and removed closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information. labels Oct 15, 2020
@teddyaryono
Copy link

Is there any update to this one?

@skinny85
Copy link
Contributor

skinny85 commented Mar 1, 2021

Not much @teddyaryono , sorry. A PR would be very welcome if that's a possibility.

@athempel
Copy link

Is this a duplicate of #3087?

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 29, 2023
@skinny85
Copy link
Contributor

Yes, I believe this issue was fixed by PR #20149, the same PR that fixed #3087.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 30, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codecommit Related to AWS CodeCommit @aws-cdk/aws-codepipeline Related to AWS CodePipeline bug This issue is a bug. cross-stack Related to cross-stack resource sharing effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

No branches or pull requests

9 participants