Skip to content

Instantly share code, notes, and snippets.

@toracle
Created September 8, 2017 07:06
Show Gist options
  • Save toracle/7923388a8dbf60f2ed2033df18c3f26b to your computer and use it in GitHub Desktop.
Save toracle/7923388a8dbf60f2ed2033df18c3f26b to your computer and use it in GitHub Desktop.
tutorial-opsworksbot-deploy
from bothub_client.bot import BaseBot
from bothub_client.messages import Message
class Bot(BaseBot):
def on_deploy(self, event, context):
data = self.get_user_data()
stack_id = data['stack_id']
client = self.get_boto_client(data)
response = client.describe_apps(StackId=stack_id)
apps = [(a['AppId'], a['Name']) for a in response['Apps']]
message = Message(event)
message.set_text('Select an app to deploy:')
for app in apps:
message.add_postback_button(app[1], '/deploy_app {}'.format(app[0]))
self.send_message(message)
def on_deploy_app(self, event, context, app_id):
message = Message(event)
message.set_text('Which deploy command do you want to execute?')
for command_name, command_id in [('deploy', 'deploy'), ('update_custom_cookbooks', 'ucc')]:
message.add_quick_reply(command_name, '/deploy_command {} {}'.format(app_id, command_id))
self.send_message(message)
def on_deploy_command(self, event, context, app_id, command_id):
data = self.get_user_data()
stack_id = data['stack_id']
client = self.get_boto_client(data)
command_id_to_name = {
'deploy': 'deploy',
'ucc': 'update_custom_cookbooks',
}
response = client.create_deployment(
StackId=stack_id,
AppId=app_id,
Command={'Name': command_id_to_name[command_id]}
)
message = Message(event)
message.set_text('Deployment is started')
message.add_postback_button('Deployment status', '/deploy_status {}'.format(response['DeploymentId']))
self.send_message(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment