From 0fa204e179b6d41990cd683509491a63db0bf507 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 12 Aug 2021 15:16:11 +0200 Subject: [PATCH] ttcn3.sh: build everything inside docker Replace the previous approach of building outside of docker and mounting everything inside docker while running tests, with also building everything inside docker. This prevents incompatibilities between host system and docker (e.g. different glibc). As nice side-effect, /usr/local is not filled up anymore. Change-Id: Ib6db8ffd916c788c9de0b3d51c82e1d7bb3f6828 --- .gitignore | 2 ++ ttcn3/scripts/docker_configure_make.sh | 38 +++++++++++++++++++++++ ttcn3/ttcn3.sh | 43 ++++++++++++++++++++------ 3 files changed, 73 insertions(+), 10 deletions(-) create mode 100755 ttcn3/scripts/docker_configure_make.sh diff --git a/.gitignore b/.gitignore index 6326775..61d0fcf 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ net/* ttcn3/3G+2G_ttcn3.deps ttcn3/out/ ttcn3/make/ +ttcn3/.run.sh +ttcn3/usr_local diff --git a/ttcn3/scripts/docker_configure_make.sh b/ttcn3/scripts/docker_configure_make.sh new file mode 100755 index 0000000..25cedb4 --- /dev/null +++ b/ttcn3/scripts/docker_configure_make.sh @@ -0,0 +1,38 @@ +#!/bin/sh -ex +# Passed by ttcn3.sh to gen_makefile.py to run './configure', 'make' and +# 'make install' inside docker. The osmo-dev directory is mounted at the same +# location inside the docker container. A usr_local dir is mounted to +# /usr/local, so 'make install' can put all files there and following builds +# have the files available. +DIR_OSMODEV="$(readlink -f "$(dirname $0)/../..")" +DIR_MAKE="$DIR_OSMODEV/ttcn3/make" +DIR_USR_LOCAL="$DIR_OSMODEV/ttcn3/usr_local" +RUN_SCRIPT="$DIR_OSMODEV/ttcn3/.run.sh" +DOCKER_IMG="$1" +UID="$(id -u)" +shift + +mkdir -p "$DIR_MAKE" + +# Script running as user inside docker +echo "#!/bin/sh -ex" > "$RUN_SCRIPT" +echo "cd \"$PWD\"" >> "$RUN_SCRIPT" +for i in "$@"; do + echo -n "'$i' " >> "$RUN_SCRIPT" +done +echo >> "$RUN_SCRIPT" +chmod +x "$RUN_SCRIPT" + +docker run \ + --rm \ + -e "LD_LIBRARY_PATH=/usr/local/lib" \ + -v "$DIR_OSMODEV:$DIR_OSMODEV" \ + -v "$DIR_USR_LOCAL:/usr/local" \ + -v "$RUN_SCRIPT:/tmp/run.sh:ro" \ + "$DOCKER_IMG" \ + sh -ex -c " + if ! id -u $UID 2>/dev/null; then + useradd -u $UID user + fi + su \$(id -un $UID) -c /tmp/run.sh + " diff --git a/ttcn3/ttcn3.sh b/ttcn3/ttcn3.sh index 9f8c1f3..6300ff7 100755 --- a/ttcn3/ttcn3.sh +++ b/ttcn3/ttcn3.sh @@ -4,8 +4,15 @@ PROJECT_UPPER="$(echo "$PROJECT" | tr '[:lower:]' '[:upper:]')" DIR_OSMODEV="$(readlink -f "$(dirname $0)/..")" DIR_MAKE="${DIR_MAKE:-${DIR_OSMODEV}/ttcn3/make}" DIR_OUTPUT="${DIR_OUTPUT:-${DIR_OSMODEV}/ttcn3/out}" +DIR_USR_LOCAL="$DIR_OSMODEV/ttcn3/usr_local" JOBS="${JOBS:-9}" +# Osmocom libraries and programs relevant for the current testsuite will be +# built in this container. It must have all build dependencies available and +# be based on the same distribution that master-* containers are based on, so +# there are no incompatibilities with shared libraries. +DOCKER_IMG_BUILD="debian-stretch-jenkins" + check_usage() { if [ -z "$PROJECT" ]; then echo "usage: $(basename $0) PROJECT" @@ -101,6 +108,9 @@ setup_dir_make() { echo "osmo-ttcn3-hacks" echo "osmocom-bb") > ttcn3/3G+2G_ttcn3.deps + local docker_cmd="$DIR_OSMODEV/ttcn3/scripts/docker_configure_make.sh" + docker_cmd="$docker_cmd $USER/$DOCKER_IMG_BUILD" + ./gen_makefile.py \ ttcn3/3G+2G_ttcn3.deps \ default.opts \ @@ -109,7 +119,10 @@ setup_dir_make() { no_doxygen.opts \ no_dahdi.opts \ no_optimization.opts \ - ttcn3/ttcn3.opts -I -m "$DIR_MAKE" + ttcn3/ttcn3.opts \ + --docker-cmd "$docker_cmd" \ + --make-dir "$DIR_MAKE" \ + --no-ldconfig } # $1: name of repository (e.g. osmo-ttcn3-hacks) @@ -157,7 +170,7 @@ prepare_local_bin() { ttcn3-docker-run.sh) name_install="ttcn3-docker-run" ;; esac - script_path_localbin="/usr/local/bin/$name_install" + script_path_localbin="$DIR_USR_LOCAL/bin/$name_install" if [ -x "$script_path_localbin" ]; then continue fi @@ -185,25 +198,34 @@ build_osmo_program_subdir() { # $1 program build_osmo_program_osmodev() { local repo="$(get_program_repo "$program")" + local usr_local_bin="$DIR_USR_LOCAL/bin" make -C "$DIR_MAKE" "$repo" - local path="$(command -v "$program")" - if [ -z "$path" ]; then - echo "ERROR: program was not installed to PATH: $program" - echo "Maybe you need to add /usr/local/bin to PATH?" + if [ -z "$(find "$usr_local_bin" -name "$program")" ]; then + echo "ERROR: program was not installed properly: $program" + echo "Expected it to be in path: $PATH_dest" exit 1 fi - local pathdir="$(dirname "$path")" local reference="$DIR_MAKE/.make.$repo.build" - if [ -z "$(find "$pathdir" -name "$program" -newer "$reference")" ]; then + if [ -z "$(find "$usr_local_bin" -name "$program" -newer "$reference")" ]; then echo "ERROR: $path is outdated!" echo "Maybe you need to pass a configure argument to $repo.git, so it builds and installs $program?" - echo "Or the order in PATH is wrong?" exit 1 fi } +prepare_docker_build_container() { + local marker="$DIR_OSMODEV/ttcn3/make/.ttcn3-docker-build" + + if [ -e "$marker" ]; then + return + fi + + make -C "$DIR_OSMODEV/src/docker-playground/$DOCKER_IMG_BUILD" + touch "$marker" +} + # Use osmo-dev to build one Osmocom program and its dependencies build_osmo_programs() { local program @@ -247,7 +269,7 @@ run_docker() { cd "$(get_testsuite_dir_docker)" export DOCKER_ARGS="\ -e LD_LIBRARY_PATH=/usr/local/lib \ - -v /usr/local:/usr/local:ro \ + -v "$DIR_USR_LOCAL":/usr/local:ro \ -v $hacks:/osmo-ttcn3-hacks:ro \ " export NO_LIST_OSMO_PACKAGES=1 @@ -283,6 +305,7 @@ clone_repo "osmo-ttcn3-hacks" clone_repo "docker-playground" check_dir_testsuite prepare_local_bin +prepare_docker_build_container build_osmo_programs build_testsuite remove_old_logs