Setting up automatic updates with Git and Dino

April 29, 2019

The requirements for setting up automatic updates between Git and your Crident server is simple:

  • A secure password on dino panel that does not contain the “@” or “$” , as this will confuse the CI pipeline.
  • A dino server where you have the ability to download a backup from the Data vault.
  • An account on gitlab.
  • Git installed on your PC.

The steps to setting this up.

First of all, you will need to download a backup of your server using the Data vault on dino panel, and you should receive a .tar file which you are able to open using a tool like WinRar or 7zip. (WinRar might not work)

When you open the .tar file, you will see one file inside it which you should open and see the contents of your Garry’s mod server.

Extract these files into any folder you like, in this picture I will choose my P drive

After you’ve done this, open up the folder you extracted the contents to, in your favourite code editor/IDE. And you should be greeted with a file structure as follows:

Now, it is a good idea to add a gitignore to filter out all of the files you don’t need to keep on git.
So create a file in the root directory called “.gitignore
with the contents of:

/*
!/.gitignore
!/.gitlab-ci.yml

!/garrysmod
garrysmod/*

!garrysmod/addons
!garrysmod/cfg
!garrysmod/gamemodes
!garrysmod/lua
!garrysmod/maps
!garrysmod/resource

Now the next step before we plug this into CI, is pushing your server to gitlab so that we can get the commit hash for later configuration.

So head over to gitlab and create a new project with any name you desire, once you have created the repository, head over to your local server directory and open a command prompt in the folder (or powershell) and type the following Git commands:

If this is the first time using Git on this PC; then first run:

> git config --global user.name "Your name"
> git config --global user.email "Your email"

And now we can go ahead and push your current server files using the following commands:

> git init
> git remote add origin https://gitlab.com/USERNAME/REPOSITORY_SLUG.git
> git add .
> git commit -m "Hey this is some cool server files"
> git push -u origin master

So now that you have pushed your current server files to your Git repository, you can go and grab the commit hash for it so we can allow your Crident server to know which git version it is currently checked out on.

So head over to your Gitlab repository and append “/commits/master” to the end of the url, and you should be greeted with a page containing one commit.
Grab the commit hash using the button here pointed at below with a red arrow.

With this commit hash, head over to your Crident server and go into the File Manager, and create a file called “.git-ftp.log” in the root folder (/home/container), and put the commit hash inside it; like this.

And then click save, now we can head back to the local folder on your computer containing the server files, and create a file called “.gitlab-ci.yml”, this is what Gitlab will read when it comes to putting your files onto your Crident server

Put the contents of this file as:

stages:
  - push

push:
  stage: push
  image: debian:stable
  before_script:
    - apt-get update -y --allow-unauthenticated
    - apt-get install -y git git-ftp --allow-unauthenticated
    
    - git config git-ftp.url "sftp://$FTP_URL/$FTP_PATH"
    - git config git-ftp.user "$FTP_USER"
    - git config git-ftp.password "$FTP_PASSWORD"
  script:
   - git ftp push -v

So now your file structure should look like this:

Now before we push these new files, we have to configure a few things at Gitlab level so the CI pipeline knows where to put these files,

Go to your repository and append “/settings/ci_cd”, and open the variables tab.
Create 4 variables called:

  • FTP_URL
  • FTP_PATH
  • FTP_USER
  • FTP_PASSWORD

To get the values you need for these variables, head over to the “SFTP Details” tab in your Dino panel.

For the “FTP_URL” variable, copy the Connection Address from Dino panel from after “sftp://”, so in my case it would be “fr-gra-source03.crident.net:2022”

For the “FTP_PATH” variable, just input “/”.
NOTE: Servers deployed before October 2018 may need to use “/data” as the “FTP_PATH

For the “FTP_USER” variable, copy the Username from Dino panel.

For the “FTP_PASSWORD” variable, it is simply the password you use to login to Dino panel not your Crident client area login password.

After you’re done, your variables should look like this.

Now once you have this configured, just click the green “Save variables” button.

The next step is to head back to the command prompt you have open in your local server directory and type the following commands.

> git add .
> git commit -m "Add gitlab-ci file."
> git push

Now head over to your repository and you will see this blue icon, click it and you will watch as Gitlab automatically carries your changes across to your Crident server.

Congrats, you can now push any updates to this git repository and it will automatically push any staged changes to your Crident server, effortlessly.