sregistry/main/google_build/build.py
def build(self, name,
                recipe="Singularity",
                context=None, 
                preview=False):

    '''trigger a build on Google Cloud (builder then storage) given a name
       recipe, and Github URI where the recipe can be found.
    
       Parameters
       ==========
       recipe: the local recipe to build.
       name: should be the complete uri that the user has requested to push.
       context: the dependency files needed for the build. If not defined, only
                the recipe is uploaded.
       preview: if True, preview but don't run the build

       Environment
       ===========
       SREGISTRY_GOOGLE_BUILD_SINGULARITY_VERSION: the version of Singularity
           to use, defaults to 3.0.2-slim
       SREGISTRY_GOOGLE_BUILD_CLEANUP: after build, delete intermediate 
           dependencies in cloudbuild bucket.

    '''
    bot.debug("BUILD %s" % recipe)

    # This returns a data structure with collection, container, based on uri
    names = parse_image_name(remove_uri(name))

    # Load the build configuration
    config = self._load_build_config(name=names['uri'], recipe=recipe)

    build_package = [recipe]
    if context not in [None, '', []]:

        # If the user gives a ., include recursive $PWD
        if '.' in context:
            context = glob(os.getcwd() + '/**/*', recursive=True)
        build_package = build_package + context
        
    package = create_build_package(build_package)

    # Does the package already exist? If the user cached, it might
    destination='source/%s' % os.path.basename(package)
    blob = self._build_bucket.blob(destination)

    # if it doesn't exist, upload it
    if not blob.exists() and preview is False:
        bot.log('Uploading build package!')
        manifest = self._upload(source=package, 
                                bucket=self._build_bucket,
                                destination=destination)
    else:
        bot.log('Build package found in %s.' % self._build_bucket.name)

    # The source should point to the bucket with the .tar.gz, latest generation
    config["source"]["storageSource"]['bucket'] = self._build_bucket.name
    config["source"]["storageSource"]['object'] = destination

    # If not a preview, run the build and return the response
    if preview is False:
        config = self._run_build(config, self._bucket, names)

    # If the user wants to cache cloudbuild files, this will be set
    if not self._get_and_update_setting('SREGISTRY_GOOGLE_BUILD_CACHE'):
        blob.delete()

    # Clean up either way, return config or response
    shutil.rmtree(os.path.dirname(package))
    return config
def build(self, name,
                recipe="Singularity",
                context=None, 
                preview=False):

    '''trigger a build on Google Cloud (builder then storage) given a name
       recipe, and Github URI where the recipe can be found.
    
       Parameters
       ==========
       recipe: the local recipe to build.
       name: should be the complete uri that the user has requested to push.
       context: the dependency files needed for the build. If not defined, only
                the recipe is uploaded.
       preview: if True, preview but don't run the build

       Environment
       ===========
       SREGISTRY_GOOGLE_BUILD_SINGULARITY_VERSION: the version of Singularity
           to use, defaults to 3.0.2-slim
       SREGISTRY_GOOGLE_BUILD_CLEANUP: after build, delete intermediate 
           dependencies in cloudbuild bucket.

    '''
    bot.debug("BUILD %s" % recipe)

    # This returns a data structure with collection, container, based on uri
    names = parse_image_name(remove_uri(name))

    # Load the build configuration
    config = self._load_build_config(name=names['uri'], recipe=recipe)

    build_package = [recipe]
    if context not in [None, '', []]:

        # If the user gives a ., include recursive $PWD
        if '.' in context:
            context = glob(os.getcwd() + '/**/*', recursive=True)
        build_package = build_package + context
        
    package = create_build_package(build_package)

    # Does the package already exist? If the user cached, it might
    destination='source/%s' % os.path.basename(package)
    blob = self._build_bucket.blob(destination)

    # if it doesn't exist, upload it
    if not blob.exists() and preview is False:
        bot.log('Uploading build package!')
        manifest = self._upload(source=package, 
                                bucket=self._build_bucket,
                                destination=destination)
    else:
        bot.log('Build package found in %s.' % self._build_bucket.name)

    # The source should point to the bucket with the .tar.gz, latest generation
    config["source"]["storageSource"]['bucket'] = self._build_bucket.name
    config["source"]["storageSource"]['object'] = destination

    # If not a preview, run the build and return the response
    if preview is False:
        config = self._run_build(config, self._bucket, names)

    # If the user wants to cache cloudbuild files, this will be set
    if not self._get_and_update_setting('SREGISTRY_GOOGLE_BUILD_CACHE'):
        blob.delete()

    # Clean up either way, return config or response
    shutil.rmtree(os.path.dirname(package))
    return config
def build ( self , name , recipe = "Singularity" , context = None , preview = False ) : bot . debug ( "BUILD %s" % recipe ) # This returns a data structure with collection, container, based on uri names = parse_image_name ( remove_uri ( name ) ) # Load the build configuration config = self . _load_build_config ( name = names [ 'uri' ] , recipe = recipe ) build_package = [ recipe ] if context not in [ None , '' , [ ] ] : # If the user gives a ., include recursive $PWD if '.' in context : context = glob ( os . getcwd ( ) + '/**/*' , recursive = True ) build_package = build_package + context package = create_build_package ( build_package ) # Does the package already exist? If the user cached, it might destination = 'source/%s' % os . path . basename ( package ) blob = self . _build_bucket . blob ( destination ) # if it doesn't exist, upload it if not blob . exists ( ) and preview is False : bot . log ( 'Uploading build package!' ) manifest = self . _upload ( source = package , bucket = self . _build_bucket , destination = destination ) else : bot . log ( 'Build package found in %s.' % self . _build_bucket . name ) # The source should point to the bucket with the .tar.gz, latest generation config [ "source" ] [ "storageSource" ] [ 'bucket' ] = self . _build_bucket . name config [ "source" ] [ "storageSource" ] [ 'object' ] = destination # If not a preview, run the build and return the response if preview is False : config = self . _run_build ( config , self . _bucket , names ) # If the user wants to cache cloudbuild files, this will be set if not self . _get_and_update_setting ( 'SREGISTRY_GOOGLE_BUILD_CACHE' ) : blob . delete ( ) # Clean up either way, return config or response shutil . rmtree ( os . path . dirname ( package ) ) return config
trigger a build on Google Cloud (builder then storage) given a name
       recipe, and Github URI where the recipe can be found.
    
       Parameters
       ==========
       recipe: the local recipe to build.
       name: should be the complete uri that the user has requested to push.
       context: the dependency files needed for the build. If not defined, only
                the recipe is uploaded.
       preview: if True, preview but don't run the build

       Environment
       ===========
       SREGISTRY_GOOGLE_BUILD_SINGULARITY_VERSION: the version of Singularity
           to use, defaults to 3.0.2-slim
       SREGISTRY_GOOGLE_BUILD_CLEANUP: after build, delete intermediate 
           dependencies in cloudbuild bucket.
trigger a build on Google Cloud ( builder then storage ) given a name recipe and Github URI where the recipe can be found . Parameters ========== recipe : the local recipe to build . name : should be the complete uri that the user has requested to push . context : the dependency files needed for the build . If not defined only the recipe is uploaded . preview : if True preview but don t run the build