bash variables in build-docker.sh are wrapped by curly brackets
This commit is contained in:
parent
3db1168fbd
commit
9e48fb6763
|
@ -3,28 +3,29 @@
|
||||||
BUILD_OPTS="$*"
|
BUILD_OPTS="$*"
|
||||||
|
|
||||||
DOCKER="docker"
|
DOCKER="docker"
|
||||||
set +e
|
|
||||||
if ! $DOCKER ps >/dev/null 2>&1; then
|
if ! ${DOCKER} ps >/dev/null 2>&1; then
|
||||||
DOCKER="sudo docker"
|
DOCKER="sudo docker"
|
||||||
fi
|
fi
|
||||||
if ! $DOCKER ps >/dev/null; then
|
if ! ${DOCKER} ps >/dev/null; then
|
||||||
echo "error connecting to docker:"
|
echo "error connecting to docker:"
|
||||||
$DOCKER ps
|
${DOCKER} ps
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ -f config ]; then
|
CONFIG_FILE="${DIR}/config"
|
||||||
|
if [ -f "${CONFIG_FILE}" ]; then
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
source config
|
source "${CONFIG_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while getopts "c:" flag
|
while getopts "c:" flag
|
||||||
do
|
do
|
||||||
case "$flag" in
|
case "${flag}" in
|
||||||
c)
|
c)
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$OPTARG"
|
source "${OPTARG}"
|
||||||
|
CONFIG_FILE="${OPTARG}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
|
@ -41,23 +42,23 @@ if [ -z "${IMG_NAME}" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CONTAINER_EXISTS=$($DOCKER ps -a --filter name="$CONTAINER_NAME" -q)
|
CONTAINER_EXISTS=$(${DOCKER} ps -a --filter name="${CONTAINER_NAME}" -q)
|
||||||
CONTAINER_RUNNING=$($DOCKER ps --filter name="$CONTAINER_NAME" -q)
|
CONTAINER_RUNNING=$(${DOCKER} ps --filter name="${CONTAINER_NAME}" -q)
|
||||||
if [ "$CONTAINER_RUNNING" != "" ]; then
|
if [ "${CONTAINER_RUNNING}" != "" ]; then
|
||||||
echo "The build is already running in container $CONTAINER_NAME. Aborting."
|
echo "The build is already running in container ${CONTAINER_NAME}. Aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ "$CONTAINER_EXISTS" != "" ] && [ "$CONTINUE" != "1" ]; then
|
if [ "${CONTAINER_EXISTS}" != "" ] && [ "${CONTINUE}" != "1" ]; then
|
||||||
echo "Container $CONTAINER_NAME already exists and you did not specify CONTINUE=1. Aborting."
|
echo "Container ${CONTAINER_NAME} already exists and you did not specify CONTINUE=1. Aborting."
|
||||||
echo "You can delete the existing container like this:"
|
echo "You can delete the existing container like this:"
|
||||||
echo " $DOCKER rm -v $CONTAINER_NAME"
|
echo " ${DOCKER} rm -v ${CONTAINER_NAME}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$DOCKER build -t pi-gen .
|
${DOCKER} build -t pi-gen .
|
||||||
if [ "$CONTAINER_EXISTS" != "" ]; then
|
if [ "${CONTAINER_EXISTS}" != "" ]; then
|
||||||
trap 'echo "got CTRL+C... please wait 5s"; $DOCKER stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
|
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
|
||||||
time $DOCKER run --rm --privileged \
|
time ${DOCKER} run --rm --privileged \
|
||||||
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
|
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
|
||||||
pi-gen \
|
pi-gen \
|
||||||
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
|
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
|
||||||
|
@ -65,8 +66,8 @@ if [ "$CONTAINER_EXISTS" != "" ]; then
|
||||||
rsync -av work/*/build.log deploy/" &
|
rsync -av work/*/build.log deploy/" &
|
||||||
wait "$!"
|
wait "$!"
|
||||||
else
|
else
|
||||||
trap 'echo "got CTRL+C... please wait 5s"; $DOCKER stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
|
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
|
||||||
time $DOCKER run --name "${CONTAINER_NAME}" --privileged \
|
time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \
|
||||||
pi-gen \
|
pi-gen \
|
||||||
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
|
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static &&
|
||||||
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
|
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
|
||||||
|
@ -74,12 +75,12 @@ else
|
||||||
wait "$!"
|
wait "$!"
|
||||||
fi
|
fi
|
||||||
echo "copying results from deploy/"
|
echo "copying results from deploy/"
|
||||||
$DOCKER cp "${CONTAINER_NAME}":/pi-gen/deploy .
|
${DOCKER} cp "${CONTAINER_NAME}":/pi-gen/deploy .
|
||||||
ls -lah deploy
|
ls -lah deploy
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
if [ "$PRESERVE_CONTAINER" != "1" ]; then
|
if [ "${PRESERVE_CONTAINER}" != "1" ]; then
|
||||||
$DOCKER rm -v "$CONTAINER_NAME"
|
${DOCKER} rm -v "${CONTAINER_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Done! Your image(s) should be in deploy/"
|
echo "Done! Your image(s) should be in deploy/"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user