Setting up GitLab on your Virtual Machine

Git services in Workspaces are now supported by Gitea which offers a more secure multi-user collaborative development environment. Gitea is available in all workspaces and you can read more about it here.

Git is a version control system used for managing and keeping track of code changes over time. To allow collaborative development and sharing of code, you also might want to use a cloud-based hosting service like GitLab that lets you manage Git repositories.

Virtual Machines host a local GitLab server. It allows multiple users to work in parallel within workspace Virtual Machines on the same repo using Git. Because the local GitLab server can only be accessed from workspace Virtual Machines, the users are not able to send data out of the local GitLab.

Before you can start using GitLab in your Virtual Machine, you have to set up an SSH key following the instructions detailed below.

Instructions for Linux

Instructions for Windows

gitlab_scr2.png

Setting up GitLab on a Linux Virtual Machine

1. Generate SSH keys

Start a desktop session on a Linux Virtual Machine and open a terminal. Generate an SSH key pair:

  • Replace your.email@example.org with the email you used to register to the DRE
  • Replace id_youruser with a username that would identify your individual key
ssh-keygen -t ed25519 -C "your.email@example.org" -f ~/.ssh/id_youruser

It will also ask you to specify a passphrase, you can just hit 'Enter' to skip it.

ssh_keys.gif

This will generate a pair of SSH keys as files:

  • ~/.ssh/id_youruser - the private key (don’t share!)
  • ~/.ssh/id_youruser.pub - the public key (to be shared)

2. Add the key to your GitLab account

Inside the Virtual Machine, navigate to the GitLab server. You can do this by copying the URL of the current workspace and replacing the workspace name with gitlab. For example, your workspace URL is https://workspace-name.region.environment.your-organisation.org. So, to access the GitLab server, you would use https://gitlab.region.environment.your-organisation.org.

Log in to GitLab with the DRE credentials. Then in the top right corner, select your avatar and click 'Settings'. From the left sidebar, select 'SSH Keys'.

sign_in.png

Back in the terminal, copy the contents of your public key:

cat ~/.ssh/id_youruser.pub

Then in the GitLab Key box, paste the contents of your public key. If you manually copied the key, make sure you copy the entire key, which starts with ssh-ed25519, and ends with your email address. Then click ‘Add key’.

add_key.gif

3. Configure git to use the SSH key

Back in the terminal, configure git with your details and the SSH key:

git config --global user.name "Your name"
git config --global user.email your.email@example.org
git config --global core.sshCommand "ssh -i ~/.ssh/id_youruser -F /dev/null"

Do not forget to replace the strings with your name, email, and the path to your private key in the ~/.ssh/id_youruser line.

4. Test the setup

Create a project in GitLab, and then clone it using SSH:

clone_ssh.png

git clone git@gitlab.region.environment.your-organisation.org:user.name/repository_name.git

Once the project has been cloned, try modifying the code and pushing it to the GitLab repository:

git add --all
git commit -m "Testing GitLab"
git push origin master

You can verify that the repository was updated on the web version of GitLab.

Setting up GitLab on a Windows Virtual Machine

1. Generate SSH keys

Go into a Windows Virtual Machine and open the command prompt. Generate an SSH key pair:

  • Replace your.email@example.org with the email you used to register to the DRE
  • Replace id_youruser with a username that would identify your individual key
ssh-keygen -t ed25519 -C "your.email@example.org" -f /c/Users/workspace/.ssh/id_youruser

It will also ask you to specify a passphrase, you can just hit 'Enter' to skip it.

ssh_windows.gif

This will generate a pair of SSH keys as files:

  • /c/Users/workspace/.ssh/id_youruser - the private key (don’t share!)
  • /c/Users/workspace/.ssh/id_youruser.pub - the public key (to be shared)

2. Add the key to your GitLab account

Inside the VM, navigate to the GitLab server. You can do this by copying the URL of the current workspace and replacing the workspace name with gitlab. For example, your workspace URL is https://workspace-name.region.environment.your-organisation.org. So, to access the GitLab server, you would use https://gitlab.region.environment.your-organisation.org.

Log in to GitLab with the DRE credentials. Then in the top right corner, select your avatar and click 'Settings'. From the left sidebar, select 'SSH Keys'.

sign_in.png

Back in the command prompt, copy the contents of your public key:

cat /c/Users/workspace/.ssh/id_youruser.pub

Then in the GitLab Key box, paste the contents of your public key. If you manually copied the key, make sure you copy the entire key, which starts with ssh-ed25519, and ends with your email address. Then click ‘Add key’.

add_key_w2.gif

3. Configure git to use the SSH key

Back in the terminal, configure git with your details and the SSH key:

git config --global user.name "Your name"
git config --global user.email your.email@example.org
git config --global core.sshCommand "ssh -i /c/Users/workspace/.ssh/id_youruser -F /dev/null"

Do not forget to replace the strings with your name, email, and the path to your private key in the /c/Users/workspace/.ssh/id_youruser line.

4. Test the setup

Create a project in GitLab, and then clone it using SSH:

clone_ssh.png

git clone git@gitlab.region.environment.your-organisation.org:user.name/repository_name.git

Once the project has been cloned, try modifying the code and pushing it to the GitLab repository:

git add --all
git commit -m "Testing GitLab"
git push origin master

You can verify that the repository was updated on the web version of GitLab.

Updated on September 8, 2023

Was this article helpful?