Skip to content

Commit e406b27

Browse files
hhromicPeterJohnson
authored andcommitted
Ensure that the configuration file is an absolute path in Docker build (RPi-Distro#306)
* Use `&&` instead of `;` in Docker pipeline * In case of error, `&&` does not continue execution * Silence shellcheck warning * SC2086: Double quote to prevent globbing and word splitting. * Ensure that the configuration file is an absolute path in Docker build The specific problem is in commit 2ddd7c1, where the passed config file (using the `-c` option) is now mounted inside the container using the `--volume src:dest:opt` Docker option. The problem is that Docker requires absolute paths for mounting single files inside the container, otherwise it silently tries to mount a volume name instead as an empty directory. Therefore the Docker build no longer works with the following invocation forms (relative config-paths): ./build-docker.sh -c myconfig /path/to/build-docker.sh -c myconfig # also doesn't work This commit uses `realpath` (included in coreutils) in the Docker build script to ensure that the passed configuration file is always an absolute path before passing it to Docker.
1 parent 74ab9c3 commit e406b27

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

build-docker.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ done
3232

3333
IMG_VERSION=${IMG_VERSION:-$(git describe)}
3434

35+
# Ensure that the configuration file is an absolute path
36+
CONFIG_FILE=$(realpath -s "$CONFIG_FILE")
37+
3538
# Ensure that the confguration file is present
3639
if test -z "${CONFIG_FILE}"; then
3740
echo "Configuration file need to be present in '${DIR}/config' or path passed as parameter"
@@ -76,7 +79,7 @@ if [ "${CONTAINER_EXISTS}" != "" ] && [ "${CONTINUE}" != "1" ]; then
7679
fi
7780

7881
# Modify original build-options to allow config file to be mounted in the docker container
79-
BUILD_OPTS="$(echo ${BUILD_OPTS:-} | sed -E 's@\-c\s?([^ ]+)@-c /config@')"
82+
BUILD_OPTS="$(echo "${BUILD_OPTS:-}" | sed -E 's@\-c\s?([^ ]+)@-c /config@')"
8083

8184
${DOCKER} build -t pi-gen "${DIR}"
8285
if [ "${CONTAINER_EXISTS}" != "" ]; then
@@ -88,7 +91,7 @@ if [ "${CONTAINER_EXISTS}" != "" ]; then
8891
-e IMG_VERSION="${IMG_VERSION}"\
8992
pi-gen \
9093
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
91-
cd /pi-gen; ./build.sh ${BUILD_OPTS} ;
94+
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
9295
rsync -av work/*/build.log deploy/" &
9396
wait "$!"
9497
else

0 commit comments

Comments
 (0)