Adding platform independent RPM download 23/96723/5
authorJan Benedikt <j.benedikt@partner.samsung.com>
Tue, 8 Oct 2019 14:01:41 +0000 (10:01 -0400)
committerJan Benedikt <j.benedikt@partner.samsung.com>
Tue, 15 Oct 2019 07:32:41 +0000 (03:32 -0400)
Updated onap_rpm.list with new versions of packages.
Added scripts for creating centos container in docker with rpm repository.
RPM repo is now created in centos container during download phase, but will work on both centos/rhel platforms.
Issue-ID: OOM-2094

Signed-off-by: Jan Benedikt <j.benedikt@partner.samsung.com>
Change-Id: I1b5bfe99da25e6815e85b449304b12fa6036c6b3

build/create_repo.sh [new file with mode: 0755]
build/docker-entrypoint.sh [new file with mode: 0755]
build/package.py
docs/BuildGuide.rst

diff --git a/build/create_repo.sh b/build/create_repo.sh
new file mode 100755 (executable)
index 0000000..8e12a16
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+container_name="centos_repo"
+# Path to folder with clonned offline-installer build directory with docker_entrypoint script
+volume_directory="."
+# Path inside container
+container_volume="/mnt/"
+# Docker image name and version
+docker_image="centos:centos7.6.1810"
+
+# Getting input parametters
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+    key="$1"
+    case $key in
+        -h|--help)
+            # Help parametter
+            echo -e "Script for run docker container with RPM repository\n"
+            echo "-h --help: Show this help"
+            echo -e "-d --directory: set root path with offline-installer directory and repository directory for RPM packages\n"
+            echo "If build folder from offline repository is not specified will be used default path of current folder."
+            shift # past argument
+            shift # past value
+            exit
+            ;;
+        -d|--directory)
+            # Directory parametter
+            # Sets path where is clonned offline-installer build directory
+            volume_directory="$2"
+            shift # past argument
+            shift # past value
+            ;;
+        --default)
+            DEFAULT=YES
+            shift # past argument
+            ;;
+        *)  
+            # unknown option
+            POSITIONAL+=("$1") # save it in an array for later
+            shift # past argument
+            ;;
+    esac
+done
+
+
+#Check if container "centos-repo" is running
+if [ ! "$(docker ps -q -f name=$container_name)" ]; then
+    if [ "$(docker ps -aq -f status=exited -f name=$container_name)" ]; then
+        # cleanup
+        docker rm $container_name
+    fi
+    # run repo container
+    # name of container $container_name
+    # docker entrypoint script from mounted volume
+    #
+    docker run -d \
+               --name $container_name \
+               -v ${volume_directory}:${container_volume} \
+               --entrypoint="${container_volume}offline-installer/build/docker-entrypoint.sh" \
+               -it ${docker_image} \
+               --rm \
+               --directory ${container_volume}resources/pkg/rhel/ \
+               --list ${container_volume}offline-installer/build/data_lists/
+fi
diff --git a/build/docker-entrypoint.sh b/build/docker-entrypoint.sh
new file mode 100755 (executable)
index 0000000..798e1f0
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/env bash
+
+# Path where will be created repository (in container)
+OOM_REPO_DIR=""
+
+# Path where is stored onap_rpm.list file
+RPM_LIST_DIR=""
+
+# Getting input parametters
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+    key="$1"
+    case $key in
+        -h|--help)
+            # Help parametter
+            echo -e "Docker entrypoint script for creating RPM repository\n"
+            echo "-h --help: Show this help"
+            echo "-d --directory: set path for repo directory in container"
+            echo -e "-l --list: set path where rpm list is stored in container\n"
+            echo "Both paths have to be set with shared volume between"
+            echo "container and host computer. Default path in container is: /tmp/"
+            echo "Repository will be created at: /<path>/resources/pkg/rhel/"
+            echo "RMP list is stored at: /<path>/offline-installer/build/data_list/"
+            shift # past argument
+            shift # past value
+            exit
+            ;;
+        -d|--directory)
+            # Directory parametter
+            # Sets path where will be created reposity
+            OOM_REPO_DIR="$2"
+            shift # past argument
+            shift # past value
+            ;;
+        -l|--list)
+            # List parametter
+            # Sets path where is stored onap_rpm.list file
+            RPM_LIST_DIR="$2"
+            shift # past argument
+            shift # past value
+            ;;
+        --default)
+            DEFAULT=YES
+            shift # past argument
+            ;;
+        *) 
+            # unknown option
+            POSITIONAL+=("$1") # save it in an array for later
+            shift # past argument
+            ;;
+    esac
+done
+
+# Testing if directory parametter was used
+# If not variable is sets to default value /tmp/resources/pkg/rhel
+if test -z "$OOM_REPO_DIR"
+then
+    OOM_REPO_DIR="/tmp/resources/pkg/rhel"
+fi
+
+# Testing if list parametter was used
+# If not variable is sets to default value /tmp/data-list
+if test -z "$RPM_LIST_DIR"
+then
+    RPM_LIST_DIR="/tmp/offline-installer/build/data_list/"
+
+fi
+
+# Create repo folder
+mkdir $OOM_REPO_DIR -p
+
+# Install createrepo package for create repository in folder
+# and yum-utils due to yum-config-manager for adding docker repository
+yum install createrepo yum-utils -y
+
+# Add official docker repository
+yum-config-manager --add-repo=https://download.docker.com/linux/centos/7/x86_64/stable/
+
+# Download all packages from onap_rpm.list via yumdownloader to repository folder
+for i in $(cat ${RPM_LIST_DIR}onap_rpm.list | awk '{print $1}');do yumdownloader --resolve --downloadonly --destdir=${OOM_REPO_DIR} $i -y; done
+
+# In repository folder create repository
+createrepo $OOM_REPO_DIR
index d30b40c..ad921ed 100755 (executable)
@@ -210,10 +210,6 @@ def build_offline_deliverables(build_version,
         os.chdir(script_location)
         # End of workaround
 
-        log.info('Create rhel repo')
-        createrepo = subprocess.run(['createrepo', os.path.join(resources_directory, 'pkg', 'rhel')])
-        createrepo.check_returncode()
-
         resources_package_tar_path = os.path.join(output_dir, 'resources_package' + build_version + '.tar')
         create_package(resources_content, resources_package_tar_path)
 
index 41cfcfe..9b581cd 100644 (file)
@@ -110,7 +110,20 @@ Part 2. Download artifacts for offline installer
 
 .. note:: Skip this step if you have already all necessary resources and continue with Part 3. Populate local nexus
 
-It's possible to download all artifacts in single ./download.py execution. Recently we improved reliability of download scripts
+Before downloading artifacts with ./download.py script is necessary to create local repository with RPM packages.
+This repository is created with docker container where is downloaded and stored in ../resources/pkg/rhel directory.
+
+::
+    # run the docker container with actual directory of offline-installer and resources
+    ./offline-installer/build/create_repo.sh -d $(pwd)
+
+.. note::
+    If script fails with permissions, problem could be with SeLinux. Issue is possible to solve by:
+    ::
+      # Change security context of directory
+      chcon -Rt svirt_sandbox_file_t $(pwd)
+
+It's possible to download rest artifacts in single ./download.py execution. Recently we improved reliability of download scripts
 so one might try following command to download most of the required artifacts in single shot.
 
 ::
@@ -125,7 +138,6 @@ so one might try following command to download most of the required artifacts in
         --docker ./build/data_lists/onap_docker_images.list ../resources/offline_data/docker_images_for_nexus \
         --git ./build/data_lists/onap_git_repos.list ../resources/git-repo \
         --npm ./build/data_lists/onap_npm.list ../resources/offline_data/npm_tar \
-        --rpm ./build/data_lists/onap_rpm.list ../resources/pkg/rhel \
         --pypi ./build/data_lists/onap_pip_packages.list ../resources/offline_data/pypi \
         --http ./build/data_lists/infra_bin_utils.list ../resources/downloads