1. VectorLinux Core
  2. vlbuildbot

Commits

M0E-lnx  committed ad6deea

Adding scripts for run-only slave tools

  • Participants
  • Parent commits c0786d0
  • Branches master

Comments (0)

Files changed (2)

File slave/sbin/ro-chrootTEST

View file
+#!/bin/bash
+RUN=$1
+CHROOT_ARG=$2
+TARGETHASH=$3
+source /etc/vlbuildslave/slavehost.conf
+
+if [ -z "$GITREPO" ]; then
+	echo "GITREPO variable is empty.  This needs to point to the repo we are using" >&2
+	exit 1
+fi
+exit_status=""
+TARGET=${TARGETHASH}
+
+# Catch the kill signal to for clean kills
+trap "sh /usr/local/bin/postbuild-cleanup $TARGET; sleep 3; /usr/local/bin/postbuild-cleanup $TARGET" TERM INT
+
+
+mkdir -p CHROOT-RO CHROOT-RWSB $TARGET
+umount $TARGET/dev > /dev/null 2>&1
+umount $TARGET/proc > /dev/null 2>&1
+umount $TARGET > /dev/null 2>&1
+#mount -o loop,ro $1 CHROOT-RO
+#mount -t aufs -o br=CHROOT-RWSB=rw:CHROOT-RO=ro none CHROOTSB || exit 1
+mount -t aufs -o br=CHROOT-RWSB=rw:CHROOT-RO=ro,xino=/dev/shm/aufs.xino$(mcookie) none $TARGET || exit 1
+cp /etc/resolv.conf $TARGET/etc/
+mount -t proc none $TARGET/proc
+mount -o bind /dev/ $TARGET/dev
+
+# mount the source repo
+mount -o bind $GITREPO $TARGET/home/slackbuilds
+
+chroot $TARGET $RUN
+let exit_status=$?
+
+#umount CHROOTSB/var/vabs
+umount $TARGET/dev
+umount $TARGET/proc
+umount $TARGET/home/slackbuilds
+umount $TARGET
+exit $exit_status
+

File slave/usr/local/bin/changetest.sh

