Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ebeigarts
Created June 30, 2017 14:28
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 ebeigarts/c85a201a60caf04f9182303d119e0226 to your computer and use it in GitHub Desktop.
Save ebeigarts/c85a201a60caf04f9182303d119e0226 to your computer and use it in GitHub Desktop.
#!/bin/bash
send-message() {
local message=$(echo "$@" \
| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" \
| sed 's/\\/\\\\/g' \
| sed 's/"/\\"/g' \
| sed "s/'/\\'/g")
echo $message
json="{ \"text\": \"$message\" }"
curl -s -d "payload=$json" $SLACK_WEBHOOK_URL > /dev/null
}
slack() {
while read line; do
send-message $line
done
}
clone-repo() {
if [ ! -d .$APP_NAME ]; then
git clone $REPO .$APP_NAME
fi
}
add-dokku-remote() {
git remote add dokku dokku@localhost:$APP_NAME
}
fetch-repo() {
git fetch origin > /dev/null
}
deploy-repo() {
git push -f dokku origin/$BRANCH:master 2>&1 | grep -v "Everything up-to-date"
}
deploy() {
while true; do
fetch-repo
deploy-repo | slack
sleep 30
done
}
set -x
APP_NAME=$1
REPO=$2
BRANCH=$3
SLACK_WEBHOOK_URL=$4
clone-repo
cd .$APP_NAME
add-dokku-remote
# deploy-test() {
# echo $'remote: \e[1G'"------>" "Updated branch 'master' of 'xx'. Deploying to dev."
# echo $'remote: \e[1G'" " "Doing a lot of awesome stuff."
# }
deploy | slack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment