summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordd <dd@wx.tnyzeq.icu>2024-07-12 17:58:27 +0200
committerdd <dd@wx.tnyzeq.icu>2024-07-12 17:58:27 +0200
commit6c7ddb626bab489dbc684d5416b185fdad493d4e (patch)
tree805d49063fcb2ab1ffaaf87dfb102a36da8f812a
parentf1b433793c1a268170517ec51b321397393ed1cc (diff)
downloadvyos-jenkins-6c7ddb626bab489dbc684d5416b185fdad493d4e.tar.gz
vyos-jenkins-6c7ddb626bab489dbc684d5416b185fdad493d4e.zip
improved build-iso error handling
-rw-r--r--auto/helper-logic69
-rwxr-xr-xbuild-iso.sh95
2 files changed, 88 insertions, 76 deletions
diff --git a/auto/helper-logic b/auto/helper-logic
index 7a60121..083f086 100644
--- a/auto/helper-logic
+++ b/auto/helper-logic
@@ -134,6 +134,17 @@ function PrintJobFailed {
>&2 echo -e "[ ${RED}Failed!${NOCOLOR} ] Package: $1 - Branch: $2"
}
+function IsFlagSet {
+ flag="$1"
+ shift
+ for arg; do
+ if [[ $arg == "$flag" ]]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
function Run {
command="$1"
infoMessage="$2"
@@ -167,6 +178,64 @@ function Run {
fi
}
+function RunWithLazyStdout {
+ set -e
+ command=$1
+
+ # stop the background command on ctrl+c
+ # and cleanup temporary file and tail on exit
+ stty -echoctl
+ trap stop INT TERM
+ trap cleanup EXIT
+
+ function stop {
+ kill $pid || true
+
+ wait $pid
+ exitCode=$?
+
+ cleanup
+ exit $exitCode
+ }
+
+ function cleanup {
+ stty echo
+ if [ "$buffer" != "" ]; then
+ rm -f $buffer 2> /dev/null || true
+ fi
+ if [ "$tailPid" != "" ]; then
+ kill $tailPid || true
+ fi
+ }
+
+ buffer=$(mktemp -p /tmp --suffix=-background-buffer)
+
+ $command > $buffer &
+ pid=$!
+
+ echo "Show output? Press y..."
+ while ps -p $pid > /dev/null
+ do
+ if [ "$tailPid" == "" ]; then
+ read -s -n 1 -t 1 input || true
+ if [ "$input" == "y" ]; then
+ tail -f -n +1 $buffer &
+ tailPid=$!
+ fi
+ else
+ sleep 1
+ fi
+ done
+
+ wait $pid
+ exit $?
+}
+
+function FilterStderr {
+ ( set -e; eval "$1" 2>&1 1>&3 | (grep -v -E "$2" || true); exit ${PIPESTATUS[0]}; ) 1>&2 3>&1
+ return $?
+}
+
function EnsureJenkinsCli {
if [ ! -f jenkins-cli.jar ]; then
PrintEmptyIndicator "Download Jenkins CLI..."
diff --git a/build-iso.sh b/build-iso.sh
index dc66470..56905af 100755
--- a/build-iso.sh
+++ b/build-iso.sh
@@ -32,11 +32,11 @@ if [ -d vyos-build ]; then
fi
echo "Cloning the VyOS build repository..."
-git clone https://github.com/dd010101/vyos-build > /dev/null 2>&1
+git clone -q https://github.com/dd010101/vyos-build > /dev/null
pushd vyos-build > /dev/null
echo "Checking out the $BRANCH branch..."
-git checkout "$BRANCH" > /dev/null 2>&1
+git checkout "$BRANCH" > /dev/null
function HandleBranding {
if [ "$NOT_VYOS" != "" ]; then
@@ -64,9 +64,12 @@ function HandleBranding {
fi
}
(set -e; HandleBranding)
+if [ $? -ne 0 ]; then
+ PrintErrorIndicator "Branding removal failed"
+fi
echo "Downloading apt signing key..."
-wget http://172.17.17.17/apt.gpg.key -O /tmp/apt.gpg.key > /dev/null 2>&1
+curl -s -S --fail-with-body http://172.17.17.17/apt.gpg.key -o /tmp/apt.gpg.key
DATE=$(date +%Y%m%d)
@@ -74,7 +77,7 @@ popd > /dev/null
function GetLatestTag {
# Clone the vyos-1x repo
- git clone --bare https://github.com/vyos/vyos-1x.git -b $1 temp-git-tag > /dev/null 2>&1
+ git clone -q --bare https://github.com/vyos/vyos-1x.git -b $1 temp-git-tag > /dev/null
pushd temp-git-tag > /dev/null
# The the latest tag for this branch
@@ -84,64 +87,6 @@ function GetLatestTag {
rm -rf temp-git-tag
}
-function RunWithLazyStdout {
- set -e
- command=$1
-
- # stop the background command on ctrl+c
- # and cleanup temporary file and tail on exit
- stty -echoctl
- trap stop INT TERM
- trap cleanup EXIT
-
- function stop {
- kill $pid || true
-
- wait $pid
- exitCode=$?
-
- cleanup
- exit $exitCode
- }
-
- function cleanup {
- stty echo
- if [ "$buffer" != "" ]; then
- rm -f $buffer 2> /dev/null || true
- fi
- if [ "$tailPid" != "" ]; then
- kill $tailPid || true
- fi
- }
-
- buffer=$(mktemp -p /tmp --suffix=-background-buffer)
-
- $command > $buffer &
- pid=$!
-
- echo "Show output? Press y..."
- while ps -p $pid > /dev/null
- do
- if [ "$tailPid" == "" ]; then
- read -s -n 1 -t 1 input || true
- if [ "$input" == "y" ]; then
- tail -f -n +1 $buffer &
- tailPid=$!
- fi
- else
- sleep 1
- fi
- done
-
- wait $pid
- exit $?
-}
-
-function FilterStderr {
- ( set -e; eval "$1" 2>&1 1>&3 | (grep -v -E "$2" || true); exit ${PIPESTATUS[0]}; ) 1>&2 3>&1
- return $?
-}
-
echo "Building the ISO..."
if [ "$BRANCH" == "equuleus" ]; then
LATEST=`GetLatestTag equuleus`
@@ -162,13 +107,6 @@ if [ "$BRANCH" == "equuleus" ]; then
docker run --rm --privileged --name="vyos-build" -v ./vyos-build/:/vyos -v "/tmp/apt.gpg.key:/opt/apt.gpg.key" -w /vyos --sysctl net.ipv6.conf.lo.disable_ipv6=0 -e GOSU_UID=$(id -u) -e GOSU_GID=$(id -g) -w /vyos vyos/vyos-build:equuleus \
sudo make iso
}
-
- (
- FilterStderr "( RunWithLazyStdout \"DockerBuild $BUILD_BY $RELEASE_NAME\" )" "(useradd warning)"
- exit $?
- )
-
- BUILD_EXIT_CODE=$?
elif [ "$BRANCH" == "sagitta" ]; then
LATEST=`GetLatestTag sagitta`
RELEASE_NAME="$LATEST-release-$DATE"
@@ -185,18 +123,23 @@ elif [ "$BRANCH" == "sagitta" ]; then
--custom-apt-key /opt/apt.gpg.key \
--custom-package vyos-1x-smoketest
}
-
- (
- FilterStderr "( RunWithLazyStdout \"DockerBuild $BUILD_BY $RELEASE_NAME\" )" "(useradd warning)"
- exit $?
- )
-
- BUILD_EXIT_CODE=$?
else
>&2 echo -e "${RED}Invalid branch${NOCOLOR}"
exit 1
fi
+dockerBuild="DockerBuild $BUILD_BY $RELEASE_NAME"
+if ! IsFlagSet "-v" "$@"; then
+ dockerBuild="RunWithLazyStdout \"$dockerBuild\""
+fi
+
+(
+ FilterStderr "( $dockerBuild )" "(useradd warning)"
+ exit $?
+)
+
+BUILD_EXIT_CODE=$?
+
if [ $BUILD_EXIT_CODE != 0 ]; then
>&2 echo -e "${RED}ISO build failed${NOCOLOR}"
exit 1