In Valohai, each project is typically linked to a single Git repository. However, there are situations where you may need to access files from another repository without merging the two projects. Here’s how you can achieve this and a brief overview of Git submodules.
What Are Git Submodules?
- Git submodules enable you to include one Git repository as a subdirectory within another Git repository. This allows you to clone and maintain a separate repository within your project while keeping their commits separate.
- Submodules may not always be the best choice, so you can also clone another Git repository directly into your Valohai execution.
Adding a Git Submodule
- Ensure the submodule’s URL follows this format:
git@github.com:<username>/<repository>.git
. - To add a submodule, use the following commands:
git submodule add git@mygitprovider.com:<username>/<repository>.git
git add .
git commit -m "Added submodule"
git push
Configuring Access for Valohai
- Valohai needs access to both the main repository and any submodule repositories.
- You can only provide one SSH key in Valohai project settings, so ensure it has access to all required repositories.
GitHub
GitHub deploy keys can be used in only one project at a time, meaning you can’t use the same key in both your main and submodule repositories.
To enable Valohai to fetch a repository with submodules: 1. Generate and add a new SSH key to your GitHub profile. 2. In your Valohai project settings, link the main repository using the newly generated SSH key.
Now, Valohai can fetch the main repository and its submodules.
GitLab
GitLab allows you to create a deploy key and use it across multiple repositories.
To set this up:
- Follow the GitLab guide in our private repositories section to create a deploy key for your main repository if you haven’t already.
- In GitLab, navigate to the submodule project’s repository.
- Go to “Project” -> “Settings” -> “Repository” -> “Deploy keys.”
- Open the “Privately accessible deploy keys” tab.
- Enable the key you’re using in your main repository.
Now, Valohai can fetch both the main repository and its submodules.
Bitbucket
To achieve this with Bitbucket:
- Follow the Bitbucket guide in our private repositories section to create a deploy key for your main repository.
- Add the same deploy key to the other repository used as a submodule.
Now, Valohai can fetch both the main repository and its submodules from Bitbucket.