aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarehbein <arehbein@sysmocom.de>2023-02-06 04:01:40 +0100
committerarehbein <arehbein@sysmocom.de>2023-09-26 23:27:16 +0200
commit5000f4b8518f548897404550cf32e1e32527d774 (patch)
tree30bf3a8c115f8cfa0a7c173c6005855a4d390a48
parent71741e4f6c167e519a686a4c629d7c94e10b3492 (diff)
scripts/docker-playground_adapt: Add feature to sync custom ttcn3-hacks into Docker image for folder debian-bullseye-titan
-rwxr-xr-xscripts/docker-playground_adapt71
1 files changed, 50 insertions, 21 deletions
diff --git a/scripts/docker-playground_adapt b/scripts/docker-playground_adapt
index 1a76ccc..6ced11f 100755
--- a/scripts/docker-playground_adapt
+++ b/scripts/docker-playground_adapt
@@ -17,13 +17,14 @@ usage () {
USAGE_STR="${USAGE_STR} -o, --osmo-ttcn3-branch Point to branch OSMO_TTCN3_BRANCH of osmo-ttcn3-hacks repo.\n"
USAGE_STR="${USAGE_STR} -l, --list-files List target files that will be changed/restored.\n"
USAGE_STR="${USAGE_STR} -d, --subdir Operate on target subdir SUBDIR of docker-playground. Has different effects depending on the actions taken (e.g. for TTCN3 branch adaption, it doesn't change anything)\n"
+ USAGE_STR="${USAGE_STR} Directory names usually end on '-master' or '-titan'\n"
USAGE_STR="${USAGE_STR} -A, --ADD Adapt Dockerfile: Essentially exchange 'git clone' command with a Dockerfile ADD. Only for 'osmo-*-master' folders, if REPO_DIR isn't given, a default repo folder \n"
USAGE_STR="${USAGE_STR} (e.g. SUBDIR/osmo-bts-repo for SUBDIR osmo-bts-master) will be expected to already exist.\n"
USAGE_STR="${USAGE_STR} -n, --no-prompt Don't prompt for changes.\n" # "Applies to the previous option used (for testcases: Don't prompt if multiple cfg files are possibly found. for --ADD: Don't prompt if subdir already exists.\n"
USAGE_STR="${USAGE_STR} -a, --append Append testcase to existing list of testcases.\n"
USAGE_STR="${USAGE_STR} -t, --testcases Give testcase(s) TTCN3_TESTCASE of format <TTCN3_TESTSUITE>.<TC_NAME>. For each '-t' option item, the testsuite prefix (including the dot) need to be given only once.\n"
USAGE_STR="${USAGE_STR} Will prompt for files to manipulate since there are subdirectories sometimes with alternative config files.\n"
- USAGE_STR="${USAGE_STR} Will not prompt for anything, if docker-playground repository subdirectory SUBDIR with the TTCN3 testconfig is given\n"
+ USAGE_STR="${USAGE_STR} Will not prompt for anything, if docker-playground repository subdirectory SUBDIR (usually starting with 'ttcn3-') with the TTCN3 testconfig is given\n"
USAGE_STR="${USAGE_STR} Example:\n"
USAGE_STR="${USAGE_STR} -t NS_Tests.TC_sns_sgsn_add TC_sns_sgsn_second_add\n"
USAGE_STR="${USAGE_STR} $RESTORE_NOTE_TC\n"
@@ -121,10 +122,13 @@ adapt_ttcn3_testcases() {
fi
continue
fi
- if [ -z "$SUBDIR" ]; then
+ if [ -z "$SUBDIR_DOCKER" ]; then
FNAME_REGEX="/$TESTSUITE_CFG"
else
- FNAME_REGEX="/$SUBDIR/.*/\?$TESTSUITE_CFG"
+ if ! echo $SUBDIR_DOCKER | grep -q 'ttcn3-'; then
+ echo "Note: Testcase adaption usually only makes sense for docker-playground directories starting with 'ttcn3-'"
+ fi
+ FNAME_REGEX="/$SUBDIR_DOCKER/.*/\?$TESTSUITE_CFG"
fi
if [ -n "$TESTCASES" ] && echo "$file" | grep -q "[^/]*$FNAME_REGEX"; then
if [ -z "$NO_PROMPT" ] && ! user_wants "Adapt file $file?" "$NO_PROMPT"; then # Multiple cfg files possible, so we prompt
@@ -163,13 +167,13 @@ adapt_ttcn3_testcases() {
}
adapt_dockerfile_checkdir() {
- if ! echo "$SUBDIR_DOCKER" | grep -q '.*-master'; then
+ if ! echo "$SUBDIR_DOCKER" | grep -q '.*-master' && ! echo "$SUBDIR_DOCKER" | grep -q '.*-titan'; then
if [ -n "$RESTORE" ]; then
local adapt_restore="restoring"
else
local adapt_restore="adapting"
fi
- if ! user_wants "$SUBDIR_DOCKER doesn't end on '-master', are you sure you want to proceed with $adapt_restore the Dockerfile in $(pwd)?"; then
+ if ! user_wants "$SUBDIR_DOCKER doesn't end on '-master' or '-titan', are you sure you want to proceed with $adapt_restore the Dockerfile in $(pwd)?"; then
echo "Exiting because there is nothing else to be done" # Keep this as the last action
exit 0
fi
@@ -192,25 +196,46 @@ adapt_dockerfile_install() {
}
adapt_dockerfile_add() {
- DST_REPO_SUBDIR="$(echo $SUBDIR_DOCKER | sed 's/-master//')" #TODO: Make subdir adaptable in case some dirs don't play nice... I think our docker playground scripts are adapted to play nice though
+ # DST_REPO_SUBDIR="$(echo $SUBDIR_DOCKER | sed 's/-master//')" #TODO: Make subdir adaptable in case some dirs don't play nice... I think our docker playground scripts are adapted to play nice though
+ DST_REPO_SUBDIR="$(basename $ADD_REPO_PATH)"
if [ -n "$ADD_REPO_PATH" ]; then
- if [ -d "$DST_REPO_SUBDIR" ]; then
- if ! user_wants "$DST_REPO_SUBDIR already exists. Do you want to update its contents with contents from $ADD_REPO_PATH?" "$NO_PROMPT"; then
- exit 0
+ if [ -d "$DST_REPO_SUBDIR" ]; then
+ wants="yes"
+ if ! user_wants "$SUBDIR_DOCKER/$DST_REPO_SUBDIR already exists. Do you want to update its contents with contents from $ADD_REPO_PATH?" "$NO_PROMPT"; then
+ wants=""
fi
fi
- rsync -avz "$ADD_REPO_PATH/" "$DST_REPO_SUBDIR" >/dev/null
- if [ $? -ne 0 ]; then
- echo "Error rsyncing" >&2
- exit 1
+ if [ -n "$wants" ]; then
+ rsync -avz "$ADD_REPO_PATH" . >/dev/null
+ echo "$ADD_REPO_PATH" > "$DST_REPO_SUBDIR/COPY_SRC.txt"
+ if [ $? -ne 0 ]; then
+ echo "Error rsyncing" >&2
+ exit 1
+ fi
+ echo -e "Source dir: $ADD_REPO_PATH\nSynced: $(date)" > "$DST_REPO_SUBDIR/source_dir.txt"
fi
- echo -e "Source dir: $ADD_REPO_PATH\nSynced: $(date)" > "$DST_REPO_SUBDIR/source_dir.txt"
fi
if (( $(cat Dockerfile | grep 'RUN.*git clone' | wc -l) > 1 )); then
echo "Found more than one line entry matching 'CMD.*git clone' in '"$(pwd)"'/Dockerfile, not proceeding" >&2
exit 1
fi
+
sed -i 's:RUN.*git clone.*$:ADD\t'"$DST_REPO_SUBDIR"' '"$DST_REPO_SUBDIR"':g' Dockerfile # Should fit the Dockerfile, e.g. 'osmo-bts' still being used inside Docker
+ if echo "$SUBDIR_DOCKER" | grep -q '.*-titan'; then
+ echo "Deactivating some error checks related to Git procedures in Docker prepare script in order for Docker to use custom osmo-ttcn3-hacks folder"
+ # Change line for running make
+ sed -i 's:\(\tmake -j8 -C /osmo-ttcn3-hacks deps\):RUN\1:g' Dockerfile
+ sed -i 's:if ! diff -q /tmp/deps-Makefile /osmo-ttcn3-hacks/deps/Makefile;:if false;:g' Dockerfile
+ # sed -i 's:\(\#!/bin/sh\) -e:\1:g' Dockerfile
+ # Add noop so as not to break if-else due to empty if-body
+ sed -i 's/\(^[\t ]*git\)/: #\1/g' ttcn3-docker-prepare.sh
+ fi
+
+
+ if echo "$SUBDIR_DOCKER" | grep -q '.*-titan'; then
+ return
+ fi
+ # ASSUMPTION: Only for -titan directories, we won't do this. Will probably be changed if I ever think about adapting Dockerfiles in ttcn3-* directories...
CD_LINE="RUN.*cd $DST_REPO_SUBDIR"
# INSTALL_LINE=".*make.*install$"
AUTORECONF_LINE=".*autoreconf.*fi"
@@ -301,7 +326,8 @@ while [ "$1" != "" ]; do
determine_subdir_docker
ADD="yes"
if [ -n "$VALUE" ] && ! echo $VALUE | grep -q "^-.*"; then
- ADD_REPO_PATH="$(readlink -f $VALUE)"
+ # sed: Remove trailing slashes for rsync
+ ADD_REPO_PATH="$(echo $(readlink -f $VALUE) | sed -s 's:\([^/]*\)/*$:\1:g')"
if ! [ -d "$ADD_REPO_PATH" ]; then
echo "Error: Couldn't find path $ADD_REPO_PATH" >&2
exit 1
@@ -459,17 +485,20 @@ if [ -n "$ADD" ] || [ -n "$INSTALL_PKGS" ]; then # No files to list
else
adapt_dockerfile_checkdir
if [ -n "$RESTORE" ]; then
- if ! git checkout -q Dockerfile; then
- echo "Error restoring file Dockerfile" >&2
+ if ! git checkout -q -- Dockerfile ttcn3-docker-prepare.sh; then
+ echo "Error restoring files Dockerfile ttcn3-docker-prepare.sh" >&2
RESTORE_ERR=1
fi
- return 0
- fi
- if [ -n "$ADD" ]; then
+ elif [ -n "$ADD" ]; then
adapt_dockerfile_add
fi
if [ -n "$INSTALL_PKGS" ]; then
- adapt_dockerfile_install
+ if ! echo "$SUBDIR_DOCKER" | grep -q '.*-titan'; then
+ adapt_dockerfile_install
+ else
+ echo "Note: Directory ends on '-titan', assuming this was an error"
+ echo "Not adding package installation(s) to Docker image creation"
+ fi
fi
fi
fi