Skip to content

Commit

Permalink
Merge pull request #13 from lubomir/misc-fixes
Browse files Browse the repository at this point in the history
Fixes for nexus-push
  • Loading branch information
jdcasey committed May 16, 2019
2 parents 0ee5fa3 + 7fd2bca commit 708fe07
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 375 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE
20 changes: 12 additions & 8 deletions rcm_nexus/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def create_partitioned_zips_from_zip(src, out_dir, max_count=MAX_COUNT, max_size
zips = Zipper(out_dir, max_count, max_size)
zf = zipfile.ZipFile(src)
for info in zf.infolist():
if info.filename.endswith("/") and info.file_size == 0:
# Skip directories
continue

# print "Path: %s (uncompressed size: %s)" % (info.filename, info.file_size)
zips.append(info.filename, info.file_size, lambda: zf.read(info.filename) )
Expand All @@ -58,22 +61,23 @@ def append(self, filename, size, stream_func):
if self.zip is None or self.file_count >= self.max_count or self.file_size + size >= self.max_size:
if self.zip is not None:
self.zip.close()
self.counter+=1
self.counter += 1
self.file_count = 0
self.file_size = 0

self.zip = zipfile.ZipFile(os.path.join(self.out_dir, OUT_ZIP_FORMAT % self.counter), mode='w')

if '/' in filename:
filename_parts = filename.split('/')

if 'maven' in filename_parts[0]:
if len(filename_parts) > 1:
filename = '/'.join(filename_parts[1:])
else:
filename = ''
while filename_parts and "maven-repository" in filename_parts[0]:
del filename_parts[0]

filename = "/".join(filename_parts)

self.zip.writestr(filename, stream_func())
self.file_count+=1
self.file_size+=size
self.file_count += 1
self.file_size += size

def close(self):
if self.zip is not None:
Expand Down
61 changes: 24 additions & 37 deletions rcm_nexus/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
from rcm_nexus.session import Session
import rcm_nexus.config as config
import rcm_nexus.repo as repos
import rcm_nexus.group as groups
import rcm_nexus.archive as archive
import rcm_nexus.staging as staging
import os.path
import sys
import re
import click
import shutil
import tempfile

RELEASE_GROUP_NAME = 'product-ga'
TECHPREVIEW_GROUP_NAME = 'product-techpreview'
PRERELEASE_GROUP_NAME = 'product-earlyaccess'

@click.command()
def init():
Expand Down Expand Up @@ -52,12 +48,7 @@ def push(repo, environment, product, version, ga=False, debug=False):
More Information: https://mojo.redhat.com/docs/DOC-1132234
"""

nexus_config = config.load(environment, debug)

if release:
groups = [RELEASE_GROUP_NAME, TECHPREVIEW_GROUP_NAME]
else:
groups = [PRERELEASE_GROUP_NAME]
nexus_config = config.load(environment, debug=debug)

session = Session(nexus_config, debug=debug)

Expand All @@ -78,56 +69,52 @@ def push(repo, environment, product, version, ga=False, debug=False):
# Open the zip, walk the entries and normalize the structure to clean zip (if necessary)
zip_paths = archive.create_partitioned_zips_from_zip(repo, zips_dir)


# Open new staging repository with description
staging_repo_id = staging.start_staging_repo(session, nexus_config, product, version, ga)

# HTTP PUT clean repository zips to Nexus.
delete_first = True
for zipfile in zip_paths:
repo.push_zip(session, staging_repo_id, zipfile, delete_first)
for idx, zipfile in enumerate(zip_paths, start=1):
print("Uploading zip %s out of %s" % (idx, len(zip_paths)))
repos.push_zip(session, staging_repo_id, zipfile, delete_first)
delete_first = False

# Close staging repository
staging.finish_staging_repo(session, nexus_config, staging_repo_id, product, version, ga)

for group_id in groups:
group = groups.load(session, group_id, ignore_missing=True)
if group is not None:
print "Adding %s to group: %s" % (staging_repo_id, group_id)
if staging.verify_action(session, staging_repo_id, "close"):
sys.exit(1)

print("Promoting repo")
promote_profile = nexus_config.get_promote_profile_id(ga)
staging.promote(session, promote_profile, staging_repo_id, product, version, ga)

group.append_member(session, staging_repo_id).save(session)
else:
print "No such group: %s" % group_id
raise Exception("No such group: %s" % group_id)
if staging.verify_action(session, staging_repo_id, "promote"):
sys.exit(1)
finally:
if session is not None:
session.close()


shutil.rmtree(zips_dir)


@click.command()
@click.argument('staging_repo_name')
@click.option('--environment', '-e', help='The target Nexus environment (from ~/.config/rcm-nexus/config.yaml)')
@click.option('--debug', '-D', is_flag=True, default=False)
def rollback(args, config, session, delete_log=None, debug=False):
"""Remove the given staging repository from all release groups
def rollback(staging_repo_name, environment, debug=False):
"""Drop given staging repository.
More Information: https://mojo.redhat.com/docs/DOC-1132234
"""
nexus_config = config.load(environment, debug=debug)

nexus_config = config.load(environment, debug)

groups = [RELEASE_GROUP_NAME, TECHPREVIEW_GROUP_NAME, PRERELEASE_GROUP_NAME]
session = Session(nexus_config, debug=debug)

session = Session(config.base_url, user, debug=debug, disable_ssl_validation=config.permissive_ssl, preemptive_auth=config.preemptive_auth)

try:
print "Removing content of: %s" % staging_repo_name

for group_name in groups:
group = groups.load(session, group_name, True)
if group is not None:
print "Removing %s from group %s" % (staging_repo_name, group_name)
group.remove_member(session, staging_repo_name).save(session)
print "Dropping repository %s" % staging_repo_name
if not staging.drop_staging_repo(session, staging_repo_name):
sys.exit(1)
finally:
if session is not None:
session.close()
10 changes: 10 additions & 0 deletions rcm_nexus/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
SSL_VERIFY = 'ssl-verify'
PREEMPTIVE_AUTH = 'preemptive-auth'
INTERACTIVE = 'interactive'
GA_PROMOTE_PROFILE = "ga-promote-profile"
EA_PROMOTE_PROFILE = "ea-promote-profile"

GA_PROFILE = 'ga'
EA_PROFILE = 'ea'
Expand All @@ -26,6 +28,8 @@ def __init__(self, name, data, profile_data):
self.password = data.get(PASSWORD, None)
self.interactive = data.get(INTERACTIVE, True)
self.profile_map = profile_data
self.ga_promote_profile = data.get(GA_PROMOTE_PROFILE)
self.ea_promote_profile = data.get(EA_PROMOTE_PROFILE)

def get_password(self):
if self.password and self.password.startswith("@oracle:"):
Expand All @@ -46,6 +50,8 @@ def get_profile_id(self, product, is_ga):

return profile_id

def get_promote_profile_id(self, is_ga):
return self.ga_promote_profile if is_ga else self.ea_promote_profile

def __str__(self):
return """RCMNexusConfig [
Expand Down Expand Up @@ -112,11 +118,15 @@ def init_config():
URL: 'http://repository.prod.corp.com/nexus',
USERNAME: user,
PASSWORD: '@oracle:eval:pass rcm-nexus-prod',
EA_PROMOTE_PROFILE: "123",
GA_PROMOTE_PROFILE: "456",
},
'stage':{
URL: 'http://repository.stage.corp.com/nexus',
USERNAME: user,
PASSWORD: '@oracle:eval:pass rcm-nexus-stage',
EA_PROMOTE_PROFILE: "321",
GA_PROMOTE_PROFILE: "654",
}
}

Expand Down
186 changes: 0 additions & 186 deletions rcm_nexus/group.py

This file was deleted.

2 changes: 1 addition & 1 deletion rcm_nexus/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
COMPRESSED_CONTENT_PATH = NAMED_REPO_PATH + "/content-compressed{delete}"

def push_zip(session, repo_key, zip_file, delete_first=False):
with open(zip_file, 'r') as f:
with open(zip_file, 'rb') as f:
delete_param = ''
if delete_first:
delete_param = '?delete=true'
Expand Down

0 comments on commit 708fe07

Please sign in to comment.