Created
June 23, 2016 13:43
-
-
Save badri/81472ec59a2c019f16ba3a439717ab02 to your computer and use it in GitHub Desktop.
prehook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo $TSURU_HOST | |
TSURU_HOST=$9; | |
ARCHIVE_SERVER_READ="54.225.98.74:6060"; | |
echo ${ARCHIVE_SERVER_READ} | |
ARCHIVE_SERVER_WRITE="http://127.0.0.1:6161"; | |
TSURU_TOKEN=$1; #archive_url=$2; commit=$3; APP_NAME=$4; TSURU_USER=$5 | |
COMMIT=$2; | |
GIT_TOKEN=$3; | |
GIT_EP=$4; | |
GIT_USER=$5; | |
GIT_REPO=$6; | |
APP_NAME=$7; | |
BORT=$8; | |
TSURU_HOST="${TSURU_HOST}:8080" | |
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}'` | |
echo $content_type; | |
done | |
} | |
git_archive_all() { | |
REV=$1; FILE=$2 | |
TMP_WORK_DIR=$(mktemp -d) | |
chmod 755 $TMP_WORK_DIR | |
if [ -z "$BORT" ]; then | |
BORT="master" | |
echo "Cloning - master branch" | |
git clone -b ${BORT} git@${GIT_EP}/${GIT_USER}/${GIT_REPO} -q $TMP_WORK_DIR | |
else | |
echo "Cloning into ${BORT}" | |
git clone -b ${BORT} git@${GIT_EP}/${GIT_USER}/${GIT_REPO} -q $TMP_WORK_DIR | |
fi | |
cd $TMP_WORK_DIR; | |
tar zcf /tmp/$FILE . | |
# rm -rf $TMP_WORK_DIR > /dev/null | |
} | |
save_archive() { | |
url=${ARCHIVE_SERVER_WRITE}/ | |
tt=$(curl -sN -F archive=@/tmp/${1} http://127.0.0.1:6161) | |
python <<END | |
import json | |
print json.loads(u"""${tt}""")["id"] | |
END | |
} | |
APP_NAME=${APP_NAME}; | |
UUID=`python -c 'import uuid; print uuid.uuid4().hex'` | |
ARCHIVE_FILE_NAME=${APP_NAME}_${COMMIT}_${UUID}.tar.gz | |
git_archive_all $COMMIT $ARCHIVE_FILE_NAME | |
echo "git archive all done----->>>" | |
archive_id=`save_archive $ARCHIVE_FILE_NAME` | |
archive_url="$ARCHIVE_SERVER_READ/?id=$archive_id" | |
echo $archive_url | |
wait_archive $archive_url | |
url="${TSURU_HOST}/apps/${APP_NAME}/deploy" | |
curl -H "Authorization: bearer ${TSURU_TOKEN}" -d "archive-url=${archive_url}&commit=${COMMIT}&user=${TSURU_USER}" -s -N $url | tee /tmp/deplo$ | |
rm /tmp/${ARCHIVE_FILE_NAME} | |
#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