From: Thanh Ha Date: Wed, 21 Jun 2017 19:47:21 +0000 (-0400) Subject: Add command to deploy nexus-zip files X-Git-Tag: v0.5.0~4 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=a72bf05;p=releng%2Flftools.git Add command to deploy nexus-zip files This command is useful to push nexus formated zip files directly to the Nexus content-compressed URL. This is useful for example with Site repos where it would be faster to cURL a zip file here than to allow Maven site:deploy to upload one file at time to Nexus. Issue: RELENG-211 Change-Id: Ie459498b4886391a4a4fbe86b3cbb1a837bc2b16 Signed-off-by: Thanh Ha --- diff --git a/docs/commands/deploy.rst b/docs/commands/deploy.rst index 1562035c..c1465ca8 100644 --- a/docs/commands/deploy.rst +++ b/docs/commands/deploy.rst @@ -34,3 +34,8 @@ nexus-stage ----- .. program-output:: lftools deploy nexus-stage --help + +nexus-zip +----- + +.. program-output:: lftools deploy nexus-zip --help diff --git a/lftools/cli/deploy.py b/lftools/cli/deploy.py index 2606b87e..15c70c1e 100644 --- a/lftools/cli/deploy.py +++ b/lftools/cli/deploy.py @@ -174,8 +174,28 @@ def nexus_stage(ctx, nexus_url, staging_profile_id, deploy_dir): sys.exit(status) +@click.command(name='nexus-zip') +@click.argument('nexus-url', envvar='NEXUS_URL') +@click.argument('nexus-repo', envvar='NEXUS_REPO') +@click.argument('nexus-path', envvar='NEXUS_PATH') +@click.argument('deploy-zip', envvar='DEPLOY_DIR') +@click.pass_context +def nexus_zip(ctx, nexus_url, nexus_repo, nexus_path, deploy_zip): + """Deploy zip file containing artifacts to Nexus using cURL. + + This script simply takes a zip file preformatted in the correct + directory for Nexus and uploads to a specified Nexus repo using the + content-compressed URL. + + Requires the Nexus Unpack plugin and permission assigned to the upload user. + """ + status = subprocess.call(['deploy', 'nexus-zip', nexus_url, nexus_repo, nexus_path, deploy_zip]) + sys.exit(status) + + deploy.add_command(archives) deploy.add_command(logs) deploy.add_command(maven_file) deploy.add_command(nexus) deploy.add_command(nexus_stage) +deploy.add_command(nexus_zip) diff --git a/shell/deploy b/shell/deploy index d8e28c97..575c9d67 100755 --- a/shell/deploy +++ b/shell/deploy @@ -90,6 +90,11 @@ deploy() { deploy_nexus_stage "$@" exit 0 ;; + nexus-zip ) + echo "Deploying nexus-zip..." + deploy_nexus_zip "$@" + exit 0 + ;; * ) echo "Invalid command: $subcommand" 1>&2 exit 1 @@ -591,6 +596,40 @@ EOF rm "$FILE_XML" } +deploy_nexus_zip() { + # Deploy zip file containing artifacts to Nexus using cURL + # + # This function simply takes a zip file preformatted in the correct + # directory for Nexus and uploads to a specified Nexus repo using the + # content-compressed URL. + # + # Requires the Nexus Unpack plugin and permission assigned to the upload user. + # + # Parameters: + # nexus_url: URL to Nexus server. (Ex: https://nexus.opendaylight.org) + # nexus_repo: The repository to push to. (Ex: site) + # nexus_path: The path to upload the artifacts to. Typically the + # project group_id depending on if a Maven or Site repo + # is being pushed. + # Maven Ex: org/opendaylight/odlparent + # Site Ex: org.opendaylight.odlparent + # deploy_zip: The zip to deploy. (Ex: /tmp/artifacts.zip) + + local nexus_url="$1" + local nexus_repo="$2" + local nexus_path="$3" + local deploy_zip="$4" + + if [ -z "$4" ]; then + echo "Missing required arguments." + exit 1 + fi + + echo "Pushing $deploy_zip to $nexus_repo on $nexus_url" + curl --netrc --upload-file "$deploy_zip" \ + "${nexus_url}/service/local/repositories/${nexus_repo}/content-compressed/${nexus_path}" +} + # Only run the script if it is being called directly and not sourced. if [[ "${BASH_SOURCE[0]}" == "${0}" ]] then