Skip to content

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

@NeilBostrom

Description

@NeilBostrom

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-codebuildRelated to AWS CodeBuildbugThis issue is a bug.effort/smallSmall work item – less than a day of effortin-progressThis issue is being actively worked on.p1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions