From fe4cf190799a39fac776765409eba622d53ea82d Mon Sep 17 00:00:00 2001 From: "Lott, Christopher (cl778h)" Date: Thu, 26 Mar 2020 21:26:14 -0400 Subject: [PATCH] Extend packagecloud-push for build-dir Extend script packagecloud-push.sh with environment variable BUILD_DIR. Populate BUILD_DIR from JJB config parameter build-dir, required for cmake anyhow. This limits the search to a single directory. Add build-dir default to docker-ci template, "export-packages" Revise export script to use a constant value for build-dir, also "export-packages" in $WORKSPACE. Signed-off-by: Lott, Christopher (cl778h) Change-Id: I3da170246fb5868e644756e80c20b07bf68f55f9 --- jjb/oran-templates/oran-c-cpp-jobs.yaml | 3 +- jjb/oran-templates/oran-docker-ci-jobs.yaml | 1 + jjb/oran-templates/oran-package-cloud-macros.yaml | 9 +-- .../ric-plt-xapp-frame-cpp.yaml | 22 ++++++-- jjb/shell/export-packages.sh | 4 +- jjb/shell/packagecloud-push.sh | 66 +++++++++++++--------- 6 files changed, 68 insertions(+), 37 deletions(-) diff --git a/jjb/oran-templates/oran-c-cpp-jobs.yaml b/jjb/oran-templates/oran-c-cpp-jobs.yaml index 386b5138..c43e7358 100644 --- a/jjb/oran-templates/oran-c-cpp-jobs.yaml +++ b/jjb/oran-templates/oran-c-cpp-jobs.yaml @@ -68,7 +68,7 @@ branch: master build-days-to-keep: 7 - build-dir: "$WORKSPACE/target" + build-dir: "$WORKSPACE/build" build-timeout: 15 cmake-opts: "" cron: "" # avoid for PackageCloud which rejects duplicates @@ -99,6 +99,7 @@ - shell: "{pre-build}" - shell: !include-raw-escape: ../../global-jjb/shell/cmake-build.sh - oran-packagecloud-push: + build-dir: "{build-dir}" packagecloud-account: "{packagecloud-account}" packagecloud-repo: "{packagecloud-repo}" debian-distribution-versions: "{debian-distribution-versions}" diff --git a/jjb/oran-templates/oran-docker-ci-jobs.yaml b/jjb/oran-templates/oran-docker-ci-jobs.yaml index 601aee1b..93c431bc 100644 --- a/jjb/oran-templates/oran-docker-ci-jobs.yaml +++ b/jjb/oran-templates/oran-docker-ci-jobs.yaml @@ -132,6 +132,7 @@ - shell: "{post_docker_build_script}" - oran-docker-build-export - oran-packagecloud-push: + build-dir: export-packages # directory with deb/rpm files packagecloud-account: "{packagecloud-account}" packagecloud-repo: "{packagecloud-repo}" debian-distribution-versions: "{debian-distribution-versions}" diff --git a/jjb/oran-templates/oran-package-cloud-macros.yaml b/jjb/oran-templates/oran-package-cloud-macros.yaml index 2005d578..cca77205 100644 --- a/jjb/oran-templates/oran-package-cloud-macros.yaml +++ b/jjb/oran-templates/oran-package-cloud-macros.yaml @@ -13,9 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Macros to invoke shell scripts for PackageCloud - - builder: + # provisions files required by package_cloud ruby gem name: oran-packagecloud-file-provider builders: - config-file-provider: @@ -28,6 +27,8 @@ target: "$HOME/packagecloud_api" - builder: + # Runs shell script to push packages to PackageCloud. + # {build-dir} is directory with deb/rpm files to push # {packagecloud-account} is PackageCloud account ID; example: oran # {packagecloud-repo} is PackageCloud repository; example: master, staging # {debian-distribution-versions} is list of DEB package distro/version strings @@ -38,9 +39,9 @@ builders: - inject: properties-content: | + BUILD_DIR={build-dir} PACKAGECLOUD_ACCOUNT={packagecloud-account} PACKAGECLOUD_REPO={packagecloud-repo} DEBIAN_DISTRIBUTION_VERSIONS={debian-distribution-versions} RPM_DISTRIBUTION_VERSIONS={rpm-distribution-versions} - - shell: !include-raw-escape: - - ../shell/packagecloud-push.sh + - shell: !include-raw-escape: ../shell/packagecloud-push.sh diff --git a/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml b/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml index 5fd387bf..9bbd4311 100644 --- a/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml +++ b/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml @@ -29,14 +29,27 @@ # install RMR per version file in repo for ubuntu pre-build: !include-raw-escape: - ../shell/install-deb-rmr3.sh - # verify and sonar use cmake + +# development library - publish only +- project: + name: xapp-frame-cpp-lib-dev + <<: *xapp_frame_cpp_common + project-name: ric-plt-xapp-frame-cpp-dev cmake-opts: -DDEV_PKG=1 - make-opts: install test ARGS=-V + make-opts: package ARGS=-V + jobs: + - oran-gerrit-cmake-pc-stage + stream: + - master: + branch: master -# verify on changes, publish on stage +# runtime library - test and publish - project: - name: xapp-frame-cpp-verify + name: xapp-frame-cpp-lib-rt <<: *xapp_frame_cpp_common + project-name: ric-plt-xapp-frame-cpp-lib + cmake-opts: -DDEV_PKG=0 + make-opts: test package ARGS=-V jobs: - gerrit-cmake-verify - oran-gerrit-cmake-pc-stage @@ -48,6 +61,7 @@ - project: name: xapp-frame-cpp-sonarqube <<: *xapp_frame_cpp_common + make-opts: test ARGS=-V sonar-project-file: "" sonar-properties: | sonar.login={sonarcloud_api_token} diff --git a/jjb/shell/export-packages.sh b/jjb/shell/export-packages.sh index e6bf0768..12c6364a 100755 --- a/jjb/shell/export-packages.sh +++ b/jjb/shell/export-packages.sh @@ -23,8 +23,10 @@ echo "--> export-packages.sh" # that copies artifacts created by the builder to a directory. # Environment variables are injected in previous Jenkins steps. # The push script searches the workspace, so do not use /tmp etc. -HOST=$WORKSPACE/export-packages-$$ +HOST=$WORKSPACE/export-packages GUEST=/export mkdir -p "$HOST" docker run -v "$HOST":"$GUEST" "$CONTAINER_PUSH_REGISTRY"/"$DOCKER_NAME":"$DOCKER_IMAGE_TAG" "$GUEST" ls "$HOST" + +echo "--> export-packages.sh ends" diff --git a/jjb/shell/packagecloud-push.sh b/jjb/shell/packagecloud-push.sh index a48d39cf..beb94676 100755 --- a/jjb/shell/packagecloud-push.sh +++ b/jjb/shell/packagecloud-push.sh @@ -1,41 +1,53 @@ #!/bin/bash -l # SPDX-License-Identifier: EPL-1.0 ############################################################################## -# Copyright (c) 2019 The Linux Foundation and others. +# Copyright (c) 2020 The Linux Foundation and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################## + +# Prereqs: +# The build minion has the ruby gem "package_cloud" +# The required credentials and API files have been provisioned +# The build directory has .deb/.rpm files +# Environment variables: +# BUILD_DIR is set and non-empty +# DEBIAN_DISTRIBUTION_VERSIONS has distro list like "debian/stretch" +# RPM_DISTRIBUTION_VERSIONS has distro list like "el/4 el/5" +# PACKAGECLOUD_ACCOUNT is set and non-empty +# PACKAGECLOUD_REPO is a value like "staging" + echo "---> packagecloud-push.sh" set -eu -o pipefail -if [ ! -f ~/.packagecloud ]; then - echo "INFO: .packagecloud file not found" - exit 0 -fi - - # For DEB -vers=("$DEBIAN_DISTRIBUTION_VERSIONS") -echo "Debian distribution versions:" "${vers[@]}" -debs=$(find . -type f -iname '*.deb') -# modern bash syntax is helpful -for (( i = 0; i < ${#vers[@]}; i++ )); do - for deb in $debs; do - echo "Pushing $deb $PACKAGECLOUD_ACCOUNT/$PACKAGECLOUD_REPO/${vers[i]}" - package_cloud push "$PACKAGECLOUD_ACCOUNT"/"$PACKAGECLOUD_REPO"/"${vers[i]}" "$deb" +# Pushes packages to PackageCloud +# $1 is a shell-style glob pattern for package files +# $2 is a space-separated list of distribution versions +push_packages () { + echo "Expanding file pattern $1" + # shellcheck disable=SC2206 + pkgs=($1) + if [[ ! -f ${pkgs[0]} ]]; then + echo "WARN: no files matched pattern $1" + return + fi + echo "Found package file(s):" "${pkgs[@]}" + echo "Processing distribution version(s): $2" + for ver in $2; do + arg="${PACKAGECLOUD_ACCOUNT}/${PACKAGECLOUD_REPO}/${ver}" + for pkg in "${pkgs[@]}"; do + echo "Pushing $arg $pkg" + package_cloud push "$arg" "$pkg" + done done -done +} -# For RPM -vers=("$RPM_DISTRIBUTION_VERSIONS") -echo "RPM distribution versions:" "${vers[@]}" -rpms=$(find . -type f -iregex '.*/.*\.\(s\)?rpm') -# modern bash syntax is helpful -for (( i = 0; i < ${#vers[@]}; i++ )); do - for rpm in $rpms; do - echo "Pushing $rpm $PACKAGECLOUD_ACCOUNT/$PACKAGECLOUD_REPO/${vers[i]}" - package_cloud push "$PACKAGECLOUD_ACCOUNT"/"$PACKAGECLOUD_REPO"/"${vers[i]}" "$rpm" - done -done +echo "Working in directory $BUILD_DIR" +cd "$BUILD_DIR" +push_packages "*.deb" "$DEBIAN_DISTRIBUTION_VERSIONS" +push_packages "*.rpm" "$RPM_DISTRIBUTION_VERSIONS" + +echo "---> packagecloud-push.sh ends" -- 2.16.6