Merge "Fix auto update image script to compare image type"
authorAnil Belur <abelur@linuxfoundation.org>
Sat, 5 Oct 2019 05:10:48 +0000 (05:10 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Sat, 5 Oct 2019 05:10:48 +0000 (05:10 +0000)
docs/jjb/lf-python-jobs.rst
jenkins-init-scripts/init.sh
jenkins-init-scripts/lf-env.sh [new file with mode: 0644]
jjb/lf-python-jobs.yaml
releasenotes/notes/add-lf-bash-library-b60dcce181c87d5a.yaml [new file with mode: 0644]
releasenotes/notes/set-pypi-test-in-merge-4b2047944dfbc34c.yaml [new file with mode: 0644]

index e6e86b2..13047ed 100644 (file)
@@ -43,7 +43,7 @@ Jenkins server must have a configuration file ".pypirc".
 :Required Parameters:
 
     :pypi-repo: PyPI repository key in .pypirc configuration file;
-        e.g., "staging" or "pypi".
+        e.g., "pypi-test" or "pypi".
 
 lf-infra-tox-install
 --------------------
@@ -396,7 +396,7 @@ PyPI Merge
 Creates and uploads distribution files on merge of a patch set.  Runs
 tox, builds a source distribution and (optionally) a binary
 distribution, and uploads the distribution(s) to a PyPI repository.
-This job should be configured to use a staging PyPI repository like
+This job should be configured to use a test PyPI repository like
 testpypi.python.org, not a public release area like the global PyPI
 repository. Like the verify job, this requires a setup.py file for
 packaging the component.
@@ -412,25 +412,23 @@ pyenv variables before running.
    export PATH="$PYENV_ROOT/bin:$PATH"
 
 
-Requires a .pypirc configuration file in the Jenkins builder home
-directory, an example appears next.
+Requires a .pypirc configuration file in the Jenkins builder home directory,
+an example appears next that uses API tokens. No repository is needed in the
+PyPI section.
 
 .. code-block:: bash
 
     [distutils] # this tells distutils what package indexes you can push to
-    index-servers =
-    staging
-    pypi
+    index-servers = pypi-test pypi
 
-    [staging]
-    repository: https://testpypi.python.org/pypi
-    username: your_username
-    password: your_password
+    [pypi-test]
+    repository: https://test.pypi.org/legacy/
+    username: __token__
+    password: pypi-test-api-token-goes-here
 
     [pypi]
-    repository: https://pypi.python.org/pypi
-    username: your_username
-    password: your_password
+    username: __token__
+    password: pypi-api-token-goes-here
 
 
 :Template Names:
@@ -463,7 +461,7 @@ directory, an example appears next.
     :pre-build-script: Shell script to execute before the tox builder. For
         example, install system prerequisites. (default: a shell comment)
     :pypi-repo: Key for PyPI repository parameters in the .pypirc file.
-        Merge jobs should use a server like testpypi.python.org.  (default: staging)
+        Merge jobs should use a server like testpypi.python.org.  (default: pypi-test)
     :python-version: Python version to invoke pip install of tox-pyenv
         (default: python3)
     :stream: Keyword representing a release code-name.
index 0ae7654..66053b0 100755 (executable)
@@ -25,4 +25,8 @@ fi
 
 # Create the jenkins user last so that hopefully we DO NOT have to deal with
 # guard files
-"$jjb_init_scripts/create-jenkins-user.sh"
+$jjb_init_scripts/create-jenkins-user.sh
+
+cp $jjb_init_scripts/lf-env.sh ~jenkins/
+chmod 644 ~jenkins/lf-env.sh
+chown jenkins:jenkins ~jenkins/lf-env.sh
diff --git a/jenkins-init-scripts/lf-env.sh b/jenkins-init-scripts/lf-env.sh
new file mode 100644 (file)
index 0000000..68e6cf0
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/no-execute
+
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 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
+##############################################################################
+
+# A library of functions for LF/Jenkins bash scripts. In the general case, do
+# NOT set shell variables here. If you want to make a variable available,
+# provide a function that sets the variable: 'function lf_set_foo()
+# {foo=asdf;}'. Any scripts that need access to the variable can call the 'set'
+# function. This keeps the name-space polution to a minimum.
+
+################################################################################
+# Functions
+################################################################################
+
+# Execute pip from 'user' venv
+function lf-pip() { /home/jenkins/.local/bin/pip "$@" ; }
+
+# Echo all arguments to stderr
+function lf-echoerr() { echo "$@" 1>&2; }
+
+# Function to safely evaluate booleans
+# If the boolean equal '' it is an Fatal Error
+# Note the case of boolean will be ignored (always mapped to lower-case)
+function lf-boolean()
+{
+    if [[ $# != 1 ]]; then
+        echo "lf-boolean(): Missing boolean operand"
+        exit 1
+    fi
+    local bool
+    bool=$(echo "$1" | tr '[:upper:]' '[:lower:]')
+    if [[ -z $bool ]] ; then
+        # Output script name & line number of call to function
+        lf-echoerr "ERROR: $(basename $0) line: ${BASH_LINENO[0]} : A boolean cannot be a empty string" >&2
+        exit 1
+    fi
+    $bool
+}
+
+# Function to activate a Python Virtual Environment
+# Just validate the path and add 'bin' to the path
+function lf-activate()
+{
+    if [[ $# != 1 ]]; then
+        echo "lf-activate(): Missing path operand"
+        exit 1
+    fi
+    local venv_path=$1
+    # Validate the path to a VENV
+    if [[ ! -d $venv_path/bin ]]; then
+        lf-echoerr "ERROR: Is '$venv_path' a Python Environment ?"
+        return 1
+    fi
+    PATH=$venv_path/bin:$PATH
+}
+
+################################################################################
+# Functions that assign Variables
+################################################################################
+
+# Although these variables are 'shell' variables, they need to be upper-case so
+# 'shellcheck' does check for 'used-before-set' when they are referenced. So if
+# forget to 'source' this file, you will get a 'run-time' error (if you have -u
+# set), otherwise you will get "MAVEN_OPIONS=''.
+
+function lf-set-maven-options()
+{
+    # shellcheck disable=SC2034  # Disable 'unused-variable' check
+    MAVEN_OPTIONS=$(echo --show-version --batch-mode -Djenkins \
+        -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
+        -Dmaven.repo.local=/tmp/r -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r)
+}
index 5a2d193..baf68f1 100644 (file)
     <<: *lf_pypi_merge_builders
 
     cron: ""
-    pypi-repo: staging
+    pypi-repo: pypi-test
 
     gerrit_merge_triggers:
       - change-merged-event
     <<: *lf_pypi_merge_builders
 
     cron: ""
-    pypi-repo: staging
+    pypi-repo: pypi-test
 
     properties:
       - github:
diff --git a/releasenotes/notes/add-lf-bash-library-b60dcce181c87d5a.yaml b/releasenotes/notes/add-lf-bash-library-b60dcce181c87d5a.yaml
new file mode 100644 (file)
index 0000000..0ff94e6
--- /dev/null
@@ -0,0 +1,8 @@
+---
+features:
+  - |
+    Add lf-env.sh 'library' script in ~jenkins. Sourcing this 'library' script
+    from a bash script provides access to a number of functions. The script is
+    installed by the 'init' script at boot time so that is is accessible from
+    any Jenkins build script. Hopefully over time other functions will be added
+    to this library.
diff --git a/releasenotes/notes/set-pypi-test-in-merge-4b2047944dfbc34c.yaml b/releasenotes/notes/set-pypi-test-in-merge-4b2047944dfbc34c.yaml
new file mode 100644 (file)
index 0000000..d43457e
--- /dev/null
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    Correct doc .pypirc test URL to https://test.pypi.org/legacy/
+    Change doc .pypirc to use API tokens instead of username/password.
+    Use pypi-test as the default repository name in the PyPI merge template
+    (instead of "staging") to match established ONAP practice.