Google Cloud Build - Cant Update Submodules - google-cloud-build

I configured google cloud build (GCB) to trigger a build on one of my repositories in Github. This repository requires another git repository in order to be built. This other repository is configured using a git submodule.
I search and at the moment it looks like GCB do not support submodules. So I am trying to run git submodule update --init manually on the source code that GCB downloaded, but there is not .gitdirectory on it and the command fails.
What am I missing here?
I am using this issue as reference: https://github.com/GoogleCloudPlatform/cloud-builders/issues/435

If trigger your build using github it will not work because of the lack of the .git folder. In order for it to work, all repositories need to be mirrored by Cloud Source Repositories. Then, the submodule can be updated like this:
- 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
Ref: https://github.com/GoogleCloudPlatform/cloud-builders/issues/26

Sometimes you get an error with GIT_DISCOVERY_ACROSS_FILESYSTEM or the missing .git folder. The following worked for me:
- id: git-submodule
name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
env: ['GIT_DISCOVERY_ACROSS_FILESYSTEM=1']
args:
- '-c'
- |
git init
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

For someone like me, who is using submodules in Bitbucket and ran into similar problems with Cloud Build: As soon as you mirror your repositories into the Cloud Source Repository, the submodule URLs are not allowed to have the .git extension.
For example for the main repository https://source.cloud.google.com/Project_ID/main_repo and submodules a, b in the "submodules" folder the .gitmodules configuration might look similar to this
[submodule "submodules/a"]
path = submodules/a
url = ../a
[submodule "submodules/b"]
path = submodules/b
url = ../b
Previously, I used for URLs ../a.git and ../b.git which works fine in Bitbucket but not in Cloud Source Repository.

Related

Why do am i getting error 404 on my sub module symlink found on my git repo?

I'm currently having an issue with my git submodule. I've created a git submodule in my cloned project folder and it appears right on my repo. But when I click on the symlink, it gives me Error 404 page not found. I am VS Code and Windows 8 x64. Thanks a lot for your help! Below is what is written in the .gitmodules
[submodule "themes/casper-two"]
path = themes/casper-two
url = "https://github.com/eueung/hugo-casper-two"
I cannot find the caa182b commit in the hugo-casper-two repository, so I believe you need to update the submodule to the latest commit available. To do this, run the following command from your project directory:
git submodule foreach git pull origin master
This command will update every submodule in your project and pull the latest commit from their master branch.
Remember to commit your own repository afterwards.
git commit -am "Pulled down updates to submodules"

Is there a DRY way to "git submodule add git#url" with ansible?

Straight forward question. MY playbook creates a new project on gitlab and then It clones it on all the host. Now I want for one host to enter the project and create a .gitmodules files with "git submodule add git#some-url.git" only once.
the git module for ansible only has track_submodules parameter but that updates the submodule which will be useful later. And I wouldn't like using the shell module in this case.
Essentially I just want an automatic ansible way to create a new project with a specific submodule.
You'll need to first check if the submodule exists. You can just use the stat module to verify that the directory exists, and then only run your git submodule add ... command if the submodule directory doesn't exist. Something like:
- name: check if submodule exists
stat:
path: mysubmodule
register: mysubmodule_check
- name: add submodule
command: git submodule add {{ submodule_url }} mysubmodule
when: not mysubmodule_check.stat.exists

How to specify the submodule branch in gitlab-ci?

How to specify branch in .gitlab-ci.yml for a submodule (different repo) in gitlab-ci?
You don't. You specify it in the .gitmodules file of the project you are building.
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master
Along with #stefan's answer to this question. You also have to tell Git to only look at the specified branch for the latest commit. git submodule update seems to always fetch the latest commit regardless of the branch. Doing git submodule update --remote seems to force git to focus on the branch you specify in the .gitmodules file.
So in your .gitmodules files, as #stefen mentions:
[submodule "MyRepo"]
path = MyRepo
url = https://github.com/vendor/MyRepo.git
branch = master
Then in your GitLab .gitlab-ci.yml file, you need to specify to only look at the configured branch when setting up submodules. My file includes this before_script:
# GitLab CI provides a variable "GIT_SUBMODULE_STRATEGY" that sets up submodules automatically
# But then branch tracking doesn't work (doesn't seem to allow for specifying the --remote) flag
before_script:
- git submodule sync --recursive
- git submodule update --init --remote --recursive
According to documentation, this before_script is the same functionality as provided by GIT_SUBMODULE_STRATEGY (except that I can add the --remote flag to the before_script): https://docs.gitlab.com/ee/ci/yaml/README.html#git-submodule-strategy

Deploying Laravel workbench projects through composer

I've created several private repos that I'm working on through Laravel 4.2's workbench feature.
How do I get composer to also install/update all the git submodules in the workbench dir on the production server when it updates the vendor dir for the main project?
Why you force composer to do that ?.
I guess you have following project pattern.
Project - A that have many private repo (submodules). for eg: you can add a blog module(Individual Private repo) as submodule to the Project - A .
like
git submodule add path_to_private_repo_for_blog workbench/Vendor_folder/blog.
Once you created all the individual repo as submodule like above. then you can get update using following command.
git pull && git submodule foreach git pull origin master
so simply you can update and deploy the Project -A with following command.
git pull && git submodule foreach git pull origin master && git add -A && git commit -m 'updated pakages' && git push && envoy run update
hope it make sense..

