In this guide, we will connect a private GitHub repository to a Valohai project using a deploy key.
Prerequisite:
- A private GitHub repository
- A Valohai project
- A tool that generates SSH keys. You can either use Valohai's UI for this or
ssh-keygen
- You’re familiar with Git for Data Science: What every data scientist should know about Git
Generate an SSH key pair
Easiest way to generate SSH key pair is to click the Generate new SSH key button in the Valohai UI. Go to app.valohai.com and navigate to the repository settings in your Valohai Project through Settings > Repository.
This will generate you a new SSH key pair and you can download/copy both the Public (.pub) and Private key (.pem).
If you want you can also use ssh-keygen
to 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.pub
is the public key you add to GitHub.my-project-deploy-key
is 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 GitHub
Find the valohai-public_xxx.pub / my-project-deploy-key.pub
file you generated in the last section. It should contain one line that starts with ssh-rsa AAAA...
. This line is the public key that we will be adding to GitHub.
Now go to your GitHub repository and navigate to the add deploy key to page through Settings > Deploy keys > Add deploy key.
Add new deploy key
- Copy and paste the contents of
.pub
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.
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 GitHub in another tab. On Github, 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 git@github.com:<owner>/<repository>.git
Next, paste the SSH URL (git@github.com:<owner>/<repository>.git
) into the URL field.
On your local machine, find the private key file(valohai-public_xxx.pem
or my-project-deploy-key
without the .pub
extension) we generated before. It should contain multiple lines starting with -----BEGIN RSA PRIVATE KEY-----
or something similar. Copy and paste the contents of .pem file or my-project-deploy-key
into the SSH private key field in the Valohai UI.
After you click Save, Valohai links the GitHub repository to the project and automatically fetches your code.
After you add new commits to your GitHub repository, remember to press the Fetch repository to update the code in Valohai.
Comments
0 comments
Please sign in to leave a comment.