def notify(targetMarathonUrl, service): parsedMarathonUrl = urlparse(targetMarathonUrl) tags = ["environment:%s" % service.environment, "service:%s" % service.id] title = "Deployed %s to the %s environment" % (service.id, service.environment) # Send HipChat notification notify_message = "Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" % ( service.id, service.image, service.environment, parsedMarathonUrl.netloc) if service.releaseNotes: notify_message += service.releaseNotes hipchat = HipChat(util.rget(service.document, 'hipchat', 'token'), util.rget(service.document, 'hipchat', 'url'), util.rget(service.document, 'hipchat', 'rooms')) hipchat.notify(notify_message) # Send NewRelic deployment notification newrelic = NewRelic(util.rget(service.document, 'newrelic', 'token')) newrelic.notify(util.rget(service.config, 'env', 'NEW_RELIC_APP_NAME'), service.uniqueVersion) # Send Datadog deployment notification datadog = Datadog( util.rget(service.document, 'datadog', 'token'), util.toList(util.rget(service.document, 'datadog', 'tags'))) datadog.notify( aggregation_key="%s_%s" % (service.environment, service.id), title=title, message= "%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc), tags=tags) # Send Graphite deployment notification prefix = (util.rget(service.document, 'graphite', 'prefix') or 'lighter').strip('.') metricname = '%s.%s.%s.deployments' % ( prefix, service.environment, '.'.join( filter(bool, service.id.split('/')))) graphite = Graphite( util.rget(service.document, 'graphite', 'address'), util.rget(service.document, 'graphite', 'url'), util.toList(util.rget(service.document, 'graphite', 'tags'))) graphite.notify(metricname=metricname, title=title, message="Lighter deployed %s with image %s to %s (%s)" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc), tags=tags)
def deploy(marathonurl, filenames, noop=False, force=False, targetdir=None): parsedMarathonUrl = urlparse(marathonurl) services = parse_services(filenames, targetdir) for service in services: try: appurl = get_marathon_url(marathonurl, service.config['id'], force) # See if service config has changed prevConfig = get_marathon_app(appurl) if compare_service_versions(service.config, prevConfig): logging.debug("Service already deployed with same config: %s", service.filename) continue # Skip deployment if noop flag is given if noop: continue # Deploy new service config logging.info("Deploying %s", service.filename) util.jsonRequest(appurl, data=service.config, method='PUT') # Send HipChat notification hipchat = HipChat( util.rget(service.document,'hipchat','token'), util.rget(service.document,'hipchat','url'), util.rget(service.document,'hipchat','rooms')) hipchat.notify("Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc)) # Send NewRelic deployment notification newrelic = NewRelic(util.rget(service.document, 'newrelic', 'token')) newrelic.notify( util.rget(service.config, 'env', 'NEW_RELIC_APP_NAME'), service.uniqueVersion ) # Send Datadog deployment notification datadog = Datadog(util.rget(service.document, 'datadog', 'token')) datadog.notify( title="Deployed %s to the %s environment" % (service.id, service.environment), message="%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc), id=service.id, tags=[ "environment:%s" % service.environment, "service:%s" % service.id ] ) except urllib2.HTTPError, e: raise RuntimeError("Failed to deploy %s HTTP %d (%s)" % (service.filename, e.code, e)), None, sys.exc_info()[2] except urllib2.URLError, e: raise RuntimeError("Failed to deploy %s (%s)" % (service.filename, e)), None, sys.exc_info()[2]
def notify(targetMarathonUrl, service): parsedMarathonUrl = urlparse(targetMarathonUrl) tags = ["environment:%s" % service.environment, "service:%s" % service.id] title = "Deployed %s to the %s environment" % (service.id, service.environment) # Send HipChat notification hipchat = HipChat( util.rget(service.document, 'hipchat', 'token'), util.rget(service.document, 'hipchat', 'url'), util.rget(service.document, 'hipchat', 'rooms')) hipchat.notify("Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc)) # Send NewRelic deployment notification newrelic = NewRelic(util.rget(service.document, 'newrelic', 'token')) newrelic.notify( util.rget(service.config, 'env', 'NEW_RELIC_APP_NAME'), service.uniqueVersion) # Send Datadog deployment notification datadog = Datadog( util.rget(service.document, 'datadog', 'token'), util.toList(util.rget(service.document, 'datadog', 'tags'))) datadog.notify( aggregation_key="%s_%s" % (service.environment, service.id), title=title, message="%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%" % ( service.id, service.image, service.environment, parsedMarathonUrl.netloc), tags=tags) # Send Graphite deployment notification prefix = (util.rget(service.document, 'graphite', 'prefix') or 'lighter').strip('.') metricname = '%s.%s.%s.deployments' % ( prefix, service.environment, '.'.join(filter(bool, service.id.split('/')))) graphite = Graphite( util.rget(service.document, 'graphite', 'address'), util.rget(service.document, 'graphite', 'url'), util.toList(util.rget(service.document, 'graphite', 'tags'))) graphite.notify( metricname=metricname, title=title, message="Lighter deployed %s with image %s to %s (%s)" % ( service.id, service.image, service.environment, parsedMarathonUrl.netloc), tags=tags)
def notify(targetMarathonUrl, service): parsedMarathonUrl = urlparse(targetMarathonUrl) tags = ["environment:%s" % service.environment, "service:%s" % service.id] title = "Deployed %s to the %s environment" % (service.id, service.environment) # Send HipChat notification notify_message = "Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" % ( service.id, service.image, service.environment, parsedMarathonUrl.netloc) if service.releaseNotes: notify_message += service.releaseNotes hipchat = HipChat(util.rget(service.document, 'hipchat', 'token'), util.rget(service.document, 'hipchat', 'url'), util.rget(service.document, 'hipchat', 'rooms')) hipchat.notify(notify_message) # Send Slack notification notify_payload = { "title_link": targetMarathonUrl, "fields": [{ "title": "Service", "value": service.id, "short": 'true' }, { "title": "Environment", "value": service.environment, "short": 'true' }, { "title": "Image", "value": service.image, "short": 'true' }], "ts": int(time.time()) } if service.releaseNotes: notify_payload = util.merge({'text': service.releaseNotes}, notify_payload) slack = Slack(util.rget(service.document, 'slack', 'token'), util.rget(service.document, 'slack', 'url'), util.rget(service.document, 'slack', 'channels')) slack.notify(notify_payload) # Send NewRelic deployment notification newrelic = NewRelic(util.rget(service.document, 'newrelic', 'token')) newrelic.notify(util.rget(service.config, 'env', 'NEW_RELIC_APP_NAME'), service.uniqueVersion) # Send Datadog deployment notification datadog = Datadog( util.rget(service.document, 'datadog', 'token'), util.toList(util.rget(service.document, 'datadog', 'tags'))) datadog.notify( aggregation_key="%s_%s" % (service.environment, service.id), title=title, message= "%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc), tags=tags) # Send Graphite deployment notification prefix = (util.rget(service.document, 'graphite', 'prefix') or 'lighter').strip('.') metricname = '%s.%s.%s.deployments' % ( prefix, service.environment, '.'.join( filter(bool, service.id.split('/')))) graphite = Graphite( util.rget(service.document, 'graphite', 'address'), util.rget(service.document, 'graphite', 'url'), util.toList(util.rget(service.document, 'graphite', 'tags'))) graphite.notify(metricname=metricname, title=title, message="Lighter deployed %s with image %s to %s (%s)" % (service.id, service.image, service.environment, parsedMarathonUrl.netloc), tags=tags)