Skip to content

Instantly share code, notes, and snippets.

@jblancett
Last active August 29, 2015 14:17
Show Gist options
  • Save jblancett/77ca1f0c8a99819b87da to your computer and use it in GitHub Desktop.
Save jblancett/77ca1f0c8a99819b87da to your computer and use it in GitHub Desktop.
#!/bin/bash -el
while read oldrev newrev refname
do
COMMIT=${newrev}
done
generate_archive() {
url="${ARCHIVE_SERVER_WRITE}/"
result=`curl -sNd "path=${1}&refid=${2}" $url`
python <<END
import json
print json.loads(u"""${result}""")["id"]
END
}
wait_archive() {
url="${1}&keep=1"
content_type=`curl -sI $url | grep Content-Type | awk '{print $2}'`
while echo $content_type | grep -v application/x-gzip
do
sleep 1
content_type=`curl -sI $url | grep Content-Type | awk '{print $2}'`
done
}
APP_DIR=${PWD##*/}
APP_NAME=${APP_DIR/.git/}
archive_id=`generate_archive $PWD $COMMIT`
archive_url="${ARCHIVE_SERVER_READ}/?id=$archive_id"
wait_archive $archive_url
url="${TSURU_HOST}/apps/${APP_NAME}/repository/clone"
curl -H "Authorization: bearer ${TSURU_TOKEN}" -d "archive-url=${archive_url}&commit=${COMMIT}&user=${TSURU_USER}" -s -N $url | tee /tmp/deploy-${APP_NAME}.log
tail -1 /tmp/deploy-${APP_NAME}.log | grep -q "^OK$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment