nm-in-container: bind mount additional directories
- If ".git/nm-in-container-host" exists, bind mount all of "/" to "/Host". - also honor all ".git/nm-data-link-*" files for additional directories to bind mount. - as before, honor ".git/NetworkManager-ci" symlink. Note that directories also get symlinked from "/". Like "/NetworkManager-ci" which symlinks links to the bind mount location.
This commit is contained in:
@@ -26,8 +26,13 @@ set -e
|
|||||||
# You can run `make install` and run tests.
|
# You can run `make install` and run tests.
|
||||||
# There is a script nm-env-prepare.sh to generate a net1 interface for testing.
|
# There is a script nm-env-prepare.sh to generate a net1 interface for testing.
|
||||||
#
|
#
|
||||||
# This will bind-mount the NetworkManager working tree inside the container.
|
# This will bind-mount the NetworkManager working tree inside the container (and symlink
|
||||||
|
# from /NetworkManager). Create a file ".git/nm-in-container-host" to bind mount the host's
|
||||||
|
# "/" to "/Host".
|
||||||
|
#
|
||||||
# Create a symlink ./.git/NetworkManager-ci, to also bind-mount the CI directory.
|
# Create a symlink ./.git/NetworkManager-ci, to also bind-mount the CI directory.
|
||||||
|
# Create additional symlinks ./.git/nm-guest-link-*, to bind mount additional
|
||||||
|
# directories.
|
||||||
#
|
#
|
||||||
# Currently NM-ci requires a working eth1.
|
# Currently NM-ci requires a working eth1.
|
||||||
# Hence call `nm-env-prepare.sh --prefix eth -i 1 && sleep 1 && nmcli device connect eth1` before
|
# Hence call `nm-env-prepare.sh --prefix eth -i 1 && sleep 1 && nmcli device connect eth1` before
|
||||||
@@ -46,10 +51,16 @@ fi
|
|||||||
BASEDIR_NM="$(readlink -f "$(dirname "$(readlink -f "$0")")/..")"
|
BASEDIR_NM="$(readlink -f "$(dirname "$(readlink -f "$0")")/..")"
|
||||||
BASEDIR_DATA="$BASEDIR_NM/tools/nm-guest-data"
|
BASEDIR_DATA="$BASEDIR_NM/tools/nm-guest-data"
|
||||||
|
|
||||||
BASEDIR_NM_CI=
|
SYMLINK_NAME=()
|
||||||
if [ -d "$BASEDIR_NM/.git/NetworkManager-ci" ] ; then
|
SYMLINK_TARGET=()
|
||||||
BASEDIR_NM_CI="$(readlink -f "$BASEDIR_NM/.git/NetworkManager-ci")"
|
for d in $(ls -1d "$BASEDIR_NM/.git/NetworkManager-ci" "$BASEDIR_NM/.git/nm-guest-link-"* 2>/dev/null) ; do
|
||||||
fi
|
NAME="${d##*/}"
|
||||||
|
NAME="${NAME##nm-guest-link-}"
|
||||||
|
TARGET="$(readlink -f "$d")"
|
||||||
|
test -e "$TARGET"
|
||||||
|
SYMLINK_NAME+=("$NAME")
|
||||||
|
SYMLINK_TARGET+=("$TARGET")
|
||||||
|
done
|
||||||
|
|
||||||
CONTAINER_NAME_REPOSITORY=${CONTAINER_NAME_REPOSITORY:-nm}
|
CONTAINER_NAME_REPOSITORY=${CONTAINER_NAME_REPOSITORY:-nm}
|
||||||
CONTAINER_NAME_TAG=${CONTAINER_NAME_TAG:-nm}
|
CONTAINER_NAME_TAG=${CONTAINER_NAME_TAG:-nm}
|
||||||
@@ -113,6 +124,17 @@ bind_files() {
|
|||||||
ARR=()
|
ARR=()
|
||||||
H=~
|
H=~
|
||||||
|
|
||||||
|
ARR+=( -v "$BASEDIR_NM:$BASEDIR_NM" )
|
||||||
|
|
||||||
|
if [ -e "$BASEDIR_NM/.git/nm-in-container-host" ] ; then
|
||||||
|
ARR+=( -v /:/Host )
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in $(seq 1 ${#SYMLINK_TARGET[@]}) ; do
|
||||||
|
j=$((i - 1))
|
||||||
|
ARR+=( -v "${SYMLINK_TARGET[$j]}:${SYMLINK_TARGET[$j]}" )
|
||||||
|
done
|
||||||
|
|
||||||
for f in ~/.gitconfig* ~/.vim* ; do
|
for f in ~/.gitconfig* ~/.vim* ; do
|
||||||
test -e "$f" || continue
|
test -e "$f" || continue
|
||||||
f2="${f#$H/}"
|
f2="${f#$H/}"
|
||||||
@@ -148,10 +170,13 @@ create_dockerfile() {
|
|||||||
RUN_LN_BASEDIR_NM="RUN ln -snf \"$BASEDIR_NM\" /NetworkManager"
|
RUN_LN_BASEDIR_NM="RUN ln -snf \"$BASEDIR_NM\" /NetworkManager"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUN_LN_BASEDIR_NM_CI=
|
RUN_LN_SYMLINK_CMDS=""
|
||||||
if [ -n "$BASEDIR_NM_CI" -a "$BASEDIR_NM_CI" != "/NetworkManager-ci" ] ; then
|
for i in $(seq 1 ${#SYMLINK_NAME[@]}) ; do
|
||||||
RUN_LN_BASEDIR_NM_CI="RUN ln -snf \"$BASEDIR_NM_CI\" /NetworkManager-ci"
|
j=$((i - 1))
|
||||||
fi
|
if [ -d "${SYMLINK_TARGET[$j]}" ] ; then
|
||||||
|
RUN_LN_SYMLINK_CMDS="$RUN_LN_SYMLINK_CMDS"$'\n'"RUN ln -snf \"${SYMLINK_TARGET[$j]}\" \"/${SYMLINK_NAME[$j]}\""
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
cat <<EOF | tmp_file "$CONTAINERFILE"
|
cat <<EOF | tmp_file "$CONTAINERFILE"
|
||||||
FROM $BASE_IMAGE
|
FROM $BASE_IMAGE
|
||||||
@@ -337,7 +362,7 @@ RUN chmod 600 /var/lib/NetworkManager/secret_key
|
|||||||
RUN sed 's/.*RateLimitBurst=.*/RateLimitBurst=0/' /etc/systemd/journald.conf -i
|
RUN sed 's/.*RateLimitBurst=.*/RateLimitBurst=0/' /etc/systemd/journald.conf -i
|
||||||
|
|
||||||
$RUN_LN_BASEDIR_NM
|
$RUN_LN_BASEDIR_NM
|
||||||
$RUN_LN_BASEDIR_NM_CI
|
$RUN_LN_SYMLINK_CMDS
|
||||||
|
|
||||||
RUN rm -rf /etc/NetworkManager/system-connections/*
|
RUN rm -rf /etc/NetworkManager/system-connections/*
|
||||||
|
|
||||||
@@ -391,24 +416,18 @@ do_run() {
|
|||||||
|
|
||||||
if container_exists "$CONTAINER_NAME_NAME" ; then
|
if container_exists "$CONTAINER_NAME_NAME" ; then
|
||||||
podman start "$CONTAINER_NAME_NAME"
|
podman start "$CONTAINER_NAME_NAME"
|
||||||
else
|
return 0
|
||||||
bind_files BIND_FILES
|
|
||||||
|
|
||||||
BIND_NM_CI=()
|
|
||||||
if [ -n "$BASEDIR_NM_CI" ] ; then
|
|
||||||
BIND_NM_CI=(-v "$BASEDIR_NM_CI:$BASEDIR_NM_CI")
|
|
||||||
fi
|
|
||||||
|
|
||||||
podman run --privileged \
|
|
||||||
--name "$CONTAINER_NAME_NAME" \
|
|
||||||
--dns=none \
|
|
||||||
--no-hosts \
|
|
||||||
-d \
|
|
||||||
-v "$BASEDIR_NM:$BASEDIR_NM" \
|
|
||||||
"${BIND_NM_CI[@]}" \
|
|
||||||
"${BIND_FILES[@]}" \
|
|
||||||
"$CONTAINER_NAME_REPOSITORY:$CONTAINER_NAME_TAG"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
bind_files BIND_FILES
|
||||||
|
|
||||||
|
podman run --privileged \
|
||||||
|
--name "$CONTAINER_NAME_NAME" \
|
||||||
|
--dns=none \
|
||||||
|
--no-hosts \
|
||||||
|
-d \
|
||||||
|
"${BIND_FILES[@]}" \
|
||||||
|
"$CONTAINER_NAME_REPOSITORY:$CONTAINER_NAME_TAG"
|
||||||
}
|
}
|
||||||
|
|
||||||
do_exec() {
|
do_exec() {
|
||||||
|
Reference in New Issue
Block a user