Skip to content

Commit

Permalink
feat(bom): Script to 'promote' BOM for release. (#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtk54 committed Mar 6, 2017
1 parent 4d3f722 commit 70514dc
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dev/generate_bom.py
Expand Up @@ -99,13 +99,13 @@ def write_bom(self):
toplevel_with_build = '{0}-{1}'.format(toplevel_version, self.build_number)
output_yaml[VERSION] = toplevel_with_build
self.__bom_file = '{0}.yml'.format(toplevel_with_build)
self.__write_bom(self.__bom_file, output_yaml)
self.__publish_bom(self.__bom_file)
self.write_bom_file(self.__bom_file, output_yaml)
self.publish_bom(self.__bom_file)
output_yaml[VERSION] = 'nightly'
self.__write_bom('nightly.yml', output_yaml) # Publish a 'nightly' BOM for folks wanting to run bleeding-edge Spinnaker.
self.__publish_bom('nightly.yml')
self.write_bom_file('nightly.yml', output_yaml) # Publish a 'nightly' BOM for folks wanting to run bleeding-edge Spinnaker.
self.publish_bom('nightly.yml')

def __write_bom(self, filename, output_yaml):
def write_bom_file(self, filename, output_yaml):
"""Helper function to write the calculated BOM to files.
Args:
Expand All @@ -120,7 +120,7 @@ def __write_bom(self, filename, output_yaml):
yaml.dump(output_yaml, output_file, default_flow_style=False)
print 'Wrote BOM to {0}.'.format(filename)

def __publish_bom(self, bom_path):
def publish_bom(self, bom_path):
"""Publishes the BOM using Halyard.
Assumes that Halyard is installed and correctly configured on the current
Expand Down
81 changes: 81 additions & 0 deletions dev/promote_bom.py
@@ -0,0 +1,81 @@
#!/usr/bin/python
#
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import sys
import yaml

from generate_bom import BomGenerator
from spinnaker.run import run_quick

VERSION = 'version'

class BomPromoter(BomGenerator):

def __init__(self, options):
self.__rc_version = options.rc_version
self.__bom_dict = {}
super(BomPromoter, self).__init__(options)

def __unpack_bom(self):
"""Load the release candidate BOM into memory.
"""
bom_yaml_string = run_quick('hal versions bom {0} --color false'
.format(self.__rc_version), echo=False).stdout.strip()
print bom_yaml_string
self.__bom_dict = yaml.load(bom_yaml_string)
print self.__bom_dict

def promote_bom(self):
"""Read, update, and promote a release candidate BOM.
"""
self.__unpack_bom()
dash_idx = self.__rc_version.index('-')
if dash_idx == -1:
raise Exception('Malformed Spinnaker release candidate version: {0}.'
.format(self.__rc_version))
# Chop off build number for BOM promotion.
new_version = self.__rc_version[:dash_idx]
print new_version
new_bom_file = '{0}.yml'.format(new_version)
self.__bom_dict[VERSION] = new_version
self.write_bom_file(new_bom_file, self.__bom_dict)
self.publish_bom(new_bom_file)
# Re-write the 'latest' Spinnaker version.
# TODO(jacobkiefer): Update 'available versions' with Halyard when that feature is ready.
self.write_bom_file('latest.yml', self.__bom_dict)
self.publish_bom('latest.yml')

@classmethod
def main(cls):
parser = argparse.ArgumentParser()
cls.init_argument_parser(parser)
options = parser.parse_args()

bom_promoter = cls(options)
bom_promoter.promote_bom()

@classmethod
def init_argument_parser(cls, parser):
"""Initialize command-line arguments."""
parser.add_argument(
'--rc_version', default='', required=True,
help='The version of the Spinnaker release candidate we are promoting.'
'We derive the promoted version from the release candidate version.')
super(BomPromoter, cls).init_argument_parser(parser)

if __name__ == '__main__':
sys.exit(BomPromoter.main())

0 comments on commit 70514dc

Please sign in to comment.