From: Thanh Ha Date: Wed, 31 May 2017 21:01:43 +0000 (-0400) Subject: Add deploy nexus command X-Git-Tag: v0.3.0~2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=c84a544;p=releng%2Flftools.git Add deploy nexus command Use curl to deploy a Maven repository to Nexus. Jira: RELENG-121 Change-Id: If46e5054a2234eab77e7bd07120d8d0f11dfd293 Signed-off-by: Thanh Ha --- diff --git a/docs/commands/deploy.rst b/docs/commands/deploy.rst new file mode 100644 index 00000000..0f7a2a4c --- /dev/null +++ b/docs/commands/deploy.rst @@ -0,0 +1,26 @@ +****** +Deploy +****** + +.. program-output:: lftools deploy --help + +Commands +======== + +.. contents:: Deploy Commands + :local: + +archives +-------- + +.. program-output:: lftools deploy archives --help + +logs +---- + +.. program-output:: lftools deploy logs --help + +nexus +----- + +.. program-output:: lftools deploy nexus --help diff --git a/lftools/cli/deploy.py b/lftools/cli/deploy.py index 318b14f0..67057aa0 100644 --- a/lftools/cli/deploy.py +++ b/lftools/cli/deploy.py @@ -67,5 +67,24 @@ def logs(ctx, nexus_url, nexus_path, build_url): sys.exit(status) +@click.command() +@click.argument('nexus-repo-url', envvar='NEXUS_REPO_URL') +@click.argument('deploy-dir', envvar='DEPLOY_DIR') +@click.pass_context +def nexus(ctx, nexus_repo_url, deploy_dir): + """Deploy a Maven repository to a specified Nexus repository. + + This script takes a local Maven repository and deploys it to a Nexus + repository. + + Example Repository: + + https://nexus.example.org/content/repositories/release + """ + status = subprocess.call(['deploy', 'nexus', nexus_repo_url, deploy_dir]) + sys.exit(status) + + deploy.add_command(archives) deploy.add_command(logs) +deploy.add_command(nexus) diff --git a/shell/deploy b/shell/deploy index fb826eaa..1b363165 100755 --- a/shell/deploy +++ b/shell/deploy @@ -75,6 +75,16 @@ deploy() { deploy_logs "$@" exit 0 ;; + nexus ) + echo "Deploying Maven artifacts..." + deploy_nexus "$@" + exit 0 + ;; + nexus-stage ) + echo "Deploying Maven artifacts to staging repo..." + deploy_nexus_stage "$@" + exit 0 + ;; * ) echo "Invalid command: $subcommand" 1>&2 exit 1 @@ -231,6 +241,51 @@ deploy_logs() { rm -rf "$tmpdir" } +deploy_nexus() { + # Deploy Maven artifacts to Nexus using curl + # + # Parameters: + # + # nexus_repo_url: The URL to the Nexus repo. + # (Ex: https://nexus.example.org/content/repositories/release) + # deploy_dir: The path to a directory to deploy. (Ex: /tmp/m2repo) + # + # One purpose of this is so that we can get around the problematic + # deploy-at-end configuration with upstream Maven. + # https://issues.apache.org/jira/browse/MDEPLOY-193 + + local nexus_repo_url="$1" + local deploy_dir="$2" + + if [ -z "$2" ]; then + echo "Missing required arguments." + echo "Usage: deploy nexus " + exit 1 + fi + + pushd "$deploy_dir" + file_list=($(find . -type f \ + ! -name "maven-metadata*" \ + ! -name _remote.repositories \ + ! -name resolver-status.properties \ + | cut -c 3-)) + + for file in "${file_list[@]}"; do + echo "Uploading ${file}" + + local resp + resp=$(curl -s -w "%{http_code}" --netrc --upload-file "$file" "$nexus_repo_url/$file") + status=$(echo "$resp" | awk 'END {print $NF}') + + if [ "$status" != "201" ]; then + echo "ERROR: Failed to upload to Nexus. Aborting..." + echo "$resp" + exit "$status" + fi + done + popd +} + # Only run the script if it is being called directly and not sourced. if [[ "${BASH_SOURCE[0]}" == "${0}" ]] then