Support stages outside of pi-gen dir in docker build

For each stage check if the path is absolute or starts with a `..`
If so add a it to the docker instance as a volume. Also modify the
STAGE_LIST variable with the paths that will be seen from within
the docker container.
pull/365/head
Sam Tygier 2019-12-20 23:20:28 +00:00
parent f8f3d6fe93
commit d1e067007a
2 changed files with 21 additions and 0 deletions

View File

@ -73,11 +73,26 @@ fi
# Modify original build-options to allow config file to be mounted in the docker container
BUILD_OPTS="$(echo "${BUILD_OPTS:-}" | sed -E 's@\-c\s?([^ ]+)@-c /config@')"
STAGE_LIST_VOLUMES=""
STAGE_LIST_DOCKER=""
for STAGE in $STAGE_LIST
do
echo stage: $STAGE
if [[ $STAGE = /* || $STAGE = ../* ]] ; then
STAGE_LIST_VOLUMES="${STAGE_LIST_VOLUMES} --volume `realpath $STAGE`:/ext-stages/`basename $STAGE`:ro"
STAGE_LIST_DOCKER="${STAGE_LIST_DOCKER} /ext-stages/`basename $STAGE`"
else
STAGE_LIST_DOCKER="${STAGE_LIST_DOCKER} $STAGE"
fi
done
${DOCKER} build -t pi-gen "${DIR}"
if [ "${CONTAINER_EXISTS}" != "" ]; then
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
time ${DOCKER} run --rm --privileged \
--volume "${CONFIG_FILE}":/config:ro \
${STAGE_LIST_VOLUMES} \
-e "STAGE_LIST_DOCKER=${STAGE_LIST_DOCKER}" \
-e "GIT_HASH=${GIT_HASH}" \
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
pi-gen \
@ -89,6 +104,8 @@ else
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \
--volume "${CONFIG_FILE}":/config:ro \
${STAGE_LIST_VOLUMES} \
-e "STAGE_LIST_DOCKER=${STAGE_LIST_DOCKER}" \
-e "GIT_HASH=${GIT_HASH}" \
pi-gen \
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&

View File

@ -228,6 +228,10 @@ fi
mkdir -p "${WORK_DIR}"
log "Begin ${BASE_DIR}"
if [ -v STAGE_LIST_DOCKER ]; then
STAGE_LIST=${STAGE_LIST_DOCKER}
fi
STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*}
for STAGE_DIR in $STAGE_LIST; do