Integrating with GitLab

In this guide, we’ll link a private GitLab repository to a Valohai project using a deploy key.

1. Requirements

For this tutorial you will need:

  • a private GitLab repository
  • a Valohai project which to link the repository
  • a tool that generates SSH keys, this guide uses ssh-keygen
  • access from Valohai (IP address: through your firewall to your private GitLab

2. Generate an SSH key pair

$ ssh-keygen -t rsa -b 4096 -N '' -f my-project-deploy-key

The ssh-keygen above generates two files:

  • is the public key you add to GitLab.
  • my-project-deploy-key is the private key you add to Valohai.

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.

3. Add the public key to GitLab

Find 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.

3.1 Go to deploy key settings

GitLab - route to the deploy key creation page

Navigate to the add deploy key page in your 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.

3.2 Add new deploy key

GitLab - deploy public key setup example

Copy and paste the contents of into the Key field.

Give the deploy key an identifying Title such as Valohai.

Valohai doesn’t require write access, make sure that is off.

4. Add the private key to Valohai

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.

4.1 Go to repository settings

Valohai - route to repository settings

Navigate to the repository settings in your Valohai Project through Settings > Repository.

4.2 Copy the repository SSH URL

GitLab - where to find repository SSH URL

To make sure you get the correct repository URL, open GitLab in another tab. On GitLab, navigate to Project Details page and press Clone.

Make sure you select the Clone with SSH field.

Then copy the field contents, something like<owner>/<repository>.git

4.3 Configure repository settings

Valohai - repository configuration example

Paste the SSH URL (<owner>/<repository>.git) into the URL field.

Change Fetch reference if applicable to your use-case. It’s essentially the branch Valohai uses. master is the most commonly used fetch reference.

Copy and paste the contents of my-project-deploy-key file (without the .pub extension) into the SSH private key field.

4.4 Save the repository settings

Valohai - screen after saving repository settings

After you click Save, the repository links to the project and automatically fetches your code.

On errors, double check the fields or contact support through Intercom.

4.5 Update project as necessary

Valohai - highlighted Fetch repository button

After you add new commits to your GitLab repository, remember to press the Fetch repository to update the code in Valohai.

5. Results

We linked a private GitLab repository to a Valohai project using GitLab deploy keys.