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

(DockerImage Build): Bundling is Not Skipped During List or When Excluded by --exclusively #19615

Closed
joel-aws opened this issue Mar 29, 2022 · 4 comments
Labels
bug This issue is a bug. duplicate This issue is a duplicate. package/tools Related to AWS CDK Tools or CLI

Comments

@joel-aws
Copy link
Contributor

What is the problem?

When running cdk ls or cdk synth my-specific-stack --exclusively, stacks that use DockerImage.from_build are bundled, which can add a lot of time for complex docker builds, even if cached.

Reproduction Steps

Run:

  • cdk ls
  • cdk synth stack-one --exclusively --quiet

app.py:

from aws_cdk import (
    App,
    Duration,
    Stack,
    Stage,
    BundlingOptions,
    DockerImage,
    aws_s3 as s3,
    aws_s3_deployment as s3_deploy,
    aws_sns as sns,
    aws_sqs as sqs,
    aws_sns_subscriptions as subs,
)

from constructs import Construct

app = App()


class StackOne(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        queue = sqs.Queue(
            self,
            "DelMeNowQueue",
            visibility_timeout=Duration.seconds(300),
        )

        topic = sns.Topic(self, "DelMeNowTopic")

        topic.add_subscription(subs.SqsSubscription(queue))


class StackTwo(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        bucket = s3.Bucket(self, "bucket")

        s3_deploy.BucketDeployment(
            self,
            "ui-deployment",
            retain_on_delete=False,
            sources=[
                s3_deploy.Source.asset(
                    asset_hash="abc",
                    path=f"docker",
                    bundling=BundlingOptions(
                        image=DockerImage.from_build(
                            path="docker",
                        ),
                        command=[
                            "/bin/bash",
                            "-c",
                            " &&".join(
                                [
                                    "printenv > env.txt",
                                    "cp env.txt /asset-output",
                                ]
                            ),
                        ],
                    ),
                )
            ],
            destination_bucket=bucket,
            memory_limit=1024,
        )


StackOne(app, "stack-one")
StackTwo(app, "stack-two")

app.synth()

docker/Dockerfile:

FROM public.ecr.aws/sam/build-nodejs14.x
RUN sleep 10 # Change this and the contents won't be cached

What did you expect to happen?

I expected assets to not be bundled during an ls and when not included in a synth that excludes the stack with the resource via --exclusively.

What actually happened?

Docker output is clearly seen in the console during an ls and synth that excludes it.

CDK CLI Version

2.18.0

Framework Version

No response

Node.js Version

v16.3.0

OS

macOS 11.6.5

Language

Python

Language Version

No response

Other information

No response

@joel-aws joel-aws added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 29, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Mar 29, 2022
@peterwoodworth peterwoodworth added duplicate This issue is a duplicate. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 29, 2022
@peterwoodworth
Copy link
Contributor

Hey @joel-aws, we're tracking this issue here #6743

Seems it hasn't got much attention unfortunately, please add a comment there and give a thumbs up reaction to the issue as that helps us decide what to work on.

@github-actions
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.

@joel-aws
Copy link
Contributor Author

joel-aws commented Mar 29, 2022

@peterwoodworth -- thanks for pointing that ticket out. I think there's two parts to this:

  • The issue you identified, where all Stacks and their assets need to exists.
  • The issue where Bundling is done during a ls or if excluded during a synth (even if the asset exists already) -- I don't think the ticket you linked asks to address this, right?

@peterwoodworth
Copy link
Contributor

Thanks for letting me know I didn't address all your concerns.

This comment describes why asset bundling is done during synth (and thus ls, because ls needs to synthesize to know which stacks there are). So currently, I think those issues you have are not possible for us to address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. duplicate This issue is a duplicate. package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

3 participants