Skip to content

Instantly share code, notes, and snippets.

@seveas
Last active December 21, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seveas/270c036499ed37f79b3afd9134288ed0 to your computer and use it in GitHub Desktop.
Save seveas/270c036499ed37f79b3afd9134288ed0 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Usage:
#
# To deploy the current branch to production
#
# .deploy
#
# To deploy the current branch to a different environment
#
# .deploy staging
#
# To deploy a branch to a single host in prod
#
# .deploy ops-default-1234567.ac4-iad.github.net
#
# To get tab completion for hostnames, add the following line to your ~/.bashrc
# and copy /etc/ssh/known_hosts from a random github server to
# ~/.ssh/known_hosts.
#
# complete -F _ssh .deploy
# This is https://git-spindle.seveas.net + a custom plugin from my dotfiles,
# let's not expect it to always be available
if which git-hub &>/dev/null; then
git hub wait-for-ci || exit $?
fi
# By default we go to this channel - change to your needs
default_chan=observability-chatops
# We deploy the currently checked out branch
repo=$(basename $(git rev-parse --show-toplevel))
branch=$(git rev-parse --abbrev-ref HEAD)
# Find the channel to use in heaven's apps.yml, if we happen to have it checked
# out locally
if [ -e ~/github/heaven ]; then
apps=~/github/heaven/config/apps.yml
chan=$(yq r $apps $repo.rooms[0])
fi
: ${chan:=$default_chan}
# Common typo: .deploy to staging. Ignore the "to"
if [ "$1" = to ]; then
shift
fi
# By default we deploy to prod. And if we deploy to a hostname, make it
# prod/hostname
to=$1
case ${to:=prod} in
*.github.net)
to=prod/$to
;;
esac
# From https://github.com/seveas/hacks
# We send the .deploy command to hubot and wait for it to finish deploying
slack-send $chan .deploy $repo/$branch to $to
slack-tail $chan hubot --until 'deployment.*(is|failed)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment