Gitlab.com allows its users to run their own, self-hosted, Gitlab Runners as part of their Gitlab CI feature. This comes in handy when the CI jobs have to run in a user-owned environment or more powerful runners are needed.
If that environment is AWS and you are looking for an automated way of setting up the Runner(s) on EC2, then stay tuned for a 56k.cloud recipe!
git clone https://gitlab.com/56k/packer.git
cd packer/gitlab-runner packer build -var 'aws_access_key=<your_access_key_id>' -var 'aws_secret_key=<your_access_key>' gitlab-runner.json
/home/ubuntu/gitlab-runner-register.sh <environment (e.g.: dev)> <gitlab_cicd_token>
At this point, the Gitlab runner is attached to the project. When defining the Gitlab CI / CD pipeline in .gitlab-ci.yml each job will have to use a tag to run that job on the new Gitlab runner. This tag matches the environment passed to the gitlab-runner-register.sh
script above. Example:
job: script: - echo "Hello world!" tags: - <environment (e.g. dev)>
Now that we have a reusable image (AMI) for a self-hosted Gitlab runner, it can be used as a building block for further automation.
One possible next improvement is to use this AMI and the User Data script in an infrastructure-as-code DSL like Terraform or Cloudformation. But that's a subject for a future blog post!
We love Cloud, Containers, DevOps, and Infrastructure as Code. If you are interested in chatting connect with us on Twitter or drop us an email: info@56K.Cloud We hope you found this article helpful. If there is anything you would like to contribute or you have questions, please let us know!
Software Engineer
"Site Reliability Engineer"