Deploying a Gitlab Runner on AWS with Packer

- 2 mins


This post was originally published on the blog. 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 Hostatic recipe!



git clone

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/ <environment (e.g.: dev)> <gitlab_cicd_token>

Next steps

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 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!

rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium tumblr soundcloud blog