Add command to deploy nexus-zip files 73/5273/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 21 Jun 2017 19:47:21 +0000 (15:47 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 21 Jun 2017 19:55:50 +0000 (15:55 -0400)
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 <thanh.ha@linuxfoundation.org>
docs/commands/deploy.rst
lftools/cli/deploy.py
shell/deploy

index 1562035..c1465ca 100644 (file)
@@ -34,3 +34,8 @@ nexus-stage
 -----
 
 .. program-output:: lftools deploy nexus-stage --help
+
+nexus-zip
+-----
+
+.. program-output:: lftools deploy nexus-zip --help
index 2606b87..15c70c1 100644 (file)
@@ -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)
index d8e28c9..575c9d6 100755 (executable)
@@ -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