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

Codebuild: Removing Cache property does not revert cache to NO_CACHE #18165

Closed
NeilBostrom opened this issue Dec 24, 2021 · 4 comments · Fixed by #18194
Closed

Codebuild: Removing Cache property does not revert cache to NO_CACHE #18165

NeilBostrom opened this issue Dec 24, 2021 · 4 comments · Fixed by #18194
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1

Comments

@NeilBostrom
Copy link

NeilBostrom commented Dec 24, 2021

What is the problem?

First setting Cache = Cache.Local(LocalCacheMode.DOCKER_LAYER), on a CodeBuild Project and deploying will correctly set the Cache setting on the project.
If you remove the Cache set from your source code, the CodeBuild project is not reverted back to NO_CACHE. It leaves the previous DOCKER_LAYER in place.
This is unexpected as most properties revert to their default option when removed.

Reproduction Steps

            var project = new Project(this, $"{ServiceName}CodeBuild", new ProjectProps
            {
                ProjectName = "Test",
                Cache = Cache.Local(LocalCacheMode.DOCKER_LAYER),
                BuildSpec = BuildSpec.FromObject(new Dictionary<string, object>
                {
                    ["version"] = "0.2",
                    ["phases"] = new Dictionary<string, object>
                    {
                        ["build"] = new Dictionary<string, object>
                        {
                            ["commands"] = new string[] {
                                "rake build[${CODEBUILD_BUILD_NUMBER}]"
                            }
                        }
                    }
                }))
            });

What did you expect to happen?

Removing the Cache = should revert the CodeBuild project to NO_CACHE

What actually happened?

Nothing, removing the property leaves the previous caching property in place.

CDK CLI Version

2.3.0 (build beaa5b2)

Framework Version

No response

Node.js Version

v14.16.1

OS

Windows 11

Language

.NET

Language Version

.NET Core 6

Other information

The reason I spotted this was that I'm in the process of moving to arm64 in our CodeBuild projects. Applying the following change to our CDK stack fails:

image

Failed to call UpdateProject, reason: Invalid cache type: local caching is not supported for projects with environment type ARM_CONTAINER and compute type BUILD_GENERAL1_SMALL (Service: AWSCodeBuild; Status Code: 400; Error Code: InvalidInputException; Request ID: 19e3b77c-fcf9-4440-a8ac-1610fb441656; Proxy: null)
        new Project (/tmp/jsii-kernel-moicem/node_modules/@aws-cdk/aws-codebuild/lib/project.js:355:26)
        \_ /tmp/0lk2tlal.3bx/lib/program.js:8432:58
        \_ Kernel._wrapSandboxCode (/tmp/0lk2tlal.3bx/lib/program.js:8860:24)
        \_ Kernel._create (/tmp/0lk2tlal.3bx/lib/program.js:8432:34)
        \_ Kernel.create (/tmp/0lk2tlal.3bx/lib/program.js:8173:29)
        \_ KernelHost.processRequest (/tmp/0lk2tlal.3bx/lib/program.js:9757:36)
        \_ KernelHost.run (/tmp/0lk2tlal.3bx/lib/program.js:9720:22)
        \_ Immediate._onImmediate (/tmp/0lk2tlal.3bx/lib/program.js:9721:46)
        \_ processImmediate (internal/timers.js:464:21)
@NeilBostrom NeilBostrom added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 24, 2021
@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Dec 24, 2021
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Dec 27, 2021
When implementing caching in CodeBuild,
we made the default cache `Cache.none()`,
and, for that reason, do not render anything in the template for that type of cache.
However, that does not work well with the CodeBuild API,
which interprets the lack of a property as the signal to leave it unchanged.
Which means it's not possible currently to disable caching on a Project once it has been enabled once.

Fix this by differentiating between the case of "no Cache has been provided",
and "the none() Cache has been provided".

Closes aws#18165
@skinny85
Copy link
Contributor

Thanks for opening the issue @NeilBostrom. The problem you're running into, I'm pretty sure, is that the CodeBuild API treats not provided fields as unchanged, and that's why removing the Cache property doesn't have any effect.

The correct way to unblock yourself would be to use Cache.None() instead of Cache.Local(), however I discovered a bug in how that method is implemented. I submitted a fix in #18194 - once that is merged and released in a new CDK version, providing Cache.None() should do the trick.

Apologies for the bad experience.

Thanks,
Adam

@skinny85 skinny85 added effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 27, 2021
@skinny85 skinny85 removed their assignment Dec 27, 2021
@skinny85
Copy link
Contributor

In the meantime, you can try using escape hatches to set the cache type to NO_CACHE.

skinny85 added a commit to skinny85/aws-cdk that referenced this issue Dec 31, 2021
When implementing caching in CodeBuild,
we made the default cache `Cache.none()`,
and, for that reason, do not render anything in the template for that type of cache.
However, that does not work well with the CodeBuild API,
which interprets the lack of a property as the signal to leave it unchanged.
Which means it's not possible currently to disable caching on a Project once it has been enabled once.

Fix this by differentiating between the case of "no Cache has been provided",
and "the none() Cache has been provided".

Closes aws#18165
@NeilBostrom
Copy link
Author

Thanks @skinny85. I thought that might be the case, it was just a little unexpected. Feel free to close this and hopefully it will help someone along their similar journey of Googling.

@mergify mergify bot closed this as completed in #18194 Jan 4, 2022
mergify bot pushed a commit that referenced this issue Jan 4, 2022
…18194)

When implementing caching in CodeBuild,
we made the default cache `Cache.none()`,
and, for that reason, do not render anything in the template for that type of cache.
However, that does not work well with the CodeBuild API,
which interprets the lack of a property as the signal to leave it unchanged.
Which means it's not possible currently to disable caching on a Project once it has been enabled once.

Fix this by differentiating between the case of "no Cache has been provided",
and "the none() Cache has been provided".

Closes #18165

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Jan 4, 2022

⚠️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.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…ws#18194)

When implementing caching in CodeBuild,
we made the default cache `Cache.none()`,
and, for that reason, do not render anything in the template for that type of cache.
However, that does not work well with the CodeBuild API,
which interprets the lack of a property as the signal to leave it unchanged.
Which means it's not possible currently to disable caching on a Project once it has been enabled once.

Fix this by differentiating between the case of "no Cache has been provided",
and "the none() Cache has been provided".

Closes aws#18165

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants