Skip to contentSkip to conversation

scripts: add container.sh as simple podman wrapper

PATCH Applied Ahmad Fatoum 2 participants 3 messages Jun 12, 2023 – Jun 13, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: add container.sh as simple podman wrapper

We have a Containerfile in tree now that is used for CI, but it's not completely self evident, how to use it locally. Add a simple script that mounts the current working directory into the container and calls its arguments inside.

Example building MAKEALL (Some configs will expectedly fail due to size or firmware constraints):

./scripts/container.sh ./MAKEALL

Example starting a shell:

./scripts/container.sh /bin/bash

---
 scripts/container.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 scripts/container.sh
scripts/container.sh new file +39 -0
new file mode 100755
index 000000000000..4ddee7d0a90c
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+CONTAINER=${CONTAINER:-ghcr.io/barebox/barebox/barebox-ci:latest}
+KCONFIG_ADD="$test/kconfig/disable_target_tools.kconf KCONFIG_ADD"
+
+while getopts "c:uh" opt; do
+	case "$opt" in
+	h)
+		echo "usage: $0 [-c CONTAINER] [command...]"
+		echo "This script mounts the working directory into a container"
+		echo "and runs the specified command inside or /bin/bash if no"
+		echo "command was specified."
+		echo "OPTIONS:"
+		echo "  -c <container>    container image to use (default: $CONTAINER)"
+		echo "  -u                pull container image updates"
+		echo "  -h                This help text"
+
+		exit 0
+		;;
+	u)
+		update=1
+		;;
+	c)
+		CONTAINER="$OPTARG"
+		;;
+	esac
+done
+
+shift $((OPTIND-1))
+
+[ -n "$update" ] && podman pull "$CONTAINER"
+
+pwd_real=$(realpath $PWD)
+
+exec podman run -it -v "$PWD:$PWD:z" -v "$pwd_real:$pwd_real:z" --rm \
+	-e TERM -e ARCH -e CONFIG -e JOBS -e LOGDIR -e REGEX \
+	-e KCONFIG_ADD -w "$PWD" --userns=keep-id \
+	-- "$CONTAINER" "${@:-/bin/bash}"
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/1 fixup! scripts: add container.sh as simple podman wrapper

fix typos. The toolchains in the container have no libc, so it's probably easiest to just set test/kconfig/disable_target_tools.kconf globally, so ./MAKEALL mostly works.

---
 scripts/container.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/container.sh +1 -1
index 4ddee7d0a90c..eb1e87b59baa 100755
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 CONTAINER=${CONTAINER:-ghcr.io/barebox/barebox/barebox-ci:latest}
-KCONFIG_ADD="$test/kconfig/disable_target_tools.kconf KCONFIG_ADD"
+export KCONFIG_ADD="test/kconfig/disable_target_tools.kconf $KCONFIG_ADD"
 
 while getopts "c:uh" opt; do
 	case "$opt" in
Signature · 1 line
2.40.1
Applied
#2 lore raw
In reply to Ahmad Fatoum
Quoted 12 lines · Ahmad Fatoum

We have a Containerfile in tree now that is used for CI, but it's not completely self evident, how to use it locally. Add a simple script that mounts the current working directory into the container and calls its arguments inside.

Example building MAKEALL (Some configs will expectedly fail due to size or firmware constraints):

./scripts/container.sh ./MAKEALL

Example starting a shell:

Quoted 7 lines

./scripts/container.sh /bin/bash

---
 scripts/container.sh | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 scripts/container.sh

Applied, thanks

Sascha

Quoted 51 lines
scripts/container.sh new file +39 -0
new file mode 100755
index 000000000000..4ddee7d0a90c
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
+
+CONTAINER=${CONTAINER:-ghcr.io/barebox/barebox/barebox-ci:latest}
+KCONFIG_ADD="$test/kconfig/disable_target_tools.kconf KCONFIG_ADD"
+
+while getopts "c:uh" opt; do
+	case "$opt" in
+	h)
+		echo "usage: $0 [-c CONTAINER] [command...]"
+		echo "This script mounts the working directory into a container"
+		echo "and runs the specified command inside or /bin/bash if no"
+		echo "command was specified."
+		echo "OPTIONS:"
+		echo "  -c <container>    container image to use (default: $CONTAINER)"
+		echo "  -u                pull container image updates"
+		echo "  -h                This help text"
+
+		exit 0
+		;;
+	u)
+		update=1
+		;;
+	c)
+		CONTAINER="$OPTARG"
+		;;
+	esac
+done
+
+shift $((OPTIND-1))
+
+[ -n "$update" ] && podman pull "$CONTAINER"
+
+pwd_real=$(realpath $PWD)
+
+exec podman run -it -v "$PWD:$PWD:z" -v "$pwd_real:$pwd_real:z" --rm \
+	-e TERM -e ARCH -e CONFIG -e JOBS -e LOGDIR -e REGEX \
+	-e KCONFIG_ADD -w "$PWD" --userns=keep-id \
+	-- "$CONTAINER" "${@:-/bin/bash}"
Signature · 1 line
2.40.1
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |