Use a Slack bot to deploy your app
Tags: bots, devops, slack
Published: 2017-11-10 17:53:15

---
title: "Use a Slack bot to deploy your app"
published: true
tags: bots,devops,slack
canonical_url: 
---

Deploying your web application is certainly not the most interesting activity of your day. But what if it could be simple, reliable and&nbsp;fun?

Using a [Slack bot](https://api.slack.com/bot-users) to deploy your app is actually fun and it brings a lot of perks to the&nbsp;table.

### Why?

Aside from the fun to talk to your bot through your preferred [chat app](https://slack.com), the main benefit is that **there is finally a single source of trust for your deployments**. If you’re using software engineering good practices, your code should be versioned, your database schema should be versioned, your infrastructure should be versioned… so you know exactly what code is deployed on what infrastructure. But what about the code that deploys the rest of the code (whatever it is: shell script, fabric, ansible, salt, puppet, chef, anything…)? Sure it is also versioned. But this code is not deployed on your servers, it’s executed on a developer|ops|devops machine. Has the code been modified? Is the working directory dirty? Is it the latest available version? You never know. Unless all the deployments are executed from a single machine that cannot be accessed through SSH (only deployed to) and that everybody uses. Yes, I’m talking about your Slack&nbsp;bot.

Besides knowing exactly how your deployments are made, another essential point is **communication**. Everybody on the team needs to know when a deployment starts, when it ends and what has been deployed. Everybody also needs to know the deployment history. What is currently deployed? Did someone perform a rollback? Just use a Slack bot, and you get all that for&nbsp;free.

There are other smaller perks too. You don’t need your computer with you for **emergency support**. You can restart a Docker container or perform a rollback right **from your phone**. You just need the mobile Slack app! It’s also really easy to handle **deployment permissions**. Just invite the right people to the authorized channel!

Did I mention it’s a lot of fun to write a Slack&nbsp;bot?

### Why a bot, why not just a slash&nbsp;command?

Slack custom [slash commands](https://api.slack.com/slash-commands) are a great way to trigger an event through a web hook and print the results in Slack. For instance I added to our Serenytics team a command _/srn-active-users_ that returns the last active users on our web app. We could use this to deploy our stack. But a bot is actually a better solution, for two main&nbsp;reasons.

**You can have a conversation with a bot**. You can’t have a conversation with a slash command. And I think this is a killer feature to perform deployments. Why? Because you first ask your bot to deploy your app. It answers with the list of new commits available since the last deployment, and asks you if you want to proceed. Then you can validate the changes before going on. And it’s just&nbsp;great.

Technically, another benefit from using a bot is that you don’t need to deploy a new server somewhere with a domain, an API, an SSL certificate, authentication… a simple daemon script is&nbsp;enough.

### What deploying actually looks like in&nbsp;Slack

Here is the Slack transcript of one of our own actual deployment. Our bot is called Nestor and I’m deploying our frontend application on our AWS&nbsp;servers.

![](https://cdn-images-1.medium.com/max/1024/1*2dW9zIlDQoepDEmXvmwDzA.png)

### Example bot&nbsp;code

Here is the skeleton of the Slack bot we use at [Serenytics](https://www.serenytics.com). It’s a complete running script where you just have to fill in the blanks: your slack token and the actual deployment code. I use shell commands and [Docker Cloud](https://cloud.docker.com) python client in our&nbsp;case.

If you want to know more about Slack bots, [go&nbsp;there](https://api.slack.com/bot-users).

{% gist https://gist.github.com/achauve/668205c28d338268ebb7b952e85b6208 %}

_Give us a shout if you want more details about integrating git history or deploying on Docker&nbsp;Cloud._

* * *