Last active
January 4, 2017 19:38
-
-
Save BrianHicks/f8159e54fe565569b85f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: | |
# Control marathon via hubot | |
# | |
# Configuration: | |
# HUBOT_MARATHON_HOST=marathon.yourcompany.com:8080 | |
# | |
# Commands: | |
# hubot marathon - show the instances of all apps | |
# hubot marathon <id> - show the number of instances for app <id> | |
# hubot scale <id> <number> - scale app ID to <number> instances | |
# | |
# Author: | |
# Brian Hicks <[email protected]> | |
module.exports = (robot) -> | |
host = process.env.HUBOT_MARATHON_HOST | |
robot.respond /marathon$/i, (msg) -> | |
msg.http("http://#{host}/v2/apps").get() (err, res, body) -> | |
apps = JSON.parse(body) | |
if err | |
msg.send err | |
return | |
for app in apps.apps | |
msg.send humanize(app) | |
robot.respond /marathon (.+?)$/i, (msg) -> | |
id = msg.match[1] | |
msg.http("http://#{host}/v2/apps#{id}") | |
.get() (err, res, body) -> | |
app = JSON.parse(body) | |
if err | |
msg.send err | |
return | |
else | |
msg.send humanize(app.app) | |
robot.respond /scale (.+?) (\d+)$/i, (msg) -> | |
id = msg.match[1] | |
instances = msg.match[2] | |
payload = JSON.stringify {instances: parseFloat(instances, 10)} | |
msg.http("http://#{host}/v2/apps#{id}") | |
.header("Content-Type", "application/json") | |
.header("Accept", "application/json") | |
.put(payload) (err, res, body) -> | |
body = JSON.parse(body) | |
if err | |
msg.send "Error! #{err}" | |
else | |
msg.send("Started deployment to scale #{id} to #{instances} instances - check http://#{host} for deployment status.") | |
msg.send("New version: #{body.version}") | |
humanize = (app) -> | |
message = "#{app.id}: #{app.instances} instances, " | |
if app.ports | |
if app.ports.length == 1 | |
message += "port #{app.ports[0]}, " | |
else | |
message += "ports " | |
for port in app.ports | |
message += "#{port}, " | |
if app.container | |
if app.container.docker | |
if app.container.docker.image | |
message += "image #{app.container.docker.image}, " | |
message += "version #{app.version}" | |
message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment