forked from gocd/build_utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-addon-release
executable file
·91 lines (73 loc) · 3.5 KB
/
create-addon-release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env ruby
if File.basename($PROGRAM_NAME) != 'rake'
require 'shellwords'
puts "bundle exec rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
exec "bundle exec rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
end
require 'rubygems'
require 'json'
require 'open-uri'
require 'pathname'
require 'yaml'
require_relative 'lib/addon_metadata.rb'
S3_BUCKET_CONFIG = YAML.load(File.read(File.expand_path('~/.s3.yml')))
S3_BUCKET = S3_BUCKET_CONFIG[ENV['BUCKET_TYPE'] || 'addons-experimental']
full_version = ENV['CORRESPONDING_GOCD_VERSION'] || (fail 'CORRESPONDING_GOCD_VERSION not set')
go_server_url = ENV['GO_SERVER_URL'] || (fail 'GO_SERVER_URL not set')
go_dependency_locator_go_postgresql_build = ENV['GO_DEPENDENCY_LOCATOR_GO_POSTGRESQL_BUILD'] || (fail 'GO_DEPENDENCY_LOCATOR_GO_POSTGRESQL_BUILD not set')
credentials = ENV['CREDENTIALS'] || (fail 'CREDENTIALS not set')
target_dir = Pathname.new('target')
addons_dir = target_dir.join('s3', full_version)
path_without_bucket_name = S3_BUCKET.sub(%r{^[^/]+/}, '')
pg_addon_metadata = AddonMetadata.new(
addon_file_s3_parent: "#{path_without_bucket_name}/#{full_version}",
metadata_full_s3_path: "s3://#{S3_BUCKET}/go-postgresql.json",
version: full_version,
prefix: 'pg'
)
bc_addon_metadata = AddonMetadata.new(
addon_file_s3_parent: "#{path_without_bucket_name}/#{full_version}",
metadata_full_s3_path: "s3://#{S3_BUCKET}/go-business-continuity.json",
version: full_version,
prefix: 'bc'
)
task :clean do
rm_rf target_dir
end
task :init do
mkdir_p target_dir
end
task :fetch_addons do
cd 'target' do
bc_url = JSON.parse(open("#{go_server_url}/files/#{go_dependency_locator_go_postgresql_build}/business-continuity/business-continuity-addon.json", 'r', http_basic_authentication: credentials.split(':')).read).find_all {|f| f['name'] =~ /go-business.*.jar/ && f['type'] == 'file'}.first['url']
pg_url = JSON.parse(open("#{go_server_url}/files/#{go_dependency_locator_go_postgresql_build}/postgresql/postgresql-addon.json", 'r', http_basic_authentication: credentials.split(':')).read).find_all {|f| f['name'] =~ /go-postgresql.*.jar/ && f['type'] == 'file'}.first['url']
mkdir_p 'addons'
cd 'addons' do
sh("curl --fail --silent --user #{credentials} #{bc_url} -O")
sh("curl --fail --silent --user #{credentials} #{pg_url} -O")
end
end # cd target
end
task :prepare_addons_for_upload do
rm_rf addons_dir
mkdir_p addons_dir
Dir['target/addons/*.jar'].each do |addon|
cp addon, addons_dir
end
cd addons_dir do
sh('md5sum *.jar > addons-md5.checksum')
sh('sha1sum *.jar > addons-sha1.checksum')
sh('sha256sum *.jar > addons-sha256.checksum')
sh('sha512sum *.jar > addons-sha512.checksum')
end
pg_metadata_file = pg_addon_metadata.create(Dir[addons_dir.join('go-postgresql*.jar')].first)
pg_addon_metadata.append_to_existing(JSON.parse(File.read(pg_metadata_file)))
bc_metadata_file = bc_addon_metadata.create(Dir[addons_dir.join('go-business-continuity*.jar')].first)
bc_addon_metadata.append_to_existing(JSON.parse(File.read(bc_metadata_file)))
end
task :upload do
sh("AWS_PROFILE=extensions aws s3 sync #{addons_dir} s3://#{S3_BUCKET}/#{full_version} --acl private --cache-control 'max-age=31536000'")
pg_addon_metadata.upload_combined_metadata_file
bc_addon_metadata.upload_combined_metadata_file
end
task default: [:clean, :init, :fetch_addons, :prepare_addons_for_upload, :upload]