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

(cdk-pipelines): Add environment_variables to SimpleSynthAction breakes pipelines behavior #11877

Closed
lucasam opened this issue Dec 4, 2020 · 3 comments
Assignees
Labels
@aws-cdk/pipelines CDK Pipelines library bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@lucasam
Copy link

lucasam commented Dec 4, 2020

Class SimpleSynthAction in python changes the behavior when we add environment_variables parameter.

Reproduction Steps

source_artifact = codepipeline.Artifact()
cloud_assembly_artifact = codepipeline.Artifact()

repo = codecommit.Repository.from_repository_name(self, 'repo_ref', 'repo_name')

code_action = cpactions.CodeCommitSourceAction(
            action_name='SourceCode',
            output=source_artifact,
            repository=repo,
            branch='main',
            trigger=cpactions.CodeCommitTrigger.EVENTS
        )
synth_action = pipelines.SimpleSynthAction(
            source_artifact=source_artifact,


            # The addition of this parameter makes the behavior to change
            environment_variables={
                'DOCKER_PASSWORD': aws_codebuild.BuildEnvironmentVariable(
                    value='DOCKERHUB_PASSWORD',
                    type=aws_codebuild.BuildEnvironmentVariableType.SECRETS_MANAGER)
            },
            environment={
                'privileged': True
            },
            cloud_assembly_artifact=cloud_assembly_artifact,
            install_commands=[
                'npm install -g aws-cdk',
                'pip install -r requirements.txt',
                'docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD'
            ],
            synth_command='cdk synth'
        )

pipeline = pipelines.CdkPipeline(self, 'MyCrazyPipeline',
                                         cloud_assembly_artifact=cloud_assembly_artifact,
                                         pipeline_name='MyCrazyPipeline',
                                         source_action=code_action,
                                         synth_action=synth_action)

When i add the environment_variables parameter to SimpleSynthAction the build behavior changes.

Before add environment_variables param


[Container] 2020/12/04 14:30:39 Entering phase INSTALL
--
[Container] 2020/12/04 14:30:39 Phase complete: INSTALL State: SUCCEEDED
[Container] 2020/12/04 14:30:39 Phase context status code:  Message:
[Container] 2020/12/04 14:30:39 Entering phase PRE_BUILD
[Container] 2020/12/04 14:30:39 Running command npm install -g aws-cdk
/usr/local/bin/cdk -> /usr/local/lib/node_modules/aws-cdk/bin/cdk
+ aws-cdk@1.76.0
added 190 packages from 186 contributors in 6.056s
....
[Container] 2020/12/04 14:30:50 Running command pip install -r requirements.txt
Collecting attrs==20.3.0
--
Downloading https://files.pythonhosted.org/packages/c3/aa/cb45262569fcc047bf070b5de61813724d6726db83259222cd7b4c79821a/attrs-20.3.0-py2.py3-none-any.whl (49kB)
...

After the addition of environment_variables param

[Container] 2020/12/04 14:36:52 Waiting for agent ping
[Container] 2020/12/04 14:36:54 Waiting for DOWNLOAD_SOURCE
[Container] 2020/12/04 14:36:55 Phase is DOWNLOAD_SOURCE
[Container] 2020/12/04 14:36:55 CODEBUILD_SRC_DIR=/codebuild/output/src650326947/src
[Container] 2020/12/04 14:36:55 YAML location is /codebuild/readonly/buildspec.yml
[Container] 2020/12/04 14:36:55 Processing environment variables

Meaning it is not using the provided install_commands and default SimpleSynthAction behavior, but instead it is failing over to the default behavior of looking for buildspec.yaml

Environment

  • CDK CLI Version : aws-cdk@1.76.0
  • Node.js Version: v12.18.0
  • OS : Ubuntu
  • Language (Version): Python (3.8)

This is 🐛 Bug Report

@lucasam lucasam added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 4, 2020
@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Dec 4, 2020
@lucasam
Copy link
Author

lucasam commented Dec 4, 2020

Found a workaround to add environment_variables inside environment instead of directly into SimpleSynthAction

synth_action = pipelines.SimpleSynthAction(
            source_artifact=source_artifact,
            environment={
                'privileged': True,
                'environment_variables': {
                   'DOCKER_PASSWORD': aws_codebuild.BuildEnvironmentVariable(
                       value='DOCKERHUB_PASSWORD',
                      type=aws_codebuild.BuildEnvironmentVariableType.SECRETS_MANAGER)
                  }
            },
            cloud_assembly_artifact=cloud_assembly_artifact,
            install_commands=[
                'npm install -g aws-cdk',
                'pip install -r requirements.txt',
                'docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD'
            ],
            synth_command='cdk synth'
        )

Documentation points that both structures accept this param. Maybe just fix documentation might work

rix0rrr added a commit that referenced this issue Dec 7, 2020
Make sure that environment variables combine correctly and a BuildSpec
is still rendered.

Relates to #11877.
@rix0rrr
Copy link
Contributor

rix0rrr commented Dec 7, 2020

I wrote a test to make sure but it seems to work fine: #11906

Can you paste the relevant output of cdk.out/PipelineStack.template.json with the "broken" environment variables config?

@rix0rrr rix0rrr added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 7, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Dec 7, 2020
mergify bot pushed a commit that referenced this issue Dec 8, 2020
…ly (#11906)

Make sure that environment variables combine correctly and a BuildSpec
is still rendered.

Relates to #11877.


----

*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

This issue has not received a response in a while. 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 closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 15, 2020
flochaz pushed a commit to flochaz/aws-cdk that referenced this issue Jan 5, 2021
…ly (aws#11906)

Make sure that environment variables combine correctly and a BuildSpec
is still rendered.

Relates to aws#11877.


----

*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/pipelines CDK Pipelines library bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants