aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.67k stars 3.92k forks source link

aws_codebuild/Source: Allow Gitlab source (potentially using codestar connector) #31138

Open nidal123 opened 2 months ago

nidal123 commented 2 months ago

Describe the feature

CodeBuild is supposed to now start allowing GitLab connections to be used as source input: https://aws.amazon.com/about-aws/whats-new/2024/03/aws-codebuild-gitlab-gitlab-self-managed/

However there's no way to do this with CDK code. Here is the relevant module: https://github.com/aws/aws-cdk/blob/c159e77ab34701fc6780b9501f1692fbf2366b04/packages/aws-cdk-lib/aws-codebuild/lib/source.ts

My best attempt at doing it in Python looks like this:

gitlabConnection = aws_codeconnections.CfnConnection(
    self,
    "myrepo-gitlab",
    connection_name="GitLabMyConnection",
    provider_type="GitLab")
gitlab_repo = "myCompany/path/myRepo"
buildproject = codebuild.Project(self, pipeline_name_prefix+repository_name+"CodeCommitProject",
    source=codebuild.Source.code_star_connection()  # here is where the problem lies
    connection_arn=gitlabConnection.attr_connection_arn,
    repo_string=gitlab_repo,
    branch=repository_ref), 
    project_name=pipeline_name_prefix+"-"+repository_name,
    environment=codebuild.BuildEnvironment(build_image=codebuild.LinuxBuildImage.STANDARD_6_0))

But that does not work because is expecting an ISource.

On the other hand, self mutating pipelines can take CodeStar connections as inputs. For example to see the contrast I was successfully able to use this code:

gitLabRepository ="myCompany/path/myRepo"
gitlabConnection = aws_codeconnections.CfnConnection(
      self,
      "myconnection-gitlab",
      connection_name="GitlabConnection",
      provider_type="GitLab")
pipeline_input = pipelines.CodePipelineSource.connection(
      gitLabRepository, 
      MAIN_BRANCH, 
      connection_arn=gitlabConnection.attr_connection_arn)
pipeline = pipelines.CodePipeline(self, "Pipeline",
      cross_account_keys=True,
      pipeline_name="SchemaManagementToolPipeline", 
      synth=pipelines.ShellStep("Synth",
          input=pipeline_input,
          commands=["zip -r code.zip *", "pip install -r requirements.txt", "npm install -g aws-cdk", "cdk synth"],))

In the second successful case, the CodePipeline consumes a IFileSetProducer as an input. So I am able to pass in the GitLab connection. I wish I could do something like that for CodeBuild. Maybe there's a different way to use CDK to let CodeBuild consume a GitLab connection but I don't see it anywhere.

Use Case

I want CodeBuild to consume a GitLab CodeStar connection as input source like gitHub here https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild.Source.html.

Proposed Solution

No response

Other Information

No response

Acknowledgements

CDK version used

2.152.0

Environment details (OS name and version, etc.)

CDK

pahud commented 2 months ago

Yes we should implement something like GitLabSource class that extends CommonGithubSource.

Making this a p2 and we welcome 👍 to help us prioritize. Any PRs are welcome and appreciated as always.

suhas38222 commented 2 months ago

Hi @pahud,

If this issue is not picked up by the team, I would like to work on it.

Suhas Jangoan