Change in docker-playground[master]: osmo-gsm-tester: Build srsLTE inside the docker instance if inst not ...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Fri Mar 20 16:15:51 UTC 2020


pespin has submitted this change. ( https://gerrit.osmocom.org/c/docker-playground/+/17531 )

Change subject: osmo-gsm-tester: Build srsLTE inside the docker instance if inst not provided by host
......................................................................

osmo-gsm-tester: Build srsLTE inside the docker instance if inst not provided by host

osmo-gsm-tester.git/contrib/jenkins-build-srslte.sh cannot be used
because there's a need to split the fetch step from the build step.
That's because we want to fetch in the host (in order to use host's user
ssh key for potential private repos) while still building inside the
docker container, where we have all the dependencies (and where the
binaries are going to be run afterwards by osmo-gsm-tester).

During the changes above it was also noticed that /tmp/trial on the host
got its UID+GID changed (because we switch user inside the container to
downscale privileges). Fix it by chown'ing the directory back to the
host user's UID+GID.

Change-Id: Ia0db8fba840392a0b7883cfc15e45c2e80407a16
---
M osmo-gsm-tester/jenkins.sh
M osmo-gsm-tester/osmo-gsm-tester-master.sh
2 files changed, 81 insertions(+), 5 deletions(-)

Approvals:
  pespin: Looks good to me, approved; Verified



diff --git a/osmo-gsm-tester/jenkins.sh b/osmo-gsm-tester/jenkins.sh
index c114222..58768c4 100755
--- a/osmo-gsm-tester/jenkins.sh
+++ b/osmo-gsm-tester/jenkins.sh
@@ -1,11 +1,20 @@
 #!/bin/sh
 
-# This docket env allows running a typical osmo-gsm-tester setup with a main
+# This docker env allows running a typical osmo-gsm-tester setup with a main
 # unit (ogt-master) running osmo-gsm-tester process, and using another docker
 # container as a remote host where to run child processes.
 #
-# Trial directory must be set in the parent host's /tmp/trial path, which will
-# then be mounted to ogt-master and used my osmo-gsm-tester.
+# Trial directory to use may be placed in the container's host /tmp/trial path,
+# which will then be mounted to ogt-master and used my osmo-gsm-tester.
+# If no inst is detected, then jenkins.sh will attempt to fetch the sources in
+# the host system (so that host's user ssh keys are potentially available) under
+# /tmp/trial, and the inst is then later built inside the container.
+# Several env vars are available to tweak where to fetch from.
+# SRS_LTE_BRANCH: The srsLTE.git branch to fetch.
+# SRS_LTE_REPO_PREFIX: The URL & prefix patch from where to clone the srsLTe.git
+#                      repo.
+# SRS_LTE_REPO_NAME: The srsLTE.git repo name, usually "srsLTE", but known to
+#                    have different names on some forks.
 #
 # osmo-gsm-tester parameters and suites are passed to osmo-gsm-tester.sh in same
 # directory as this script using environment variable OSMO_GSM_TESTER_OPTS.
@@ -14,6 +23,35 @@
 # osmo-gsm-tester last run can be found as usual under the trial directory
 # (/tmp/trial/last_run).
 
+TRIAL_DIR="/tmp/trial"
+
+SRS_LTE_BRANCH=${SRS_LTE_BRANCH:-master}
+SRS_LTE_REPO_PREFIX=${SRS_LTE_REPO_PREFIX:-git at github.com:srsLTE}
+SRS_LTE_REPO_NAME=${SRS_LTE_REPO_NAME:-srsLTE}
+have_repo_srslte() {
+	echo "srsLTE inst not provided, fetching it now and it will be build in container"
+	if [ -d "${TRIAL_DIR}/${SRS_LTE_REPO_NAME}" ]; then
+		git fetch -C ${TRIAL_DIR}/${SRS_LTE_REPO_NAME}
+	else
+		mkdir -p ${TRIAL_DIR}
+		git clone "${SRS_LTE_REPO_PREFIX}/${SRS_LTE_REPO_NAME}" "${TRIAL_DIR}/${SRS_LTE_REPO_NAME}"
+	fi
+	# Figure out whether we need to prepend origin/ to find branches in upstream.
+	# Doing this allows using git hashes instead of a branch name.
+	if git -C "${TRIAL_DIR}/${SRS_LTE_REPO_NAME}" rev-parse "origin/$SRS_LTE_BRANCH"; then
+	  SRS_LTE_BRANCH="origin/$SRS_LTE_BRANCH"
+	fi
+
+	git -C "${TRIAL_DIR}/${SRS_LTE_REPO_NAME}" checkout -B build_branch "$SRS_LTE_BRANCH"
+	rm -rf "${TRIAL_DIR:?}/${SRS_LTE_REPO_NAME}/*"
+	git -C "${TRIAL_DIR}/${SRS_LTE_REPO_NAME}" reset --hard "$SRS_LTE_BRANCH"
+}
+
+# If srsLTE trial not provided by user, fetch srsLTE git repo and let the container build it:
+if [ "x$(ls ${TRIAL_DIR}/srslte.*.tgz 2>/dev/null | wc -l)" = "x0" ]; then
+	have_repo_srslte
+fi
+
 . ../jenkins-common.sh
 IMAGE_SUFFIX="${IMAGE_SUFFIX:-master}"
 docker_images_require \
@@ -51,8 +89,11 @@
 		--network $NET_NAME \
 		--ip 172.18.50.2 \
 		-v $VOL_BASE_DIR/ogt-master:/data \
-		-v /tmp/trial:/tmp/trial \
+		-v "${TRIAL_DIR}:/tmp/trial" \
 		-e "OSMO_GSM_TESTER_OPTS=${OSMO_GSM_TESTER_OPTS}" \
+		-e "SRS_LTE_REPO_NAME=${SRS_LTE_REPO_NAME}" \
+		-e "HOST_USER_ID=$(id -u)" \
+		-e "HOST_GROUP_ID=$(id -g)" \
 		--name ${BUILD_TAG}-ogt-master \
 		$REPO_USER/osmo-gsm-tester
 
diff --git a/osmo-gsm-tester/osmo-gsm-tester-master.sh b/osmo-gsm-tester/osmo-gsm-tester-master.sh
index 975e4e5..bd8a659 100755
--- a/osmo-gsm-tester/osmo-gsm-tester-master.sh
+++ b/osmo-gsm-tester/osmo-gsm-tester-master.sh
@@ -11,4 +11,39 @@
 ip addr add 172.18.50.9/24 dev eth0
 ip addr add 172.18.50.10/24 dev eth0
 
-su -c "python3 -u /tmp/osmo-gsm-tester/src/osmo-gsm-tester.py /tmp/trial $OSMO_GSM_TESTER_OPTS" -m jenkins
+build_srslte() {
+        git_repo_dir="/tmp/trial/${SRS_LTE_REPO_NAME}"
+        if [ ! -d "$git_repo_dir" ]; then
+                echo "No external trial nor git repo provided for srsLTE!"
+                exit 1
+        fi
+        pushd "/tmp/trial"
+        rm -rf inst && mkdir inst
+        rm -rf build && mkdir build && cd build || exit 1
+        cmake -DCMAKE_INSTALL_PREFIX="../inst/" "${git_repo_dir}"
+        set +x; echo; echo; set -x
+        make "-j$(nproc)"
+        set +x; echo; echo; set -x
+        make install
+        this="srslte.build-${BUILD_NUMBER-$(date +%Y-%m-%d_%H_%M_%S)}"
+        tar="${this}.tgz"
+        tar czf "/tmp/trial/$tar" -C "/tmp/trial/inst" .
+        cd "/tmp/trial/" && md5sum "$tar" >>checksums.md5
+        popd
+}
+
+# Build srsLTE.git if not provided by host system:
+if [ "x$(ls /tmp/trial/srslte.*.tgz 2>/dev/null | wc -l)" = "x0" ]; then
+        build_srslte
+fi
+
+# Make trial dir avaialable to jenkins user inside container:
+chown -R jenkins /tmp/trial/
+
+rc=0
+su -c "python3 -u /tmp/osmo-gsm-tester/src/osmo-gsm-tester.py /tmp/trial $OSMO_GSM_TESTER_OPTS" -m jenkins || rc=$?
+
+# Make trial dir again owned by user running the container:
+chown -R "${HOST_USER_ID}:${HOST_GROUP_ID}" /tmp/trial/
+
+exit $rc

-- 
To view, visit https://gerrit.osmocom.org/c/docker-playground/+/17531
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: docker-playground
Gerrit-Branch: master
Gerrit-Change-Id: Ia0db8fba840392a0b7883cfc15e45c2e80407a16
Gerrit-Change-Number: 17531
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200320/7b1b9318/attachment.htm>


More information about the gerrit-log mailing list