From 19ff7a8fcbf18f92f754e201bd2abdba7ee98734 Mon Sep 17 00:00:00 2001 From: Geert Jansen Date: Wed, 7 Sep 2016 15:55:09 -0400 Subject: [PATCH] vmpublish.rb: publish public images This script publishes builds from a previous vmbuild.rb invocation to any of the configurated public directories. Currently this means Atlas (for Vagrant images) and GCE (for GCE images). This code could probably use a similar metadata driven approach as vmbuild.rb. However for now I believe the current approach of hardcoding some of the calling conventions and parameters for each of the supported targets works. --- .gitignore | 1 + bin/release-build.sh | 7 +++- config/creds/README.creds | 21 ++++++++++ scripts/config.rb | 15 ++++++++ scripts/vmbuild.rb | 19 ++-------- scripts/vmpublish.rb | 80 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 config/creds/README.creds create mode 100644 scripts/config.rb create mode 100644 scripts/vmpublish.rb diff --git a/.gitignore b/.gitignore index ad89d990..4a6c9e4f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /productization kickstarts/generated/*.ks scripts/Gemfile.dev.rb +config/creds/*.json diff --git a/bin/release-build.sh b/bin/release-build.sh index d86e9954..3781f58e 100755 --- a/bin/release-build.sh +++ b/bin/release-build.sh @@ -12,5 +12,10 @@ if [[ $# != 1 ]]; then fi log_file="/build/logs/${1}.log" -nohup time ruby ${BUILD_DIR}/scripts/vmbuild.rb --type release --upload --reference $1 --copy-dir ${1%%-*} > $log_file 2>&1 & +copy_dir="${1%%-*}" + +nohup sh -c \ + "echo time ruby ${BUILD_DIR}/scripts/vmbuild.rb --type release --upload --reference $1 --copy-dir $copy_dir \ + && time ruby ${BUILD_DIR}/scripts/vmpublish.rb --copy-dir $copy_dir" \ + > $log_file 2>&1 & echo "${1} release build kicked off, see log @ $log_file ..." diff --git a/config/creds/README.creds b/config/creds/README.creds new file mode 100644 index 00000000..752632ef --- /dev/null +++ b/config/creds/README.creds @@ -0,0 +1,21 @@ +This directory will hold credentials files on the build host. + +All JSON files in this directory are ignored via gitignore(5) to reduce the +risk that credentials accentally get commit. + +The following files are currently used: + +* gce.json + + A service account JSON file for the Google Cloud Platform. This file can be + generated as describe here: + https://cloud.google.com/storage/docs/authentication#generating-a-private-key + +* atlas.json + + A JSON file with an Atlas token, as follows: + + { + "username": "", + "token": " :string, :short => 'd', :default => "master" + opt :type, type_desc, :type => :string, :short => 't', :default => "stable" +end + +copy_dir = FILESHARE_DIR.join(options[:copy_dir], options[:type]) + +Dir.foreach(copy_dir) do |filename| + next if ['.', '..'].include? filename + + parts = filename.split('.').first.split('-') + next unless parts.length >= 6 # only release builds, which are build from a tag (name-version) + next unless parts[0] == 'manageiq' + target = parts[1] + next unless ['vagrant', 'gce'].include? target + reference = parts[2] + version = parts[3..parts.length-3].join('-') + + image = copy_dir.join(filename) + uuid = find_imgfac_image(image) + + $log.info "processing image: #{image}" + $log.info "target = #{target}, reference = #{reference}, version = #{version}" + $log.info "imagefactory image = #{uuid}" + + upload_imgfac_image(uuid, target, reference, version) +end