Skip to content

Commit

Permalink
Showing 2 changed files with 55 additions and 27 deletions.
15 changes: 8 additions & 7 deletions scripts/aws.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# Adapted from https://gist.github.com/chrismdp/6c6b6c825b07f680e710
function rbx_s3_upload {
local url bucket path file date acl content_type data signature
local url bucket path dest src date acl content_type data signature

url=$1
bucket=$2
file=$3
path=${4:-/}
dest=$3
src=$4
path=${5:-/}

date=$(date +"%a, %d %b %Y %T %z")

acl="x-amz-acl:public-read"
content_type=$(file --mime-type -b $file)
content_type=$(file --mime-type -b "$src")

data="PUT\n\n$content_type\n$date\n$acl\n/$bucket$path$file"
data="PUT\n\n$content_type\n$date\n$acl\n/$bucket$path$dest"
signature=$(echo -en "${data}" |
openssl sha1 -hmac "${AWS_SECRET_ACCESS_KEY}" -binary | base64)

curl -X PUT -T "$file" \
curl -X PUT -T "$src" \
-H "Host: $bucket.s3-us-west-2.amazonaws.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$acl" \
-H "Authorization: AWS ${AWS_ACCESS_KEY_ID}:$signature" \
"$url$path$file"
"$url$path$dest"
}

function rbx_s3_download {
67 changes: 47 additions & 20 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -4,71 +4,98 @@ source "scripts/io.sh"
source "scripts/aws.sh"
source "scripts/configuration.sh"

release_name="rubinius-$(rbx_revision_version).tar.bz2"

file_exts=("" ".md5" ".sha1" ".sha512")

function rbx_url_prefix {
local bucket=$1
echo "https://${bucket}.s3-us-west-2.amazonaws.com"
}

function rbx_upload_files {
local bucket file path url name
local bucket dest src path url name file_exts index

bucket=$1
file=$2
path=${3:-}
dest=$2
src=$3
path=${4:-}
url=$(rbx_url_prefix "$bucket")
file_exts=("" ".md5" ".sha1" ".sha512")
index="index.txt"

rbx_s3_download "$url" "index.txt"
rbx_s3_download "$url" "$index"

# Upload all the files first.
for ext in "${file_exts[@]}"; do
rbx_s3_upload "$url" "$bucket" "$file$ext" "$path" || fail "unable to upload file"
rbx_s3_upload "$url" "$bucket" "$dest$ext" "$src$ext" "$path" ||
fail "unable to upload file"
done

# Update the index and upload it.
for ext in "${file_exts[@]}"; do
if [[ -n $path ]]; then
name="$url$path$file$ext"
name="$url$path$dest$ext"
else
name="$file$ext"
name="$dest$ext"
fi

grep "$name" "index.txt"
grep "$name" "$index"
if [ $? -ne 0 ]; then
echo "$name" >> "index.txt"
echo "$name" >> "$index"
fi
done

rbx_s3_upload "$url" "$bucket" "index.txt" || fail "unable to upload index"
rbx_s3_upload "$url" "$bucket" "$index" "$index" || fail "unable to upload index"
}

# Build and upload the release tarball to S3.
if [[ $TRAVIS_OS_NAME == osx && $CC == gcc && $RVM == "rbx-2" ]]; then
echo "Deploying release tarball ${release_name}..."
echo "Deploying release tarball $(rbx_revision_version)..."

rake release || fail "unable to build release tarball"

bucket="rubinius-releases-rubinius-com"
release_name="rubinius-$(rbx_revision_version).tar.bz2"

rbx_upload_files "$bucket" "$release_name"
rbx_upload_files "$bucket" "$release_name" "$release_name"
fi

# Build and upload a binary to S3.
if [[ $RVM == "rbx-2" ]]; then
echo "Deploying Travis binary ${release_name} for ${TRAVIS_OS_NAME}..."
echo "Deploying Travis binary $(rbx_revision_version) for ${TRAVIS_OS_NAME}..."

rake package:binary || fail "unable to build binary"

bucket="rubinius-binaries-rubinius-com"
revision_version=$(rbx_revision_version)
release_name="rubinius-$revision_version.tar.bz2"

declare -a paths os_releases versions

if [[ $TRAVIS_OS_NAME == linux ]]; then
path="/ubuntu/12.04/x86_64/"
os_releases=("12.04" "14.04" "15.10")
for (( i=0; i < ${#os_releases[@]}; i++ )); do
paths[i]="/ubuntu/${os_releases[i]}/x86_64/"
done
else
path="/osx/10.9/x86_64/"
os_releases=("10.9" "10.10" "10.11")
for (( i=0; i < ${#os_releases[@]}; i++ )); do
paths[i]="/osx/${os_releases[i]}/x86_64/"
done
fi

rbx_upload_files "$bucket" "$release_name" "$path"
IFS="." read -r -a array <<< "$revision_version"

let i=0
version=""
versions[i]=""

for v in "${array[@]}"; do
let i=i+1
versions[i]="-$version$v"
version="$v."
done

for path in "${paths[@]}"; do
for version in "${versions[@]}"; do
rbx_upload_files "$bucket" "rubinius$version.tar.bz2" "$release_name" "$path"
done
done
fi

0 comments on commit 2b6ff7f

Please sign in to comment.