GitLab Runners and Go

This lesson will briefly present the CI/CD systems of GitLab and GitHub, starting with GitLab Runners, which can be helpful for automating package development and deployment.

When developing Go packages and documentation, we want to be able to test the results and find bugs as quickly as possible. When everything works as expected, we might want to publish our results to the world automatically without spending more time on this. One of the best solutions for this is using a CI/CD system for automating tasks. This lesson will briefly illustrate the use of GitLab Runners for automating Go projects.

Note: In order to follow this lesson, we need to have a GitLab account, create a dedicated GitLab repository, and store the relevant files there.

We will begin with a GitLab repository that contains the following files:

  • hw.go: This is a sample program that is used to make sure that everything works in our GitLab setup.

  • .gitignore: It is not necessary to have such a file, but it is very handy for ignoring some files and directories.

  • usePost05.go: This is a sample Go file that uses an external package—please refer to the https://gitlab.com/mactsouk/runners-go/ repository for its contents.

  • README.md: This file is automatically displayed on the repository web page and is usually used for explaining the purpose of the repository.

There is also a directory called .git that contains information and metadata about the repository.

The initial version of the configuration file

Let’s set up a CI/CD configuration file to help us ensure that everything is fine with our GitLab Runner setup. The name of the configuration file is .gitlab-ci.yml, and it is a YAML file that should be located in the root directory of the GitLab repository. This initial version of the .gitlab-ci.yml configuration file compiles hw.go and creates a binary file, which is executed in a different stage than the one it was created in. This means that we should create an artifact for keeping and transferring that binary file:

Get hands-on with 1400+ tech skills courses.