forked from gocd/build_utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promote-to-stable
executable file
·76 lines (56 loc) · 3.91 KB
/
promote-to-stable
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
#!/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 'json'
require 'open-uri'
require 'yaml'
require_relative 'lib/addon_metadata.rb'
S3_BUCKET_CONFIG = YAML.load(File.read(File.expand_path('~/.s3.yml')))
S3_EXPERIMENTAL_BUCKET = S3_BUCKET_CONFIG[ENV['S3_EXPERIMENTAL_BUCKET_TYPE'] || 'downloads-experimental']
S3_STABLE_BUCKET = S3_BUCKET_CONFIG[ENV['S3_STABLE_BUCKET_TYPE'] || 'downloads-stable']
S3_ADDONS_EXPERIMENTAL_BUCKET = S3_BUCKET_CONFIG[ENV['S3_ADDONS_EXPERIMENTAL_BUCKET_TYPE'] || 'addons-experimental']
S3_ADDONS_STABLE_BUCKET = S3_BUCKET_CONFIG[ENV['S3_ADDONS_STABLE_BUCKET_TYPE'] || 'addons-stable']
S3_UPDATE_CHECK_BUCKET = S3_BUCKET_CONFIG[ENV['UPDATE_CHECK_BUCKET_TYPE'] || 'update-check']
job_identifier = ENV['INSTALLER_JOB_IDENTIFIER']
username = ENV['ARTIFACT_FETCH_USERNAME'] || 'view'
password = ENV['ARTIFACT_FETCH_PASSWORD'] || 'password'
version_info = JSON.parse(open("https://build.gocd.org/go/files/#{job_identifier}/dist/meta/version.json", 'r', http_basic_authentication: [username, password]).read)
go_full_version = version_info['go_full_version']
task :promote_artifacts_to_stable do
$stderr.puts "*** Promoting version #{go_full_version} to stable"
sh("aws s3 sync s3://#{S3_EXPERIMENTAL_BUCKET}/binaries/#{go_full_version} s3://#{S3_STABLE_BUCKET}/binaries/#{go_full_version} --acl public-read --cache-control 'max-age=31536000'")
sh("AWS_PROFILE=extensions aws s3 sync s3://#{S3_ADDONS_EXPERIMENTAL_BUCKET}/#{go_full_version} s3://#{S3_ADDONS_STABLE_BUCKET}/#{go_full_version} --acl private --cache-control 'max-age=31536000'")
sh("./create-repositories-stable")
sh("AWS_PROFILE=update aws s3 cp s3://#{S3_UPDATE_CHECK_BUCKET}/channels/supported/latest.json s3://#{S3_UPDATE_CHECK_BUCKET}/channels/supported/latest.previous.json --cache-control 'max-age=600' --acl public-read")
sh("aws s3 cp s3://#{S3_EXPERIMENTAL_BUCKET}/binaries/#{go_full_version}/latest.json /tmp/latest.json")
sh("AWS_PROFILE=update aws s3 cp /tmp/latest.json s3://#{S3_UPDATE_CHECK_BUCKET}/channels/supported/latest.json --cache-control 'max-age=600' --acl public-read")
sh("AWS_PROFILE=update aws s3 cp /tmp/latest.json s3://#{S3_UPDATE_CHECK_BUCKET}/channels/supported/latest-#{go_full_version}.json --cache-control 'max-age=600' --acl public-read")
sh("rm /tmp/latest.json")
end
task :update_addons_metadata do
path_without_bucket_name = S3_ADDONS_STABLE_BUCKET.sub(%r{^[^/]+/}, '')
pg_addon_metadata = AddonMetadata.new(
addon_file_s3_parent: "#{path_without_bucket_name}/#{go_full_version}",
metadata_full_s3_path: "s3://#{S3_ADDONS_STABLE_BUCKET}/go-postgresql.json",
version: go_full_version,
prefix: 'pg'
)
bc_addon_metadata = AddonMetadata.new(
addon_file_s3_parent: "#{path_without_bucket_name}/#{go_full_version}",
metadata_full_s3_path: "s3://#{S3_ADDONS_STABLE_BUCKET}/go-business-continuity.json",
version: go_full_version,
prefix: 'bc'
)
pg_metadata_file = Tempfile.new(['pg_metadata', '.json'], Dir.tmpdir)
sh("AWS_PROFILE=extensions aws s3 cp s3://#{S3_ADDONS_EXPERIMENTAL_BUCKET}/#{go_full_version}/pg_metadata.json #{pg_metadata_file.path}")
pg_addon_metadata.append_to_existing(JSON.parse(File.read(pg_metadata_file.path)))
bc_metadata_file = Tempfile.new(['bc_metadata', '.json'], Dir.tmpdir)
sh("AWS_PROFILE=extensions aws s3 cp s3://#{S3_ADDONS_EXPERIMENTAL_BUCKET}/#{go_full_version}/bc_metadata.json #{bc_metadata_file.path}")
bc_addon_metadata.append_to_existing(JSON.parse(File.read(bc_metadata_file.path)))
pg_addon_metadata.upload_combined_metadata_file
bc_addon_metadata.upload_combined_metadata_file
end
task default: [:promote_artifacts_to_stable, :update_addons_metadata]