github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/scenarios/kubernetes_build.py (about)

     1  #!/usr/bin/env python
     2  
     3  # Copyright 2016 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # Need to figure out why this only fails on travis
    18  # pylint: disable=bad-continuation
    19  
    20  """Builds kubernetes with specified config"""
    21  
    22  import argparse
    23  import os
    24  import subprocess
    25  import sys
    26  
    27  
    28  def check(*cmd):
    29      """Log and run the command, raising on errors."""
    30      print >>sys.stderr, 'Run:', cmd
    31      subprocess.check_call(cmd)
    32  
    33  
    34  def main(args):
    35      """Build and push kubernetes.
    36  
    37      This is a python port of the kubernetes/hack/jenkins/build.sh script.
    38      """
    39      if os.path.split(os.getcwd())[-1] != 'kubernetes':
    40          print >>sys.stderr, (
    41              'Scenario should only run from a kubernetes directory!')
    42          sys.exit(1)
    43      env = {
    44          # Skip gcloud update checking; do we still need this?
    45          'CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK': 'true',
    46          # Don't run any unit/integration tests when building
    47          'KUBE_RELEASE_RUN_TESTS': 'n',
    48      }
    49      push_build_args = ['--nomock', '--verbose', '--ci']
    50      if args.suffix:
    51          push_build_args.append('--gcs-suffix=%s' % args.suffix)
    52      if args.federation:
    53          # TODO: do we need to set these?
    54          env['PROJECT'] = args.federation
    55          env['FEDERATION_PUSH_REPO_BASE'] = 'gcr.io/%s' % args.federation
    56          push_build_args.append('--federation')
    57      if args.release:
    58          push_build_args.append('--bucket=%s' % args.release)
    59      if args.registry:
    60          push_build_args.append('--docker-registry=%s' % args.registry)
    61      if args.hyperkube:
    62          env['KUBE_BUILD_HYPERKUBE'] = 'y'
    63      if args.extra_publish_file:
    64          push_build_args.append('--extra-publish-file=%s' % args.extra_publish_file)
    65  
    66      for key, value in env.items():
    67          os.environ[key] = value
    68      check('make', 'clean')
    69      if args.fast:
    70          check('make', 'quick-release')
    71      else:
    72          check('make', 'release')
    73      check('../release/push-build.sh', *push_build_args)
    74  
    75  if __name__ == '__main__':
    76      PARSER = argparse.ArgumentParser(
    77          'Build and push.')
    78      PARSER.add_argument('--fast', action='store_true', help='Build quickly')
    79      PARSER.add_argument(
    80          '--release', help='Upload binaries to the specified gs:// path')
    81      PARSER.add_argument(
    82          '--suffix', help='Append suffix to the upload path if set')
    83      PARSER.add_argument(
    84          '--federation',
    85          help='Push federation images to the specified project')
    86      PARSER.add_argument(
    87          '--registry', help='Push images to the specified docker registry')
    88      PARSER.add_argument(
    89          '--hyperkube', action='store_true', help='Build hyperkube image')
    90      PARSER.add_argument(
    91          '--extra-publish-file', help='Additional version file uploads to')
    92      ARGS = PARSER.parse_args()
    93      main(ARGS)