From 98fc1997491706dbb6fcc199eef72f09c4e4179c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez?= Date: Thu, 25 Jun 2020 11:24:51 +0200 Subject: [PATCH] F #4944: Include context packages in OpenNebula distribution * download context pkgs with scons * update gitignore info * update docker_downloader.sh (cherry picked from commit be6d4d916cd6083c53b7fe57d50d857443ebfe21) --- .gitignore | 4 ++ SConstruct | 6 +- install.sh | 6 +- share/context/SConstruct | 29 +++++++++ share/context/download_context.sh | 53 ++++++++++++++++ .../remotes/docker_downloader.sh | 61 +++---------------- 6 files changed, 106 insertions(+), 53 deletions(-) create mode 100644 share/context/SConstruct create mode 100755 share/context/download_context.sh diff --git a/.gitignore b/.gitignore index c9825d6f37..80129c6c86 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,7 @@ share/esx-fw-vnc/*.rpm share/esx-fw-vnc/.vagrant* *.vscode + +share/context/* +!share/context/download_context.sh +!share/context/SConstruct diff --git a/SConstruct b/SConstruct index ba8d34fff3..f8a0764a24 100755 --- a/SConstruct +++ b/SConstruct @@ -209,6 +209,9 @@ main_env.Append(marshal=ARGUMENTS.get('marshal', 'no')) # Docker-machine addon generation main_env.Append(docker_machine=ARGUMENTS.get('docker_machine', 'no')) +# Context packages download +main_env.Append(context=ARGUMENTS.get('context', 'no')) + if not main_env.GetOption('clean'): try: if mysql == 'yes': @@ -313,7 +316,8 @@ build_scripts = [ 'src/docker_machine/SConstruct', 'src/monitor/SConstruct', 'src/onedb/SConstruct', - svncterm_path + svncterm_path, + 'share/context/SConstruct' ] # disable svncterm diff --git a/install.sh b/install.sh index 19bb7e480a..24eb44c352 100755 --- a/install.sh +++ b/install.sh @@ -237,7 +237,8 @@ SHARE_DIRS="$SHARE_LOCATION/examples \ $SHARE_LOCATION/schemas/libvirt \ $SHARE_LOCATION/ssh \ $SHARE_LOCATION/start-scripts \ - $SHARE_LOCATION/conf" + $SHARE_LOCATION/conf \ + $SHARE_LOCATION/context" ETC_DIRS="$ETC_LOCATION/vmm_exec \ $ETC_LOCATION/hm \ @@ -668,6 +669,7 @@ INSTALL_FILES=( SSH_SH_LIB_FILES:$LIB_LOCATION/sh SSH_SH_OVERRIDE_LIB_FILES:$LIB_LOCATION/sh/override SSH_SHARE_FILES:$SHARE_LOCATION/ssh + CONTEXT_SHARE:$SHARE_LOCATION/context ) INSTALL_CLIENT_FILES=( @@ -2682,6 +2684,8 @@ LIBVIRT_RNG_SHARE_MODULE_FILES="share/schemas/libvirt/basictypes.rng \ share/schemas/libvirt/nwfilter_params.rng \ share/schemas/libvirt/storagecommon.rng" +CONTEXT_SHARE=$(find share/context/ -type f \( ! -iname "*.sh" ! -iname "SConstruct" \)) + #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # INSTALL.SH SCRIPT diff --git a/share/context/SConstruct b/share/context/SConstruct new file mode 100644 index 0000000000..a050ad7b8b --- /dev/null +++ b/share/context/SConstruct @@ -0,0 +1,29 @@ +# SConstruct for share/scripts/rubygems + +# -------------------------------------------------------------------------- # +# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +import os + +Import('env') + +if env['context']=='yes': + print ("Downloading OpenNebula context packages\n") + exit_code=os.system("./download_context.sh") + + if exit_code != 0: + print ("Error downloading OpenNebula context packages\n") + exit(-1) diff --git a/share/context/download_context.sh b/share/context/download_context.sh new file mode 100755 index 0000000000..4ef44a7986 --- /dev/null +++ b/share/context/download_context.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +#------------------------------------------------------------------------------- +# This function returns the associated context packages version to the installed +# OpenNebula version +#------------------------------------------------------------------------------- +function get_tag_version { + local creleases=`curl -sSL $1 | jq -r '.[].tag_name' | cut -d 'v' -f 2` + + for tag in `echo $creleases`; do + if [ "$tag" = "`echo -e "$tag\n$VERSION" | sort -V | head -n1`" ]; then + echo "$tag" + break + fi + done +} + +CONTEXT_API="https://api.github.com/repos/OpenNebula/addon-context-linux/releases" +CONTEXT_API_WINDOWS="https://api.github.com/repos/OpenNebula/addon-context-windows/releases" + +VERSION=`cat ../../src/im_mad/remotes/VERSION` + +############################################################################### +# Download linux packages +############################################################################### + +TAG_VERSION=`get_tag_version $CONTEXT_API` + +# If the current ONE version is greater than every context version the last one is retrieved +if [ -z "$TAG_VERSION" ]; then + TAG_VERSION=`curl -s $CONTEXT_API | jq -r '.[0].tag_name' | cut -d 'v' -f 2` +fi + +TAG="v$TAG_VERSION" + +curl -s $CONTEXT_API | \ + jq -r --arg TAG "$TAG" '.[] | select(.tag_name == $TAG) | .assets[].browser_download_url' | \ + xargs wget -P . + +############################################################################### +# Download windows .msi +############################################################################### + +TAG_VERSION=`get_tag_version $CONTEXT_API_WINDOWS` + +# If the current ONE version is greater than every context version the last one is retrieved +if [ -z "$TAG_VERSION" ]; then + TAG_VERSION=`curl -s $CONTEXT_API_WINDOWS | jq -r '.[0].tag_name' | cut -d 'v' -f 2` +fi + +TAG="v$TAG_VERSION" + +wget -P . https://github.com/OpenNebula/addon-context-windows/releases/download/$TAG/one-context-$TAG_VERSION.msi diff --git a/src/datastore_mad/remotes/docker_downloader.sh b/src/datastore_mad/remotes/docker_downloader.sh index aa0542c6b6..e9678ddfcc 100755 --- a/src/datastore_mad/remotes/docker_downloader.sh +++ b/src/datastore_mad/remotes/docker_downloader.sh @@ -19,9 +19,11 @@ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one VAR_LOCATION=/var/lib/one + SHARE_LOCATION=/usr/share/one else LIB_LOCATION=$ONE_LOCATION/lib VAR_LOCATION=$ONE_LOCATION/var + SHARE_LOCATION=$ONE_LOCATION/share fi . $LIB_LOCATION/sh/scripts_common.sh @@ -34,42 +36,14 @@ MARKET_URL=$1 MK_DOCKER=$LIB_LOCATION/sh/create_docker_image.sh -# URL with the context releases -CONTEXT_API="https://api.github.com/repos/OpenNebula/addon-context-linux/releases" -CONTEXT_URL="https://github.com/OpenNebula/addon-context-linux/releases/download" - -PKG_APK="curl openssh" -PKG_DEB="curl " -PKG_RPM="openssh-server" -PKG_CENTOS6="epel-release $PKG_RPM" -PKG_FEDORA="network-scripts $PKG_RPM" - #Default DNS server to download the packages DNS_SERVER="1.1.1.1" #Directory used to download packages TMP_DIR=/var/tmp -#Curl command and options used to download container image -CURL="curl -L" - -#------------------------------------------------------------------------------- -# This function returns the associated context packages version to the installed -# OpenNebula version -#------------------------------------------------------------------------------- -function get_tag_name { - local version=`oned --version 2>/dev/null | grep '^OpenNebula [0-9.]\+ ' | cut -d' ' -f2` - - local creleases=`curl -sSL $CONTEXT_API | grep "\"tag_name\":" | \ - awk '{print $2}' | cut -d 'v' -f 2 | cut -d '"' -f 1` - - for tag in `echo $creleases`; do - if [ "$tag" = "`echo -e "$tag\n$version" | sort -V | head -n1`" ]; then - echo "$tag" - break - fi - done -} +#Context location +CONTEXT_PATH="$SHARE_LOCATION/context" #------------------------------------------------------------------------------- # This function takes care of removing all temporary directories in case @@ -104,8 +78,6 @@ sid=`echo $id | cut -d '-' -f 1` url=`echo $MARKET_URL | grep -oP "^"docker://"\K.*"` arguments=`echo $url | cut -d '?' -f 2` -selected_tag=`get_tag_name` - #Create a shell variable for every argument (size=5219, format=raw...) for p in ${arguments//&/ }; do kvp=( ${p/=/ } ); @@ -150,10 +122,7 @@ fi case "$distro" in debian|ubuntu) - contextpkg=$dockerdir/context.deb - contexturl=$CONTEXT_URL/v$selected_tag/one-context_$selected_tag-1.deb commands=$(cat <> /etc/inittab - -RUN apk add --allow-untrusted /root/context.apk -RUN rm /root/context.apk +RUN apk add --allow-untrusted /root/context/*.apk RUN rc-update del one-context boot && \ rc-update add one-context default @@ -234,13 +191,15 @@ esac cat > $dockerfile < /etc/resolv.conf RUN rm -f /etc/ssh/ssh_host_* > /dev/null 2>&1 RUN usermod -p '*' root > /dev/null 2>&1 EOC -$CURL $contexturl -Lsfo $contextpkg > /dev/null 2>&1 +cp -rL $CONTEXT_PATH $dockerdir docker build -t one$sid -f $dockerfile $dockerdir > /dev/null 2>&1