In this guide, we’ll link a private GitLab repository to a Valohai project using a deploy key.
- A private Gitlab repository
- A Valohai project
- A tool that generates SSH keys. This guide uses
- You’re familiar with Git for Data Science: What every data scientist should know about Git
Generate an SSH key pair
ssh-keygento create a new SSH key pair.
ssh-keygen -t rsa -b 4096 -f my-project-deploy-key
This will generate two files:
my-project-deploy-key.pubis the public key you add to GitLab.
my-project-deploy-keyis the private key you add to Valohai.
Don’t include the keys in your version control
You should not include these keys in the version control. Anybody that gains access to the
my-project-deploy-key file contents will have read access to your repository, so use appropriate caution.
Add the public key to GitLab
my-project-deploy-key.pub the file we generated in the last section, and it should contain one line that starts with
ssh-rsa AAAA.... This line is the public key that we’ll be adding to GitLab.
Navigate to the add deploy key page in your GitLab repository at Settings > Repository > Deploy Keys.
If you can’t see this Deploy Keys menu, you are most likely lacking the permissions to add deploy keys so contact your GitLab admins.
- Copy and paste the contents of
my-project-deploy-key.pubinto the Key field.
- Give the deploy key an identifying Title such as Valohai.
- Valohai doesn’t require write access, make sure that is off.
Add the private key to Valohai
Go to app.valohai.com and navigate to the repository settings in your Valohai Project through Settings > Repository.
To make sure you get the correct repository URL, open GitLab in another tab. On GitLab, navigate to Code page and press Clone or download.
Make sure you have Clone with SSH active on the popup window. If it reads Clone with HTTPS, click the Use SSH button next to the text.
Then copy the text field with
Next, paste the SSH URL (
git@GitLab.com:<owner>/<repository>.git into the URL field.
On your local machine, find the
my-project-deploy-key file (without the
.pub extension) we generated before. It should contain multiple lines starting with
-----BEGIN RSA PRIVATE KEY-----or something similar. The contents of this file are the private key we’ll be adding to Valohai.
Copy and paste the contents of
my-project-deploy-key into the
SSH private key field.
After you click Save, Valohai links the GitLab repository to the project and automatically fetches your code.
After you add new commits to your GitLab repository, remember to press the Fetch repository to update the code in Valohai.
Please sign in to leave a comment.