Solvedcloud builders Fetch repositories with submodules
✔️Accepted Answer
You can use the source repositories of gcloud instead of github. Read my comment in the #44
I perform a step in my cloudbuild.yaml which rename the repositories :
- id: renameGitHubUrl
name: debian
args:
- sed
- -i
- 's#git@github.com:___GitHubId___/\(.*\)\.git#https://source.developers.google.com/p/___GCLOUD_PROJECT_ID___/r/github-___GitHubId___-\1#g'
- .gitmodules
As soon as your private github repository are well named in gcloud source repositories, it will be correct. After this step you can submodule init and update.
Other Answers:
For anyone coming across this: An easier way than creating deploy keys, encrypting them with kms and adding multiple additional steps to your pipeline is to simply have a Google mirror the submodule as well. Then run two commands to temporarily change the submodule config on disk to point to the Google mirror before updating the submodule. Like so:
# Update submodules
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
git config -f .git/config submodule.one.url https://source.developers.google.com/p/[project_id]/r/[repo_one]
git config -f .gitmodules submodule.one.url https://source.developers.google.com/p/[project_id]/r/[repo_one]
git submodule init
git submodule update
For what it's worth, pst's comment saved the day. THANKS!
That said, I must admit I had to poke around to make sense of it, so perhaps these more detailed steps will save the next person time...
To mirror the submodule, go to Cloud Source Repositories. That gave me a repo like:
https://source.cloud.google.com/[my-project]/github_[my-sub-repo-name]
In order for Cloud Build to gain access, I needed to rewrite like:
https://source.developers.google.com/p/[my-project]/r/github_[my-sub-repo-name]
With that new url, I followed the example above... but I did not need to update .git/config
, only .gitmodules
.
So:
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
git config -f .gitmodules submodule.[my-sub-repo-name].url https://source.developers.google.com/p/[my-project]/r/github_[my-sub-repo-name]
git submodule init
git submodule update
I added this to my cloudbuild.yaml
as the first step. Cloud Build then had no issues cloning the submodule during the build.
Your mileage may vary with a different setup. I do hope Google adds proper support to do this automatically in the near future. What a pain.
It is unclear how repositories with submodules can be built.
This is what the build currently does:
It is not clear if it is possible to use the
cloud-builders/git
container somehow to fetch all of the repositories. Is the workspace cleared between each buildstep? What if they are executed in parallel?