forked from gocd/build_utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demote-from-stable
executable file
·61 lines (47 loc) · 2.64 KB
/
demote-from-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
#!/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_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 :demote_artifacts do
$stderr.puts "*** Demoting version #{go_full_version} from stable"
sh("AWS_PROFILE=update aws s3 cp s3://#{S3_UPDATE_CHECK_BUCKET}/channels/supported/latest.previous.json s3://#{S3_UPDATE_CHECK_BUCKET}/channels/supported/latest.json --cache-control 'max-age=600' --acl public-read")
sh("aws s3 rm --recursive s3://#{S3_STABLE_BUCKET}/binaries/#{go_full_version}/")
sh("aws s3 rm --recursive s3://#{S3_ADDONS_STABLE_BUCKET}/#{go_full_version}/")
sh("./create-repositories-stable")
end
task :remove_version_from_extensions_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_addon_metadata.remove_version(go_full_version)
bc_addon_metadata.remove_version(go_full_version)
pg_addon_metadata.upload_combined_metadata_file
bc_addon_metadata.upload_combined_metadata_file
end
task default: [:demote_artifacts, :remove_version_from_extensions_metadata]