Files
tools/tb.sh
Scott Little f6755e179a Enable build of docker images, charts and wheels from a layered build
1) Add config for the container layer.

2) Add support for the new config file 'required_layer_wheel_inc.cfg',
Which will specify the default urls for lower layer wheels.inc files.
These files must be downloaded by download_mirror.sh, and linked by
generate-cgcs-centos-repo.sh.

3) Add options to download_mirror.sh and generate-cgcs-centos-repo.sh
allowing overrides or additions to the set of url's for lower layer
wheels.inc

4) Changes to allow build scripts running within a docker container
to launch a sister (not daughter) container.  This will allow
build-wheels to run within a container.

Story: 2006166
Task: 38980
Depends-On: https://review.opendev.org/711773
Depends-On: https://review.opendev.org/717755
Change-Id: I95c71a0327dc9d919ed835d3661a6f1ec7ce30c7
Signed-off-by: Scott Little <scott.little@windriver.com>
2020-04-14 22:00:52 -04:00

119 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# tb.sh - tbuilder commands
#
# Subcommands:
# env - Display a selection of configuration values
# exec - Starts a shell inside a running container
# run - Starts a container
# stop - Stops a running container
#
# Configuration
# tb.sh expects to find its configuration file buildrc in the current
# directory, like Vagrant looks for Vagrantfile.
SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
WORK_DIR=$(pwd)
# Load tbuilder configuration
if [[ -r ${WORK_DIR}/buildrc ]]; then
source ${WORK_DIR}/buildrc
fi
CMD=$1
TC_CONTAINER_NAME=${MYUNAME}-centos-builder
TC_CONTAINER_TAG=local/${MYUNAME}-stx-builder:7.4
TC_DOCKERFILE=Dockerfile
function create_container {
docker build \
--build-arg MYUID=$(id -u) \
--build-arg MYUNAME=${USER} \
--ulimit core=0 \
--network host \
-t ${TC_CONTAINER_TAG} \
-f ${TC_DOCKERFILE} \
.
}
function exec_container {
docker cp ${WORK_DIR}/buildrc ${TC_CONTAINER_NAME}:/home/${MYUNAME}
docker cp ${WORK_DIR}/localrc ${TC_CONTAINER_NAME}:/home/${MYUNAME}
docker exec -it --user=${MYUNAME} -e MYUNAME=${MYUNAME} ${TC_CONTAINER_NAME} script -q -c "/bin/bash" /dev/null
}
function run_container {
# create localdisk
mkdir -p ${LOCALDISK}/designer/${MYUNAME}/${PROJECT}
docker run -it --rm \
--name ${TC_CONTAINER_NAME} \
--detach \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ${LOCALDISK}:/${GUEST_LOCALDISK} \
-v ${HOST_MIRROR_DIR}:/import/mirrors:ro \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
-v ~/.ssh:/mySSH:ro \
-e "container=docker" \
-e MYUNAME=${MYUNAME} \
--privileged=true \
--security-opt seccomp=unconfined \
${TC_CONTAINER_TAG}
}
function stop_container {
docker stop ${TC_CONTAINER_NAME}
}
function kill_container {
docker kill ${TC_CONTAINER_NAME}
}
function clean_container {
docker rm ${TC_CONTAINER_NAME} || true
docker image rm ${TC_CONTAINER_TAG}
}
function usage {
echo "$0 [create|run|exec|env|stop|kill|clean]"
}
case $CMD in
env)
echo "LOCALDISK=${LOCALDISK}"
echo "GUEST_LOCALDISK=${GUEST_LOCALDISK}"
echo "TC_DOCKERFILE=${TC_DOCKERFILE}"
echo "TC_CONTAINER_NAME=${TC_CONTAINER_NAME}"
echo "TC_CONTAINER_TAG=${TC_CONTAINER_TAG}"
echo "SOURCE_REMOTE_NAME=${SOURCE_REMOTE_NAME}"
echo "SOURCE_REMOTE_URI=${SOURCE_REMOTE_URI}"
echo "HOST_MIRROR_DIR=${HOST_MIRROR_DIR}"
echo "MY_RELEASE=${MY_RELEASE}"
echo "MY_REPO_ROOT_DIR=${MY_REPO_ROOT_DIR}"
echo "LAYER=${LAYER}"
;;
create)
create_container
;;
exec)
exec_container
;;
run)
run_container
;;
stop)
stop_container
;;
kill)
kill_container
;;
clean)
clean_container
;;
*)
echo "Unknown command: $CMD"
usage
exit 1
;;
esac