Xcode bot: git submodules not initialized

I'm trying to set up an Xcode bot with OSX server.
After configuring the git repository and creating a bot, I run integrate.
It fails because the repository is checked out only partially. More precisely: Of the 6 submodules configured, only 3 are initialized and checked out.
didi#mac:/Library/Server/Xcode/Data/BotRuns/Cache/c5fda8f4-4d25-4d25-c18a-eb0b16a06692/source$ git submodule status
+c6e8420aec4147641fb1ca12d9f1d31bdd804e77 libs/asi-http-request (v1.7-320-gc6e8420)
-ae64a38766b42f236bb94f0e661cddb829f9ac43 libs/kraken
-7da02b323636bbaa0bbbf5b4eb229fcc07b1e14a libs/route-me
152f9ee5576e710705a49032253d7d5af5366f9c libs/routing (152f9ee)
347aaf74fe0c6388785095efdbf6397851514b7f libs/rtlabel (1.0-32-g347aaf7)
-562cf6b1c879f03546f5184e012cea15c4f159db libs/skmaps
(- means not initialized)
Looking at the bot log, it seems to just ignore the missing submodules in the submodule initialize part:
...
Checking connectivity... done
Submodule 'libs/asi-http-request' (https://github.com/BikeCityGuide/asi-http-request.git) registered for path 'libs/asi-http-request'
Submodule 'libs/routing' (ssh://mac_ci#rooty.bikecityguide.org/var/repos/librouting.git) registered for path 'libs/routing'
Submodule 'libs/rtlabel' (https://github.com/BikeCityGuide/RTLabel.git) registered for path 'libs/rtlabel'
Cloning into 'libs/asi-http-request'...
...
No error message here or anywhere else. No single mention of e.g. "kraken" (name of a missing submodule) anywhere in the logs.
When checking out manually (clone, submodule init, submodule update), all submodules are initialized.
.gitmodules looks like this:
$ cat .gitmodules
[submodule "libs/asi-http-request"]
path = libs/asi-http-request
url = https://github.com/BikeCityGuide/asi-http-request.git
[submodule "libs/rtlabel"]
path = libs/rtlabel
url = https://github.com/BikeCityGuide/RTLabel.git
[submodule "libs/routing"]
path = libs/routing
url = ../librouting.git
[submodule "libs/kraken"]
path = libs/kraken
url = ../kraken_ios.git
[submodule "libs/route-me"]
path = libs/route-me
url = ../route-me.git
[submodule "libs/skmaps"]
path = libs/skmaps
url = ../skmaps.git
The base repository and the 4 submodule repositories referenced with relative URL all need ssh authentication. The user set up in OSX server has access to all of them.
The log of the bot contains no trace of trying to pull the missing submodules.
I can manually fix the local repository, but I'd like not to have the same issue again with new projects and new submodules added.
git version 1.8.4.2
I'm out of ideas.
On Xcode 6.1.1 and OS X Server 4.0, it looks like they fixed the submodules with detached HEAD issue, but there are still some bugs. One of my project has one its submodules being completely ignored by Xcode Server so the app fails to build:
$ git submodule
8a88bc41c9dc0f57c921d82bc4e7b93e1c4cbf7a InAppStore (heads/master)
e4203f9f61d2546868c1274da5c7a0c56b87a737 Libraries (heads/master) <--- IGNORED
01902f255e6c3d90f0db41cb62dd2934098b98dd MixpanelTracker (heads/master)
e2bee59accd817d50dff881a42c9e9afe307226f XLFacility (1.4.1-5-ge2bee59)
The fix for me was to add a pre-integration script trigger as such:
cd "$XCS_SOURCE_DIR/{YOUR_APP_REPO_NAME_WITHOUT_DOT_GIT_SUFFIX}"
git submodule update --init --recursive
At this point things were building although there were non-fatal warnings about the checkout not being clean or something like that. They went away when I changed to the bot's configuration to have "Cleaning" set to "Always".
In Xcode 9 server, submodules are not initialized if none of the files of the submodules is referenced by one of the Xcode projects in the workspace.
This may happen, for instance, when you include a header file from a submodule that is not part of your code and therefore you added it to the "headers search paths" (c/c++) instead of adding it to the project.
A possible workaround is to add at least one file from the submodule to the Xcode project. It can even be a Readme.md file.
This is easier than checking out submodules using a custom script because it relies on Xcode Server to store your GIT credentials.
Is I understand its a bug.
I had the same problems and found that there is an issue with detached submodules.
See the next article that show how to fix this issue (doesn't help on public repository)
http://ikennd.ac/blog/2013/10/xcode-bots-common-problems-and-workarounds/
Hope this helps you.

Resources