How to integrate cloudbuild (GCP) with CodeCommit - google-cloud-platform

I have my source code in code commit and my new client is with GCP. They wanted to connect code-commit from google cloud-build, is there any option for that ?

Given the fact that GCP and AWS are competitor cloud providers I would say that you will not find a way to trigger Google Cloud Build from AWS CodeCommit, which is what I believe you mean with "integrate" both products.
What I would do in your scenario is replicate you CodeCommit repository in it's equivalent in GCP, which is Google Cloud Source Repositories. You can find a tutorial for how to setup
Build Triggers from Cloud Source Repositories in this documentation. Another option is pushing a container ready to be deployed into Cloud Registry and deploying that instead, you can follow these steps for that.

Related

Mirror Bitbucket Server repo in Bitbucket Cloud?

As part of some infrastructure code I am writing with Terraform, I am trying to deploy a Google cloud function. However, in the terraform code for the function, it is mandatory to specify a Cloud Source Repositories repo that the function will pull the application code from, using the "source_repository" and "url" fields.
Currently, what I had set up in my sandbox, was a mirrored connection from cloud source repositories to my own bitbucket cloud repository where the application code was being commmited to, however once I tried to copy this to our company's bitbucket server account, I have realised there is no option to simply mirror a bitbucket server repository in cloud source repositories (it's only available for bitbucket cloud).
Therefore my plan was to mirror a bitbucket server repo, into a bitbucket cloud repo, into a Google Cloud Source Repository which my Cloud Function could pull the code from. Has anyone experimented with this - I already tried but there doesn't seem to be an option for a web hook to mirror it.
Any help appreciated. I have attached a diagram that might help explain the solution i am wanting. The part in green is what I want to add Bitbucket Mirror Image Architecture Diagram

Can Google Cloud Repositories be shared cross projects?

I am trying to set up a continous developemnt system for creating an app and I would like to know if this is idea is feasible within GCP:
Project A - Hosts Cloud Source Repository
Project B - Cloud Run for the app
On project B, I have the Cloud Run option of 'Continously deploy new revisions from a source repository' which I would like to point to the CSR from project A.
My question is, Can CSR be shared cross-project or do I need to go for GitHub or BitBucket to be able to share code between projects?
You can access y our Cloud Source Repository from any project as long as your account (service or user) has the permission to access it.
However, you can't configure Cloud Build triggers on Cloud Source Repository that is in another project (the continuous deployment on Cloud Run configure a Cloud Build trigger behind the scene for you. It's simply a shortcut).
But you can also create a Cloud Build Trigger in your Cloud Source Repository project and grant the permission to the Cloud Build service account to deploy the Cloud Run service to the target project.
Because the continuous deployment on Cloud Run is a shortcut to configure Cloud Build trigger and deployment pipeline, you can do the same manually (longer and required more skill/experience with GCP), but it's not impossible!!

Mirror Bitbucket Repositories to Google Cloud Source Repositories

I am trying to build CICD using cloud build in GCP. As a part of that, I am trying to mirror the repositories from Bitbucket into CSR. But I am not able to mirror the repositories. I am able to view the repositories that are present in the Bitbucket after authorizing to bitbucket from GCP.
https://cloud.google.com/build/docs/automating-builds/create-manage-triggers
https://cloud.google.com/source-repositories/docs/mirroring-a-bitbucket-repository
IAM Permissions:
I have Admin access for Source Repositories in GCP along with Cloud Build Service Account.
I have Admin access for the bitbucket repository and the workspace. The workspace in bitbucket is private.
Per the Cloud Source Repositories
If you are mirroring your Bitbucket repository to Cloud Source
Repositories to integrate with Cloud Build and do not need any other
Cloud Source Repositories features, follow the Cloud Build
instructions on building repositories from Bitbucket Cloud instead.
The referenced guide, Building repositories from Bitbucket Cloud, mentions that you need to create an SSH key in order to authenticate your connection to Bitbucket Cloud.
Bitbucket documenentation also confirms that the connection fails if there is no SSH key.
I have learned that the repositories in the Bitbucket are in Private Workspace and are IP restricted. So adding a set of Google Cloud's Public IPs solved this issue.

Problem mirroring Bitbucket repo to GCP Cloud Source Repo

I'm attempting to setup CICD for a GCP Cloud Function and App-Engine deployment. The repo is in Bitbucket and I am following the instructions found here to create a mirror between my Bitbucket repo and a GCP Cloud Source repo.
Using the GCP Cloud Source "Connect external repository" UI I am able to select my GCP project, select Bitbucket as the Git provider, connect to Bitbucket using my credentials (I am admin on the Bitbucket repo), and select the desired Bitbucket repo. Then when I click the "Connect selected repository" I get about a 30s delay and finally a simple "Failed to connect repositories" error message with no further explanation as to why. GCP logging shows nothing.
Any ideas would be appreciated.
Thanks
Ensure that you have enabled the source repos API. Retrospectively I guess this is obvious, because the Bitbucket webhooks need to call out to Google's API to announce when changes occur on the repo.
The GCP API is called Cloud Source Repositories API, and the service name is sourcerepo.googleapis.com
https://console.cloud.google.com/apis/api/sourcerepo.googleapis.com

Integrating Github Enterprise with AWS Codepipeline

I have a repository in a [company hosted] GitHub enterprise site that I need to integrate within a CI/CD pipeline in AWS using the CodePipeline service. The CodePipeline service then will connect with a Jenkins Service running in an EC2 instance. I am following this AWS documentation to do this.
Note that this is an enterprise GitHub repo and not hosted on GitHub.com.
I am unable to connect to the GitHub Enterprise site in the "Create a pipeline" wizard. Selecting GitHub as a source only lets me connect to GitHub.com, and not to my organization's enterprise site.
How do I connect to the enterprise GitHub site so that I can add the repo as a source for my codepipeline?
UPDATE: An integration was finally released for github enterprise to work with AWS Codepipeline. Please see this answer by Pedreiro
As Sid Malani said in the comments, there's no straightforward or direct way to use a privately hosted GitHub Enterprise Repository in AWS CodePipeline.
One way would be to use CodeBuild, which allows to add custom github repositories which can then be used in CodePipeline. This, however, should only be considered as a stop-gap solution.
Thank you Sid Malani for the alternative strategy
I doubt AWS will ship this feature anytime soon (hopefully I eat my words) since the workaround is well-documented and works fine. The gist of it can be found here, which I'll summarize as follows:
Create a CodeBuild project (which can take GitHub Enterprise as a source) which essentially just listens to a push event (webhook) of your development or master branch and outputs a .zip file of the source-code into an S3 bucket.
Use the S3 bucket as the source of your CodePipeline.
The official integration was finally released.
https://aws.amazon.com/about-aws/whats-new/2020/09/aws-codepipeline-supports-github-enterprise-server
Here is the documentation:
https://docs.aws.amazon.com/codepipeline/latest/userguide/connections-ghes.html
There is a way to integrate 3rd party Git repos with AWS CodePipeline. AWS suggested the following process. It used S3 buckets and API Gateways and Lambdas to connected Github enterprise repos to CodePipeline. It's not ideal but it can work.
Unofficial: I've heard CodePipeline support for Github Enterprise will be out second half of 2019.