View file
+#!/bin/bash
+
+# This will call /sbin/ro-chrootTEST using the following variables
+# REPO=.. - This is the path to the git repo we will mount inside the chroot
+
+# file needs to save the build list either to a text file in the JAIL or to a variable
+# Once inside the chroot, we need to iterate over the list of changed files, and build each SB
+
+# IMPORTANT: Assumes the bot master will set 'workingdir' to the repo to be used.
+
+GITREPO=${GITREPO:-$(pwd)}
+CONF=/etc/vlbuildslave/slavehost.conf
+SRC_CACHE=/tmp/sources-cache
+
+function exit_error {
+msg=$1
+echo $msg >&2
+exit 1
+}
+
+source $CONF || exit_error "Unable to source $CONF"
+
+function get_jail_path {
+	# Determine which jail environment to use for running the test build
+	# This is done by reading the values of REPOBRANCH and VLBB_TARGET_ARCH
+	# Both of these are set to the ENV on the builder configuration at the bot master
+	verstr=$(branch_to_vlrelease $REPOBRANCH)
+	case "$VLBB_TARGET_ARCH" in
+		x86_64|amd64 )
+			JAILV="64c$verstr"
+			;;
+		i[3456]86|x86)
+			JAILV="32c$verstr"
+			;;
+	esac
+	if [ -z $JAILV ]; then
+		# Unable to determine jail.  Exit
+		exit_error "Unable to determine jail path.  Make sure VLBB_TARGET_ARCH and REPOBRANCH are set"
+	fi
+	echo ${CHROOTS[$JAILV]}
+
+}
+
+function changed_paths {
+	# Find the list of changed files.  We need to do this because we monitor an entire git tree.
+	# so, we have to find this list so we know what we need to build.  If we dont do this, we would
+	# have to build the entire tree.
+	#
+	# Returns a list of application folders that changed. <----
+	gitdir=$GITREPO/.git
+	worktree=$GITREPO
+	# git diff-tree --no-commit-id --name-only -r HEAD|cut -f 3 -d /|uniq
+	RES=$(git --git-dir="$gitdir" --work-tree="$worktree" diff-tree --no-commit-id --name-only -r HEAD | cut -f 3 -d / |uniq)
+	echo $RES
+
+}
+
+function can_source {
+	# Test if we can safely source this slackbuild.  returns "YES" or "NO"
+	sbpath=$1
+	res="NO"
+	for line in "$(grep "NORUN" $sbpath)"; do
+		first="${line:0:1}"
+		if [ "$first" != "#" ]; then
+			res="YES"
+			break
+		fi
+	done
+	echo $res
+}
+
+function process_link {
+	# See if we can avoid a download by running the the LINK through a cache.
+	# If the file is not found, we will download it to the cache dir in case we need to build the same version again
+	sbpath=$1
+	# Check to make sure we have a NORUN in the SB
+	if [ "$(can_source $sbpath)" != "YES" ]; then
+		echo "$(basename $sbpath) does cannot be sourced without running it.  Make sure it has a NORUN if statement"; exit 1
+	else
+		NORUN=1 source $sbpath
+		mkdir -p $SRC_CACHE
+		( cd $SRC_CACHE
+			for url in $(echo $LINK); do
+				wget -c --no-check-certificate $url
+			done
+		)
+	fi
+}
+
+function main {
+	# Main operation here.  This is where we turn things over to the jail.
+	# We need to set $APPNAME
+	buildlist=$(echo `changed_paths`)
+	jail=$(echo `get_jail_path`)
+	# Run a sanity test to make sure we have a jail
+	if [ -z $jail ]; then
+		exit_error "Unable to determine jail to be used.  Aborting build(s)"
+		exit 1
+	fi
+	if [ "x$buildlist" = "x" ]; then
+		echo "No changes in git tree.  Nothing to build"
+		exit 1
+	fi
+	for app in $buildlist; do
+		sbpath="$GITREPO/var/vabs/$app/src/$app.SlackBuild"
+		srcpath=$(dirname $sbpath)
+		export APPNAME=$app
+		# Prepare the jail
+		( cd $jail
+			# remove any previous build dirs
+			rm -rf CHROOT-RWSB.$APPNAME
+			rm -rf CHROOT-RWSB
+			mkdir -p CHROOT-RWSB/{tmp/builds,usr/local/bin}
+			# Copy the tools from the host to the chroot
+			cp -arxp /usr/local/bin/* CHROOT-RWSB/usr/local/bin
+			# We will run this script as soon as we get into the chroot
+			cat /usr/local/bin/build-runner > CHROOT-RWSB/tmp/$APPNAME.build || exit 1
+			chmod +x CHROOT-RWSB/tmp/$APPNAME.build
+			# See if we can copy the source tarball from cache
+			if [ "$(can_source $sbpath)" = "YES" ]; then
+				echo "Downloading $app source to cache dir $SRC_CACHE"
+				process_link $sbpath || exit 1
+				# Copy the source to the build dir
+				NORUN=1 source $sbpath
+				for i in $(echo "$LINK"); do
+					echo "Attempting to copy source file to $srcpath"
+					cp -v $SRC_CACHE/$(basename $i) $srcpath
+				done
+			fi
+		)
+		export TARGETHASH=CHROOTSB-$$
+		trap "/usr/local/bin/postbuild-cleanup $TARGETHASH" TERM INT HUP
+		# Launch the build
+		echo "Building $app in jail $(basename $jail)"
+		echo ;
+		cd $jail
+			/sbin/ro-chrootTEST "sh /tmp/$APPNAME.build" "$APPNAME" "$TARGETHASH" || exit 1
+			let RETVAL=$?
+		# Clean up the build dir... remove the source tarball from there
+		rm -f $srcpath/*.tar.*
+
+#		# Just in case anything is still mounted
+		cd /
+
+		# TARGT shouldb set by ro-chrootSB
+		/usr/local/bin/postbuild-cleanup $jail/$TARGETHASH
+
+		# Indicate the return value to the bot
+		if [ ! $RETVAL = 0 ]; then
+			exit_error "$APPNAME build failed"
+		fi
+
+
+
+	done
+
+}
+
+export NUMJOBS="-j$(count_cpus)"
+main