Example #1
0
 def make_packages(cls, packages):
     """builds a sets of package rules and returns the dict from package
 name to package version
 Args:
   packages (list) - list of package rules to build
 Returns:
   dict from package name to package version
 Raises:
   Error - one or more of the packages could not be created
 """
     pkg_prefix = Packages.get_valid_package_prefix(
         GitUtil.get_latest_commit()[0:6])
     tmp_fn = '%d_%d' % (int(time.time()), random.randint(1, 1e5))
     cmd = 'flash --pkg_version_prefix=%s --pkg_version_path=%s run %s' % \
           (pkg_prefix, tmp_fn, ' '.join(packages))
     process = subprocess.Popen(['/bin/bash', '-c', cmd])
     process.wait()
     if not process.returncode == 0:
         if os.path.exists(tmp_fn):
             # delete the temporary package file if it exists
             os.remove(tmp_fn)
         raise Error('one of more of the packages cannot be created')
     # construct the release yaml from the temp package list
     packages = {}
     with open(tmp_fn, 'r') as f:
         packages = yaml.safe_load(f)
     os.remove(tmp_fn)  # delete the temporary package file
     return packages
Example #2
0
 def make_packages(cls, packages):
   """builds a sets of package rules and returns the dict from package
   name to package version
   Args:
     packages (list) - list of package rules to build
   Returns:
     dict from package name to package version
   Raises:
     Error - one or more of the packages could not be created
   """
   pkg_prefix = Packages.get_valid_package_prefix(
     GitUtil.get_latest_commit()[0:6])
   tmp_fn = '%d_%d' % (int(time.time()), random.randint(1, 1e5))
   cmd = 'flash --pkg_version_prefix=%s --pkg_version_path=%s run %s' % \
         (pkg_prefix, tmp_fn, ' '.join(packages))
   process = subprocess.Popen(['/bin/bash', '-c', cmd])
   process.wait()
   if not process.returncode == 0:
     if os.path.exists(tmp_fn):
       # delete the temporary package file if it exists
       os.remove(tmp_fn)
     raise Error('one of more of the packages cannot be created')
   # construct the release yaml from the temp package list
   packages = {}
   with open(tmp_fn, 'r') as f:
     packages = yaml.safe_load(f)
   os.remove(tmp_fn)  # delete the temporary package file
   return packages
Example #3
0
 def get_deployspec_name(cls, cluster_name):
   """given a cluster returns the deployspec name
   convention of $cluster-$current_branchname.
   Args:
     cluster - the cluster name
   Returns:
     the deployspec name for the current branch and cluster
   """
   return '%s-%s' % (cluster_name, GitUtil.get_current_branch())
Example #4
0
 def build_update_release(self):
   """builds the requested packages, updates the releases file including
   the cluster.yaml, commits/pushes the new releases file.
   """
   # build the packages
   try:
     packages = PackagerUtil.make_packages(self._rules)
   except PackagerUtilError:
     raise Error(
       'one or more of the packages could NOT be built. Once you fix '
       'the problem, please run update_packages again with the following '
       'rules : %s'  % ' '.join(self._rules))
   # update the releases file with the new packages and version names
   QueueClusterConfigUpdates.update_release(self._release_name, packages)
   # update the submodule to get the latest cluster info
   GitUtil.update_submodules()
   # success!
   print TermColor.ColorStr(
     'Updated releases.yaml for RULES: %s' % (' '.join(self._rules)),
     'GREEN')
Example #5
0
 def update_deployspec(cls, name, cluster, release_name):
   """
   Args:
     name (string) - the name of this deployspec
     cluster (string) - the name of the cluster
     release_name (string) - the name of this release
   """
   cmd = '%s --required_user=%s %s deployspecs %s %s %s' % (
     cls.BIN_NAME, Flags.ARGS.queue_config_user,
     GitUtil.get_current_branch(), name, cluster, release_name)
   cls._run_locked_update(cmd)
Example #6
0
 def build_update_release(self):
   """builds the requested packages, updates the releases file including
   the cluster.yaml, commits/pushes the new releases file.
   """
   # build the packages
   try:
     packages = PackagerUtil.make_packages(self._rules)
   except PackagerUtilError:
     raise Error(
       'one or more of the packages could NOT be built. Once you fix '
       'the problem, please run update_packages again with the following '
       'rules : %s'  % ' '.join(self._rules))
   # update the releases file with the new packages and version names
   QueueClusterConfigUpdates.update_release(self._release_name, packages)
   # update the submodule to get the latest cluster info
   GitUtil.update_submodules()
   # success!
   print(TermColor.ColorStr(
     'Updated releases.yaml for RULES: %s' % (' '.join(self._rules)),
     'GREEN'))
Example #7
0
 def update_release(cls, name, release_pkgs):
   """
   Args:
     name (string) - the name of this release
     release (dict) - dict from package name to package version name
   """
   pkgs_str = ''
   for pkg_name, pkg_ver in release_pkgs.iteritems():
     pkgs_str += '%s %s ' % (pkg_name, pkg_ver)
   cmd = '%s --verbose --required_user=%s %s releases %s %s' % (
     cls.BIN_NAME, Flags.ARGS.queue_config_user,
     GitUtil.get_current_branch(), name, pkgs_str)
   cls._run_locked_update(cmd)
Example #8
0
  def run(self):
    """build and create the package
    Returns:
      tuple(string, string) the package name followed by the
      package version name
    """
    if not Flags.ARGS.pkg_version_prefix:
      Flags.ARGS.pkg_version_prefix = Packages.get_valid_package_prefix(
        GitUtil.get_latest_commit()[0:6])

    version = self._packager.make_package(self._rule)
    if Flags.ARGS.pkg_version_path:
      with open(Flags.ARGS.pkg_version_path, 'a') as f:
        config = {}
        config[version[0]] = version[1]
        f.write('%s' % yaml.safe_dump(config, default_flow_style=False))
    return version