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: Arrays are not preserved between commands #26694

Closed
BastiQ opened this issue Aug 9, 2023 · 9 comments
Closed

codebuild: Arrays are not preserved between commands #26694

BastiQ opened this issue Aug 9, 2023 · 9 comments
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild bug This issue is a bug. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@BastiQ
Copy link

BastiQ commented Aug 9, 2023

Describe the bug

When using LinuxArmBuildImage with the docker image, public.ecr.aws/sam/build-python3.9:latest-arm64 and buildspec version 0.2, I run into the issue that arrays are not being preserved between commands.

According to the docs this should only happen with buildspec version 0.1 and be resolved in version 0.2.

The weird thing is, that other variables are preserved, and array variables can be looped over if the command is in the same line (see examples below).

This, btw. doesn't happen if I use LinuxBuildImage with public.ecr.aws/sam/build-python3.9:latest (no arm image).

I assume this is a bug, as arm support has just recently (v2.88.0, #26121, f522796) been added.

Expected Behavior

Current Behavior

Reproduction Steps

from aws_cdk import aws_codebuild as codebuild
# ...
example_codebuild_project = codebuild.Project(
    self,
    "EFSPackageInstallerProject",
    project_name="EFSPackageInstallerProject",
    description="Installs Python packages on EFS for use in model serving Lambda",
    build_spec=codebuild.BuildSpec.from_object(
        {
            "version": "0.2",
            "phases": {
                "build": {
                    "commands": [
                        'my_array=("first" "second" "third" "fourth")',
                        'for item in "${my_array[@]}"; do echo "$item" ; done',
                        # → empty outputs
                        'my_array=("first" "second" "third" "fourth"); for item in "${my_array[@]}"; do echo "$item" ; done',
                        # Outputs:
                        # first
                        # second
                        # third
                        # fourth

                        'myvar=hello; echo $myvar',
                        # outputs: hello
                        'myvar=hello',
                        'echo $myvar',
                        # outputs: hello
                    ]
                }
            },
        }
    ),
    environment=codebuild.BuildEnvironment(
        build_image=codebuild.LinuxArmBuildImage.from_docker_registry(
            f"public.ecr.aws/sam/build-python3.9:latest-arm64"
        ),
        compute_type=codebuild.ComputeType.SMALL,
        privileged=True,
    ),
)

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.90.0 (build 8c535e4)

Framework Version

No response

Node.js Version

v16.16.0

OS

MacOS

Language

Python

Language Version

3.9

Other information

No response

@BastiQ BastiQ added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 9, 2023
@github-actions github-actions bot added the @aws-cdk/aws-codebuild Related to AWS CodeBuild label Aug 9, 2023
@BastiQ BastiQ changed the title codebuild: codebuild: Arrays are not being preserved between commands Aug 9, 2023
@BastiQ BastiQ changed the title codebuild: Arrays are not being preserved between commands codebuild: Arrays are not preserved between commands Aug 10, 2023
@peterwoodworth
Copy link
Contributor

What makes you think this is an issue with CDK, can you identify a misconfigured option in the synthesized template?

@peterwoodworth peterwoodworth added p1 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 10, 2023
@BastiQ
Copy link
Author

BastiQ commented Aug 11, 2023

Hey Peter, not sure if this is an issue with CDK. I thought it would make sense since ARM support was just recently added. Let me know where else I can report the issue. It takes some time to figure out that such a basic thing is not working, so I'm just trying to create awareness and potentially help others not to run into it. Feel free to close if the issue is not with CDK.

@peterwoodworth
Copy link
Contributor

peterwoodworth commented Aug 11, 2023

Yeah I don't see any explicit issues with the template. If you're able to test this same setup in the console to verify that it's not an issue with the service not fixing this particular case of the issue, that would be very helpful. Else, I can see what else I can do

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Aug 11, 2023
@BastiQ
Copy link
Author

BastiQ commented Aug 12, 2023

Sorry, but I don't have the time for further investigation now. I also don't feel particularly excited about fixing AWS services for them. For anyone running into the same issue, just use multi-line commands. E.g.:

from aws_cdk import aws_codebuild as codebuild
# ...
example_codebuild_project = codebuild.Project(
    self,
    "EFSPackageInstallerProject",
    project_name="EFSPackageInstallerProject",
    description="Installs Python packages on EFS for use in model serving Lambda",
    build_spec=codebuild.BuildSpec.from_object(
        {
            "version": "0.2",
            "phases": {
                "build": {
                    "commands": [
                        """echo "Using an example array";
                        my_array=("first" "second" "third" "fourth");
                        for item in "${my_array[@]}"; do 
                            echo "$item";
                        done""",
                    ]
                }
            },
        }
    ),
    environment=codebuild.BuildEnvironment(
        build_image=codebuild.LinuxArmBuildImage.from_docker_registry(
            f"public.ecr.aws/sam/build-python3.9:latest-arm64"
        ),
        compute_type=codebuild.ComputeType.SMALL,
        privileged=True,
    ),
)

@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 12, 2023
@peterwoodworth peterwoodworth added p2 needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. and removed p1 labels Aug 14, 2023
@peterwoodworth
Copy link
Contributor

Yeah to put it simply - if it is using the correct image after you deploy, then this is almost certainly a service issue, which unfortunately I can't help much with. I submitted a ticket internally for this (P96948151), will provide an update when one becomes available

@peterwoodworth
Copy link
Contributor

@BastiQ the service team let me know that arrays are not supported in buildspec command yet - From the team:

In order to workaround, try putting that in a script file and invoke that in buildspec, which should work.

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

@BastiQ
Copy link
Author

BastiQ commented Aug 24, 2023

Good to know, thanks for the update! Maybe something worth adding to the docs somewhere.

@peterwoodworth
Copy link
Contributor

I'll forward this feedback onto them 🙂

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. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

2 participants