Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use bash for deploy scripts.
  • Loading branch information
brixen committed Dec 14, 2015
1 parent 00e855a commit 78ee0d5
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 58 deletions.
59 changes: 1 addition & 58 deletions rakelib/deploy.rake
@@ -1,61 +1,4 @@
require 'aws-sdk'
require 'pathname'

desc "Deploy a Rubinius release"
task :deploy do
s3 = Aws::S3::Client.new(region: "us-west-2")
file_exts = ["", ".md5", ".sha1", ".sha512"]

# TODO: extract the name to a method
basename = "rubinius-#{rbx_version}.tar.bz2"

# Build and upload the release tarball to S3.
if ENV["TRAVIS_OS_NAME"] == "linux" and ENV["CC"] == "clang" and ENV["RVM"] == "rbx-2"
puts "Deploying release tarball #{basename}..."

Rake::Task['release'].invoke

bucket = "rubinius-releases-rubinius-com"

index = "index.txt"
index_list = s3.get_object(bucket: bucket, key: index).body.read

file_exts.each do |ext|
name = basename + ext
s3.put_object bucket: bucket, key: name, body: File.read(name)

index_list << name << "\n" unless index_list =~ /#{name}/
end

s3.put_object bucket: bucket, key: index, body: index_list
end

# Build and upload a binary to S3.
if ENV["RVM"] == "rbx-2"
puts "Deploying Travis binary #{basename}..."

Rake::Task['package:binary'].invoke

url_prefix = "https://rubinius-binaries-rubinius-com.s3-us-west-2.amazonaws.com/"
bucket = "rubinius-binaries-rubinius-com"

if ENV["TRAVIS_OS_NAME"] == "linux"
path_prefix = "ubuntu/12.04/x86_64/"
else
path_prefix = "osx/10.9/x86_64/"
end

index_list = s3.get_object(bucket: bucket, key: index).body.read

file_exts.each do |ext|
name = basename + ext
key = path_prefix + name
s3.put_object bucket: bucket, key: key, body: File.read(name)

path = url_prefix + key
index_list << path << "\n" unless index_list =~ /#{path}/
end

s3.put_object bucket: bucket, key: index, body: index_list
end
sh "./scripts/deploy.sh"
end
2 changes: 2 additions & 0 deletions rakelib/package.rake
Expand Up @@ -8,6 +8,8 @@ namespace :package do
desc "Create a release tarball from the source"
task :tar do
archive = "rubinius-#{rbx_version}.tar.bz2"
sh "rm -rf #{archive}"

files = "{ git ls-files; ls .revision; ls vendor/cache/*.gem; }"
prefix = "-s '|^|rubinius-#{rbx_version}/|'"
sh "#{files} | sort | uniq | tar -c #{prefix} -T - -f - | bzip2 > #{archive}"
Expand Down
36 changes: 36 additions & 0 deletions scripts/aws.sh
@@ -0,0 +1,36 @@
# Adapted from https://gist.github.com/chrismdp/6c6b6c825b07f680e710
function rbx_s3_upload {
local url bucket path file date acl content_type data signature

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

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

acl="x-amz-acl:public-read"
content_type="application/octet-stream"

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

curl -X PUT -T "$file" \
-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"
}

function rbx_s3_download {
local url file path

url=$1
file=$2
path=${3:-/}

curl -o "$file" "$url$path$file"
}
49 changes: 49 additions & 0 deletions scripts/configuration.sh
@@ -0,0 +1,49 @@
function rbx_script_path {
local dir
dir=$(dirname "$0")

cd "$dir" && pwd
}

function rbx_git_directory {
echo "$(rbx_script_path)/../.git"
}

function rbx_revision_file {
echo "$(rbx_script_path)/../.revision"
}

function rbx_get_revision {
local describe count version commit_count commit_date commit_hash

if [[ -d $(rbx_git_directory) ]]; then
describe=$(git describe --tags --match=v2* --abbrev=40 --long)

count=$(echo "$describe" | cut -d - -f 2)
if [[ $count != "0" ]]; then
commit_count=".c$count"
fi

version=$(echo "$describe" | egrep -o '^v\d+\.\d+' | cut -c 2-)
commit_date=$(git show --format="%ci" HEAD | egrep -o '\d+-\d+-\d+')
commit_hash=$(echo "$describe" | egrep -o '[[:xdigit:]]{8,}$')

echo "$version$commit_count $commit_date $commit_hash"
elif [[ -f $(rbx_revision_file) ]]; then
cat "$(rbx_revision_file)"
else
echo "X.Y $( date +"%F" ) build"
fi
}

function rbx_revision_version {
rbx_get_revision | cut -d ' ' -f 1
}

function rbx_revision_date {
rbx_get_revision | cut -d ' ' -f 2
}

function rbx_revision_hash {
rbx_get_revision | cut -d ' ' -f 3
}
74 changes: 74 additions & 0 deletions scripts/deploy.sh
@@ -0,0 +1,74 @@
#!/bin/bash

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

bucket=$1
file=$2
path=${3:-}
url=$(rbx_url_prefix "$bucket")

rbx_s3_download "$url" "index.txt"

# Upload all the files first.
for ext in "${file_exts[@]}"; do
rbx_s3_upload "$url" "$bucket" "$file$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"
else
name="$file$ext"
fi

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

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

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

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

bucket="rubinius-releases-rubinius-com"

rbx_upload_files "$bucket" "$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}..."

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

bucket="rubinius-binaries-rubinius-com"

if [[ $TRAVIS_OS_NAME == linux ]]; then
path="ubuntu/12.04/x86_64/"
else
path="osx/10.9/x86_64/"
fi

rbx_upload_files "$bucket" "$release_name" "$path"
fi
6 changes: 6 additions & 0 deletions scripts/io.sh
@@ -0,0 +1,6 @@
function fail {
local message=$1
message=${message:=An unhandled error occurred}
echo "$message at ${BASH_SOURCE[1]}:${FUNCNAME[1]} line ${BASH_LINENO[0]}." >&2
exit 1
}

0 comments on commit 78ee0d5

Please sign in to comment.