git-lfs/docker/run_dockers.bsh
Chris Darroch f9e22f18b3 docker/run_dockers.bsh: update available options
The --prune command-line option was added to the docker/run_dockers.bsh
script in commit 4a2e96b74337b91012b95314633db1d5f4181a52 of PR #4104,
and the --arch command-line options was added in commit
569b5ce4e56dcfda2fb26d6277047182d8ec4d11 of PR #4728.  Earlier, the
REPO_HOSTNAME environment variable was removed from all the corresponding
Dockerfiles in the git-lfs/build-dockers repository in commit
git-lfs/build-dockers@d4c2fe6f79.

We therefore update the docker/run_dockers.bsh script now to remove
the unused REPO_HOSTNAME environment variable and document the new
--prune and --arch command-line options.
2023-09-12 11:17:02 -07:00

109 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Usage:
# ./run_dockers.bsh # Run all the Docker images
# ./run_dockers.bsh centos_6 centos_7 # Run only the CentOS 6 & 7 Docker images
# ./run_dockers.bsh centos_6 -- bash # Run Bash in the CentOS 6 Docker image
# ./run_dockers.bsh --prune # Remove each Docker image after running
# ./run_dockers.bsh --arch=<arch> # Build for a specific architecture,
# # e.g., arm64
# Special Environment Variables
# AUTO_REMOVE - Default 1. If set to 0, the Docker container will not be
# automatically deleted when done. This can be useful for a
# post-mortem analysis. Just make sure you clean up the Docker
# containers manually.
set -eu
#Mingw32 auto converts /drive/dir/blah to drive:\dir\blah ... Can't have that.
if [[ `uname` == MINGW* ]]; then
MINGW_PATCH='/'
else
MINGW_PATCH=''
fi
CUR_DIR=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
REPO_DIR=$(cd ${CUR_DIR}/..; pwd)
PACKAGE_DIR=${REPO_DIR}/repos
mkdir -p ${PACKAGE_DIR}/centos || :
mkdir -p ${PACKAGE_DIR}/debian || :
#If you are not in docker group and you have sudo, default value is sudo
: ${SUDO=`if ( [ ! -w /var/run/docker.sock ] && id -nG | grep -qwv docker && [ "${DOCKER_HOST:+dh}" != "dh" ] ) && command -v sudo > /dev/null 2>&1; then echo sudo; fi`}
function split_image_name()
{ #$1 - image dockerfile
#sets IMAGE_NAME to the basename of the dir containing the docker file
#sets IMAGE_INFO to be the array name following my pattern
local IFS=_
IMAGE_INFO=($1)
}
# Parse Arguments
IMAGES=
PRUNE=
ARCH=amd64
while [[ $# -gt 0 ]]; do
if [ "$1" = "--prune" ]; then
PRUNE=t
elif [[ "$1" == --arch=* ]]; then
ARCH="${1#--arch=}"
elif [ "$1" == "--" ]; then
shift
DOCKER_CMD="${@}"
break
else
IMAGES="$IMAGES $1"
fi
shift
done
if [[ -z "$IMAGES" ]]; then
IMAGES="$(script/distro-tool --image-names)"
fi
mkdir -p "${PACKAGE_DIR}"
#Run docker to build packages
for IMAGE_NAME in $IMAGES; do
split_image_name "${IMAGE_NAME}" #set IMAGE_NAME and IMAGE_INFO
#It CAN'T be empty () with set -u... So I put some defaults in here
OTHER_OPTIONS=("-t")
if tty >/dev/null; then
OTHER_OPTIONS+=("-i")
fi
if [ "${AUTO_REMOVE-1}" == "1" ]; then
OTHER_OPTIONS+=("--rm")
fi
FINAL_UID=$(id -u)
FINAL_GID=$(id -g)
if [[ $FINAL_UID == 0 ]]; then
FINAL_UID=${SUDO_UID-}
fi
if [[ $FINAL_GID == 0 ]]; then
FINAL_GID=${SUDO_GID-}
fi
echo Compiling LFS in docker image ${IMAGE_NAME}
IMAGE_REPO_DIR="${PACKAGE_DIR}"/"${IMAGE_INFO[0]}"/"${IMAGE_INFO[1]}"
$SUDO docker run "${OTHER_OPTIONS[@]}" ${DOCKER_OTHER_OPTIONS-} \
-e USER=root \
-e FINAL_UID=${FINAL_UID} \
-e FINAL_GID=${FINAL_GID} \
-v "${MINGW_PATCH}${REPO_DIR}:/src" \
-v "${MINGW_PATCH}${IMAGE_REPO_DIR}:/repo" \
--platform "$ARCH" \
gitlfs/build-dockers:${IMAGE_NAME} ${DOCKER_CMD-}
if [ -n "$PRUNE" ]
then
$SUDO docker rmi -f "gitlfs/build-dockers:${IMAGE_NAME}"
fi
done
echo "Docker run completed successfully!"