From: garciadeblas Date: Thu, 21 Jul 2016 12:53:32 +0000 (+0200) Subject: RO scripts added. Also possible now to create privileged containers X-Git-Tag: v1.0.0~38 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F54%2F254%2F1;p=osm%2Fdevops.git RO scripts added. Also possible now to create privileged containers - SETTINGS files in template and riftware were modified to allow option for privileged container - New function in common/container to create privileged containers - RO SETTINGS and start_build skeleton were created Change-Id: I80143214708e65c62c899efecd30d4b84fb715ce Signed-off-by: garciadeblas --- diff --git a/jenkins/RO/SETTINGS b/jenkins/RO/SETTINGS new file mode 100644 index 00000000..50c3e3fd --- /dev/null +++ b/jenkins/RO/SETTINGS @@ -0,0 +1,28 @@ +# Copyright 2016 RIFT.IO Inc +# +# 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. +# +# sample SETTINGS file +# +# 24 June 2016 -- Jeremy Mordkoff -- Genesis +# +# this variable holds the name of the container image needed to build or run this product +export OSM_BASE_IMAGE=ubuntu:14.04 +# +# this variable holds the name of the container to be used to build a package +# if this container already exists, the build process can skip the container build +export OSM_BUILD_CONTAINER=RO +# +# this variable holds the name of the container to be used to run a package +# if this container already exists, the run processes can skip the container build +export OSM_RUNTIME_CONTAINER=RO diff --git a/jenkins/RO/start_build b/jenkins/RO/start_build new file mode 100755 index 00000000..92b29944 --- /dev/null +++ b/jenkins/RO/start_build @@ -0,0 +1,54 @@ +#!/bin/bash +# Copyright 2016 RIFT.IO Inc +# +# 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. +# +# TEMPLATE script to start a build. This is run inside a container +# +# 6 July 2016 -- Jeremy.Mordkoff@riftio.com -- adapted from the riftware version +# + +HERE=$(realpath $(dirname $0)) +OSM_JENKINS=$(dirname $HERE) +. $OSM_JENKINS/common/all_funcs + +# SET YOU MDG repository name here +export OSM_MDG=RO +OSM_load_config + + +# Here is an example for how to handle an incremental build +if [ -d $OSM_MDG ]; then + INFO "reusing existing workspace" + cd $OSM_MDG + git pull +else + INFO "cloning MDG $OSM_MDG from $OSM_GIT_URL/$OSM_MDG" + git clone $OSM_GIT_URL/$OSM_MDG + cd $OSM_MDG +fi +INFO "starting build" + +### for start_build +### put your commands here to +### build, test and produce coverage reports + +##CODE HERE +touch compiled + +RC=0 + +INFO "done, RC=$RC" +exit $RC + + diff --git a/jenkins/common/container b/jenkins/common/container index 89db8bab..3c09d7f2 100644 --- a/jenkins/common/container +++ b/jenkins/common/container @@ -37,13 +37,22 @@ create_container() { fi INFO "creating container $2 using image $1" DEBUG "lxc launch $1 $2" - sudo lxc launch "$1" "$2" + lxc launch "$1" "$2" +} + +create_privileged_container() { + if [ $# -ne 2 ]; then + FATAL "args are image container" + fi + INFO "creating container $2 using image $1" + DEBUG "lxc launch $1 $2" + lxc launch "$1" "$2" -c security.privileged=true } container_exec() { container="$1" shift - DEBUG "exec in $1 \"$*\"" + DEBUG "exec in $container \"$*\"" lxc exec "$container" -- $* } diff --git a/jenkins/host/start_build b/jenkins/host/start_build index d6fbea8d..06ce3a6e 100755 --- a/jenkins/host/start_build +++ b/jenkins/host/start_build @@ -28,21 +28,25 @@ export OSM_MDG=$1 OSM_load_config if ! container_exists $OSM_BUILD_CONTAINER; then - create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER + if [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]]; then + create_privileged_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER + else + create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER + fi wait_container_up $OSM_BUILD_CONTAINER RE="fedora|fc[0-9]" if [[ $OSM_BASE_IMAGE =~ $RE ]]; then container_exec $OSM_BUILD_CONTAINER yum -y install git else - container_exec $OSM_BUILD_CONTAINER apt install git + container_exec $OSM_BUILD_CONTAINER apt -y install git realpath fi container_exec $OSM_BUILD_CONTAINER git clone ${OSM_GIT_URL}/devops else container_exec $OSM_BUILD_CONTAINER git -C devops pull fi - container_exec $OSM_BUILD_CONTAINER ./devops/jenkins/$OSM_MDG/start_build RC=$? INFO "$OSM_MDG build complete. Return code was $RC" exit $RC + diff --git a/jenkins/riftware/SETTINGS b/jenkins/riftware/SETTINGS index d1af4176..50f9982d 100644 --- a/jenkins/riftware/SETTINGS +++ b/jenkins/riftware/SETTINGS @@ -17,6 +17,8 @@ # 24 June 2016 -- Jeremy Mordkoff -- Genesis # # see ../template/SETTINGS for descriptions -export OSM_BASE_IMAGE=fc20 +export OSM_BASE_IMAGE=fedora20 export OSM_BUILD_CONTAINER=rift-build +export OSM_BUILD_CONTAINER_PRIVILEGED=yes export OSM_RUNTIME_CONTAINER=rift-runtime +export OSM_RUNTIME_CONTAINER_PRIVILEGED=yes diff --git a/jenkins/template/SETTINGS b/jenkins/template/SETTINGS index 09cae6dd..86202eba 100644 --- a/jenkins/template/SETTINGS +++ b/jenkins/template/SETTINGS @@ -17,12 +17,21 @@ # 24 June 2016 -- Jeremy Mordkoff -- Genesis # # this variable holds the name of the container image needed to build or run this product -export OSM_BASE_IMAGE=fc20 +export OSM_BASE_IMAGE=ubuntu:16.04 # # this variable holds the name of the container to be used to build a package # if this container already exists, the build process can skip the container build -export OSM_BUILD_CONTAINER=rift-build +export OSM_BUILD_CONTAINER=container_name-build +# +# this variable must be set to allow creating the build container in privileged mode +# this variable should be removed in the future when no privileged mode is required +#export OSM_BUILD_CONTAINER_PRIVILEGED=yes # # this variable holds the name of the container to be used to run a package # if this container already exists, the run processes can skip the container build -export OSM_RUNTIME_CONTAINER=rift-runtime +export OSM_RUNTIME_CONTAINER=container_name-runtime +# +# this variable must be set to allow creating the runtime container in privileged mode +# this variable should be removed in the future when no privileged mode is required +#export OSM_RUNTIME_CONTAINER_PRIVILEGED=yes +