Skip to content

Instantly share code, notes, and snippets.

@vekMaster
Last active March 17, 2021 22:57
Show Gist options
  • Save vekMaster/bae0d9de4ea673fa9fe25776b40bd2ad to your computer and use it in GitHub Desktop.
Save vekMaster/bae0d9de4ea673fa9fe25776b40bd2ad to your computer and use it in GitHub Desktop.
Create gitlab runner in AWS with Spot instance

Requirements

  1. the Registration Token for Specific project, or Group project (Recommend).
  2. AWS account with Policies (or permissions) to use cloudformation.
  3. EC2 key pair. Tutorial [here][https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html]

How to create

  1. With the registration token, we are going to register a new Runner and generate an <AUTHENTICATION_TOKEN>
  • Run the next command in a terminal: curl --header "PRIVATE-TOKEN: <REGISTER_TOKEN>" "https://gitlab.com/api/v4/runners"

  • The response looks like this: {"id":<NUMBER_ID>,"token":<AUTHENTICATION_TOKEN>}

    Note: Don't forget save the <AUTHENTICATION_TOKEN>

  1. Now, we are going to use a template to create an stack in cloudformation. Just open the repository[1] and click in Launch Stack button

  2. In template, Just fill information:

    • Use the <AUTHENTICATION_TOKEN> in "GitlabToken" Input
    • Use the KeyPair you already created
    • Select in "use spot instance" yes
    • Select in spot instance, the value you want to pay (recommend 0.03)

    Note:

    • Some Avaiability zones does not support nano and micro instances
    • The ec2 and s3 shouldn't exist. the template creates all resources
    • You should give IAM ROLE CAPABILITY to cloudformation template, just select in last step the checkbox "I acknowledge that AWS CloudFormation might create IAM resources"
  3. Check the progress in cloudformation, it takes around 5-10 minutes. If something is wrong, check the AWS cloudformation event tab

  4. If everything is ok, the new Runner should appear in Runner section in your project or group

References

[1] https://github.com/chialab/aws-autoscaling-gitlab-runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment