In this tutorial I will learn you how to create and use submodules in Odoo.sh. In this example I will create a public submodule and a private submodule and I will link them to the Odoo.sh project.
1. Introduction to submodules
Tip: If you haven’t made an Odoo.sh project yet you can follow my tutorial here.
So, what exactly is a submodule? A submodule is a link from one Github repository to another repository. You can see it as a virtual pointer to a specific commit in time of the remote repository.
For Odoo.sh there are two major differences. You have public submodules and private submodules. Public repositories are those that are publicly available (for example https://github.com/odoo/odoo). Private repositories are the repositories that are not publicly available. Usually you have private repositories when you work for a company and when you manage customer code.
There is a big difference in using public or private submodules on Odoo.sh though. When you have a public repository you can easily add the submodule and it will work. For a private repository you will need to generate a deploy key on Odoo.sh and then add it on the remote Github repository.
1.1 Why use submodules?
Now we know what a submodule is but the question is why would you use a submodule? Submodules are very handy to use if you want to include third party apps in your Odoo.sh tests. The only other way to get this code available in your Odoo.sh builds is to add all this third party code in your own repository. But what if the third party developer has made a lot of changes, fixes or improvements? If you don’t use submodules you will constantly need to download the remote apps, add them to your own repository and keep track of all those changes. This is the true power of submodules. Now let us first link a public repository to the Odoo.sh project in chapter 2. In chapter 3 I will learn you how to add a private repository as a submodule.
2. Public repositories
Setting up public repositories is really very easy to do.
You will need to create a submodule and commit it to Github. Go to your Github repository, switch to the correct branch and add the submodule from the command line:
git submodule -b 11.0 add email@example.com:oca/hr.git
git add -A && git commit -m "[ADD] submodule: add OCA/hr as submodule"
This new commit will trigger a new Odoo.sh build. After this build is ready you will see that the modules from the OCA/hr repository are available on this instance:
Great job! This is all you need for a public repository. If you also have a private repository and want to add it then continue to the next chapter.
3. Private repositories
Alright now let us configure the use of a private submodule! Go back to your Odoo.sh project to the settings tab and add the link to your private repository (firstname.lastname@example.org:youruser/repository.git). In your repository you could now make a commit to add the repository as a submodule. For a private repository however you have some extra work. You have to copy the generated key from the Odoo.sh project and add it on Github. First copy the key:
Now go to the repository where you’ve linked to (so the submodule), go to the settings tab, open “Deploy keys” and add your own key here by clicking on “Deploy key”:
Now add the key in the next screen and click on “Add key”:
After doing this Odoo.sh can find the private repository and can access all the data it needs. The final thing you need to do is to add the submodule from the command line, commit it and push it to Github:
git submodule -b 11.0 add email@example.com:account/private_subrepo.git
git add -A && git commit -m "[ADD] submodule: add private repository as submodule"
This new commit will trigger a new Odoo.sh build. After this build is ready you will see that the modules from your other private repository are available on this instance.
Using submodules in combination with Odoo.sh is very powerfull and handy to use. Setting it up in the beginning might take some time and you can make some mistakes but in the long run it will save you a load of time and redundant code. As a result it’ll improve your testing a lot as all your custom code will be automatically tested.
If you can use submodules and want to test your deployments on Odoo.sh then submodules are the way to go.
Has this tutorial helped you, do you have any feedback or questions? Post away!
4 thoughts on “Configuring submodules on Odoo.sh”
How can you update modules that you add as submodules in odoo.sh ?
You can do this with the following command:
git submodule update –remote
this is not working right:
git submodule update –remote
fatal: Not a git repository (or any of the parent directories): .git
is there any repository I need to go in ?
You’re not doing this in the correct folder, you’re doing this in a folder that is not on Github. You should go into your Github folder and execute the command there.