Skip to content

Instantly share code, notes, and snippets.

@enyachoke
Created November 13, 2013 20:43
Show Gist options
  • Save enyachoke/7456079 to your computer and use it in GitHub Desktop.
Save enyachoke/7456079 to your computer and use it in GitHub Desktop.
This is a git pre-recieve hook that compiles a slug using heroku buildpacks and optionally uploads it to s3 and generate a pre-signed url for downloading it. This script assumes you have s3cmd installed and configured.
#!/bin/bash
while read oldrev newrev refname
do
# Only build the master branch.
if [[ $refname = "refs/heads/master" ]] ; then
echo "building------> $newrev ... "
#We get the archive and pass it to the slug builder
slug_id=newapp
git archive $newrev | docker run -i -name $newrev -a stdin -a stdout -a stderr flynn/slugbuilder - > $newrev.tgz
# s3cmd put $newrev.tgz s3://pyxiscloud/$newrev.tgz
#s3cmd signurl s3://pyxiscloud/$newrev.tgz
#s3cmd signurl s3://pyxiscloud/$newrev.tgz "1415837645"
docker rm $newrev
#mv $newrev.tgz ../../$newrev.tgz
# $? is a shell variable which stores the return code from what we just ran
rc=$?
if [[ $rc != 0 ]] ; then
# A non-zero return code means an error occurred, so tell the user and exit
echo "for some reason we where unable to build $newrev - Please try again"
exit $rc
fi
fi
done
# Bingo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment