Skip to content

Commit 4dee847

Browse files
committedDec 14, 2015
Use bash for deploy scripts.
1 parent 1cafa08 commit 4dee847

File tree

6 files changed

+168
-58
lines changed

6 files changed

+168
-58
lines changed
 

‎rakelib/deploy.rake

+1-58
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,4 @@
1-
require 'aws-sdk'
2-
require 'pathname'
3-
41
desc "Deploy a Rubinius release"
52
task :deploy do
6-
s3 = Aws::S3::Client.new(region: "us-west-2")
7-
file_exts = ["", ".md5", ".sha1", ".sha512"]
8-
9-
# TODO: extract the name to a method
10-
basename = "rubinius-#{rbx_version}.tar.bz2"
11-
12-
# Build and upload the release tarball to S3.
13-
if ENV["TRAVIS_OS_NAME"] == "linux" and ENV["CC"] == "clang" and ENV["RVM"] == "rbx-2"
14-
puts "Deploying release tarball #{basename}..."
15-
16-
Rake::Task['release'].invoke
17-
18-
bucket = "rubinius-releases-rubinius-com"
19-
20-
index = "index.txt"
21-
index_list = s3.get_object(bucket: bucket, key: index).body.read
22-
23-
file_exts.each do |ext|
24-
name = basename + ext
25-
s3.put_object bucket: bucket, key: name, body: File.read(name)
26-
27-
index_list << name << "\n" unless index_list =~ /#{name}/
28-
end
29-
30-
s3.put_object bucket: bucket, key: index, body: index_list
31-
end
32-
33-
# Build and upload a binary to S3.
34-
if ENV["RVM"] == "rbx-2"
35-
puts "Deploying Travis binary #{basename}..."
36-
37-
Rake::Task['package:binary'].invoke
38-
39-
url_prefix = "https://rubinius-binaries-rubinius-com.s3-us-west-2.amazonaws.com/"
40-
bucket = "rubinius-binaries-rubinius-com"
41-
42-
if ENV["TRAVIS_OS_NAME"] == "linux"
43-
path_prefix = "ubuntu/12.04/x86_64/"
44-
else
45-
path_prefix = "osx/10.9/x86_64/"
46-
end
47-
48-
index_list = s3.get_object(bucket: bucket, key: index).body.read
49-
50-
file_exts.each do |ext|
51-
name = basename + ext
52-
key = path_prefix + name
53-
s3.put_object bucket: bucket, key: key, body: File.read(name)
54-
55-
path = url_prefix + key
56-
index_list << path << "\n" unless index_list =~ /#{path}/
57-
end
58-
59-
s3.put_object bucket: bucket, key: index, body: index_list
60-
end
3+
sh "./scripts/deploy.sh"
614
end

‎rakelib/package.rake

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace :package do
88
desc "Create a release tarball from the source"
99
task :tar do
1010
archive = "rubinius-#{rbx_version}.tar.bz2"
11+
sh "rm -rf #{archive}"
12+
1113
files = "{ git ls-files; ls .revision; ls vendor/cache/*.gem; }"
1214
prefix = "-s '|^|rubinius-#{rbx_version}/|'"
1315
sh "#{files} | sort | uniq | tar -c #{prefix} -T - -f - | bzip2 > #{archive}"

‎scripts/aws.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Adapted from https://gist.github.com/chrismdp/6c6b6c825b07f680e710
2+
function rbx_s3_upload {
3+
local url bucket path file date acl content_type data signature
4+
5+
url=$1
6+
bucket=$2
7+
file=$3
8+
path=${4:-/}
9+
10+
date=$(date +"%a, %d %b %Y %T %z")
11+
12+
acl="x-amz-acl:public-read"
13+
content_type="application/octet-stream"
14+
15+
data="PUT\n\n$content_type\n$date\n$acl\n/$bucket$path$file"
16+
signature=$(echo -en "${data}" |
17+
openssl sha1 -hmac "${AWS_SECRET_ACCESS_KEY}" -binary | base64)
18+
19+
curl -X PUT -T "$file" \
20+
-H "Host: $bucket.s3-us-west-2.amazonaws.com" \
21+
-H "Date: $date" \
22+
-H "Content-Type: $content_type" \
23+
-H "$acl" \
24+
-H "Authorization: AWS ${AWS_ACCESS_KEY_ID}:$signature" \
25+
"$url$path$file"
26+
}
27+
28+
function rbx_s3_download {
29+
local url file path
30+
31+
url=$1
32+
file=$2
33+
path=${3:-/}
34+
35+
curl -o "$file" "$url$path$file"
36+
}

‎scripts/configuration.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
function rbx_script_path {
2+
local dir
3+
dir=$(dirname "$0")
4+
5+
cd "$dir" && pwd
6+
}
7+
8+
function rbx_git_directory {
9+
echo "$(rbx_script_path)/../.git"
10+
}
11+
12+
function rbx_revision_file {
13+
echo "$(rbx_script_path)/../.revision"
14+
}
15+
16+
function rbx_get_revision {
17+
local describe count version commit_count commit_date commit_hash
18+
19+
if [[ -d $(rbx_git_directory) ]]; then
20+
describe=$(git describe --tags --match=v2* --abbrev=40 --long)
21+
22+
count=$(echo "$describe" | cut -d - -f 2)
23+
if [[ $count != "0" ]]; then
24+
commit_count=".c$count"
25+
fi
26+
27+
version=$(echo "$describe" | egrep -o '^v\d+\.\d+' | cut -c 2-)
28+
commit_date=$(git show --format="%ci" HEAD | egrep -o '\d+-\d+-\d+')
29+
commit_hash=$(echo "$describe" | egrep -o '[[:xdigit:]]{8,}$')
30+
31+
echo "$version$commit_count $commit_date $commit_hash"
32+
elif [[ -f $(rbx_revision_file) ]]; then
33+
cat "$(rbx_revision_file)"
34+
else
35+
echo "X.Y $( date +"%F" ) build"
36+
fi
37+
}
38+
39+
function rbx_revision_version {
40+
rbx_get_revision | cut -d ' ' -f 1
41+
}
42+
43+
function rbx_revision_date {
44+
rbx_get_revision | cut -d ' ' -f 2
45+
}
46+
47+
function rbx_revision_hash {
48+
rbx_get_revision | cut -d ' ' -f 3
49+
}

‎scripts/deploy.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
source "scripts/io.sh"
4+
source "scripts/aws.sh"
5+
source "scripts/configuration.sh"
6+
7+
release_name="rubinius-$(rbx_revision_version).tar.bz2"
8+
9+
file_exts=("" ".md5" ".sha1" ".sha512")
10+
11+
function rbx_url_prefix {
12+
local bucket=$1
13+
echo "https://${bucket}.s3-us-west-2.amazonaws.com"
14+
}
15+
16+
function rbx_upload_files {
17+
local bucket file path url name
18+
19+
bucket=$1
20+
file=$2
21+
path=${3:-}
22+
url=$(rbx_url_prefix "$bucket")
23+
24+
rbx_s3_download "$url" "index.txt"
25+
26+
# Upload all the files first.
27+
for ext in "${file_exts[@]}"; do
28+
rbx_s3_upload "$url" "$bucket" "$file$ext" "$path" || fail "unable to upload file"
29+
done
30+
31+
# Update the index and upload it.
32+
for ext in "${file_exts[@]}"; do
33+
if [[ -n $path ]]; then
34+
name="$url$path$file$ext"
35+
else
36+
name="$file$ext"
37+
fi
38+
39+
grep "$name" "index.txt"
40+
if [ $? -ne 0 ]; then
41+
echo "$name" >> "index.txt"
42+
fi
43+
done
44+
45+
rbx_s3_upload "$url" "$bucket" "index.txt" || fail "unable to upload index"
46+
}
47+
48+
# Build and upload the release tarball to S3.
49+
if [[ $TRAVIS_OS_NAME == linux && $CC == clang && $RVM == "rbx-2" ]]; then
50+
echo "Deploying release tarball ${release_name}..."
51+
52+
rake release || fail "unable to build release tarball"
53+
54+
bucket="rubinius-releases-rubinius-com"
55+
56+
rbx_upload_files "$bucket" "$release_name"
57+
fi
58+
59+
# Build and upload a binary to S3.
60+
if [[ $RVM == "rbx-2" ]]; then
61+
echo "Deploying Travis binary ${release_name} for ${TRAVIS_OS_NAME}..."
62+
63+
rake package:binary || fail "unable to build binary"
64+
65+
bucket="rubinius-binaries-rubinius-com"
66+
67+
if [[ $TRAVIS_OS_NAME == linux ]]; then
68+
path="ubuntu/12.04/x86_64/"
69+
else
70+
path="osx/10.9/x86_64/"
71+
fi
72+
73+
rbx_upload_files "$bucket" "$release_name" "$path"
74+
fi

‎scripts/io.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function fail {
2+
local message=$1
3+
message=${message:=An unhandled error occurred}
4+
echo "$message at ${BASH_SOURCE[1]}:${FUNCNAME[1]} line ${BASH_LINENO[0]}." >&2
5+
exit 1
6+
}

0 commit comments

Comments
 (0)
Please sign in to comment.