Code Monkey home page Code Monkey logo

buildkite-spot-fleet-scaler's Introduction

buildkite-spot-fleet-scaler

What is this?

buildkite-spot-fleet-scaler is a script that scales fleet(s) of Buildkite agents up/down as necessary based on the number of queued jobs for each fleet.

Dependencies

  • The AWS CLI (aws) command
  • Data::Compare (libdata-compare-perl on Debian)
  • IPC::Run (libipc-run-perl on Debian)
  • JSON (libjson-perl on Debian)
  • List::Compare (liblist-compare-perl on Debian)
  • List::Util (included in Perl core)
  • LWP (included in Perl core)

The AWS user used for the script needs to have permissions like the following IAM policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "ec2:ModifySpotFleetRequest",
            "Resource": "arn:aws:ec2:*:652694334613:spot-fleet-request/*",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "ec2:ResourceTag/buildkite-scaler-enable": "1"
                }
            }
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeTags",
                "ec2:DescribeSpotFleetRequests"
            ],
            "Resource": "*"
        }
    ]
}

An "API Token" must be created on Buildkite that has the "Read Builds" permission.

How to use it?

This script only handles scaling of existing Spot Fleet Requests, you have to create those yourself.

To enable automatic scaling add the following tags to your Spot Fleet Requests:

# 'meta-data' parameter from buildkite-agent.cfg
buildkite-agent-meta-data = "queue=default"

# 'spawn' parameter from buildkite-agent.cfg
buildkite-agent-spawn = "1"

# Minimum and maximum number of allowed spot instances.
buildkite-scaler-min-instances = "0"
buildkite-scaler-max-instances = "2"

# Enable the scaler on this fleet.
buildkite-scaler-enable = "1"

# Automatically terminate agents when there is no work (optional).
# NOTE: This is prone to race conditions. I suggest leaving this disabled and designing the agent
# AMIs so that they shut themselves down when idle instead.
buildkite-scaler-terminate-on-scale-down = "1"

Set BUILDKITE_ORGANIZATION and BUILDKITE_API_KEY in the environment and run the buildkite-spot-fleet-scaler script with no arguments. The script will update the fleet target capacities as necessary once and then exit. Run it from cron or another part of your automation pipeline.

buildkite-spot-fleet-scaler's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.