def upload_app_version(app_name, bundled_zip): """ Uploading zip file of app version to S3 :param app_name: application name to deploy :param bundled_zip: String path to zip file :return: bucket name and key for file (as tuple). """ bucket = elasticbeanstalk.get_storage_location() key = app_name + '/' + os.path.basename(bundled_zip) try: ebs3.get_object_info(bucket, key) logger.info('S3 Object already exists. Skipping upload.') except NotFoundError: logger.info('Uploading archive to s3 location: ' + key) ebs3.upload_application_version(bucket, key, bundled_zip) return bucket, key
def __upload_app_version(app_name, bundled_file): ''' Uploading zip file of app version to S3 ''' bucket = elasticbeanstalk.get_storage_location() print("Bucket to deploy bundle '{}'".format(bucket)) key = app_name + '/' + os.path.basename(bundled_file) print("'{}' Location of the bundle ".format(key)) try: s3.get_object_info(bucket, key) except NotFoundError: print ("Uploading archive to S3") s3.upload_application_version(bucket, key, bundled_file) finally: os.remove(bundled_zip) return bucket, key
def create_app_version(app_name, process=False, label=None, message=None, staged=False, build_config=None): cwd = os.getcwd() fileoperations.ProjectRoot.traverse() try: if heuristics.directory_is_empty(): io.echo('NOTE: {}'.format(strings['appversion.none'])) return None finally: os.chdir(cwd) source_control = SourceControl.get_source_control() if source_control.untracked_changes_exist(): io.log_warning(strings['sc.unstagedchanges']) if label: version_label = label else: version_label = source_control.get_version_label() if staged: timestamp = datetime.now().strftime("%y%m%d_%H%M%S") version_label = version_label + '-stage-' + timestamp if message: description = message else: description = source_control.get_message() if len(description) > 200: description = description[:195] + '...' artifact = fileoperations.get_config_setting('deploy', 'artifact') if artifact: file_name, file_extension = os.path.splitext(artifact) file_name = version_label + file_extension file_path = artifact s3_key = None s3_bucket = None else: s3_bucket, s3_key = get_app_version_s3_location(app_name, version_label) if s3_bucket is None and s3_key is None: file_name, file_path = _zip_up_project( version_label, source_control, staged=staged) else: file_name = None file_path = None bucket = elasticbeanstalk.get_storage_location() if s3_bucket is None else s3_bucket key = app_name + '/' + file_name if s3_key is None else s3_key try: s3.get_object_info(bucket, key) io.log_info('S3 Object already exists. Skipping upload.') except NotFoundError: if file_name is None and file_path is None: raise NotFoundError('Application Version does not exist in the S3 bucket.' ' Try uploading the Application Version again.') io.log_info('Uploading archive to s3 location: ' + key) s3.upload_application_version(bucket, key, file_path) fileoperations.delete_app_versions() io.log_info('Creating AppVersion ' + version_label) return _create_application_version(app_name, version_label, description, bucket, key, process, build_config=build_config)
def create_app_version(app_name, process=False, label=None, message=None, staged=False, build_config=None): cwd = os.getcwd() fileoperations._traverse_to_project_root() try: if heuristics.directory_is_empty(): io.echo('NOTE: {}'.format(strings['appversion.none'])) return None finally: os.chdir(cwd) source_control = SourceControl.get_source_control() if source_control.untracked_changes_exist(): io.log_warning(strings['sc.unstagedchanges']) #get version_label if label: version_label = label else: version_label = source_control.get_version_label() if staged: # Make a unique version label timestamp = datetime.now().strftime("%y%m%d_%H%M%S") version_label = version_label + '-stage-' + timestamp # get description if message: description = message else: description = source_control.get_message() if len(description) > 200: description = description[:195] + '...' # Check for zip or artifact deploy artifact = fileoperations.get_config_setting('deploy', 'artifact') if artifact: file_name, file_extension = os.path.splitext(artifact) file_name = version_label + file_extension file_path = artifact s3_key = None s3_bucket = None else: # Check if the app version already exists s3_bucket, s3_key = get_app_version_s3_location( app_name, version_label) # Create zip file if the application version doesn't exist if s3_bucket is None and s3_key is None: file_name, file_path = _zip_up_project(version_label, source_control, staged=staged) else: file_name = None file_path = None # Get s3 location bucket = elasticbeanstalk.get_storage_location( ) if s3_bucket is None else s3_bucket key = app_name + '/' + file_name if s3_key is None else s3_key # Upload to S3 if needed try: s3.get_object_info(bucket, key) io.log_info('S3 Object already exists. Skipping upload.') except NotFoundError: # If we got the bucket/key from the app version describe call and it doesn't exist then # the application version must have been deleted out-of-band and we should throw an exception if file_name is None and file_path is None: raise NotFoundError( 'Application Version does not exist in the S3 bucket.' ' Try uploading the Application Version again.') # Otherwise attempt to upload the local application version io.log_info('Uploading archive to s3 location: ' + key) s3.upload_application_version(bucket, key, file_path) fileoperations.delete_app_versions() io.log_info('Creating AppVersion ' + version_label) return _create_application_version(app_name, version_label, description, bucket, key, process, build_config=build_config)