Skip to content
Snippets Groups Projects
Commit 9ab61d63 authored by Daniel Playle's avatar Daniel Playle
Browse files

fixup! Support dynamic client certificates for CAS cache

parent 170ad40c
No related branches found
No related tags found
Loading
Pipeline #27036833 passed
#!/usr/bin/env bash
#
# Copyright (C) 2018 Codethink Limited
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Tristan Maat <tristan.maat@codethink.co.uk>
set -eu
usage () {
cat <<EOF
Usage:
test-bst [options] [<bst-version>]
Run a test buildstream container with your cwd as /src. Also allows
using an editable local copy of the buildstream repository, or a
different branch from the current repository.
The bst-version argument is presumed to be a branch of the main repo
by default, and will default to "master" if not specified.
Options:
-b|--branch Treat bst-version as a branch name
-c|--commit Treat bst-version as a commit sha
-d|--directory Treat bst-version as a local directory
containing buildstream's repository
-i|--image Use the given image as base
-v|--volume Specify additional volumes to mount; should be in format
'host-src:container-dest' same as 'docker run -v'
-e|--env Specify additional environment variables; same as
'docker run --env'
--keep-artifacts Enable local artifact cache
--no-source-cache Disable local source cache
--help Display this help message and exit
EOF
}
RED='\033[0;31m'
RESET='\033[0m'
main () {
local env
local image
local branch
local commit
local volumes
local buildstream_dir
local keep_sources=true
local keep_artifacts=false
while : ; do
case "${1:-}" in
"")
break ;;
-v|--volume)
volumes="$volumes $2"
shift 2 ;;
-e|--env)
env="$env $2"
shift 2 ;;
-d|--directory)
if [ ! -z "$branch" ] || [ ! -z "$commit" ]; then
echo -e "${RED}Error: Cannot specify '$1' and '-c' or '-b'"
usage
exit 1
fi
buildstream_dir=$(abspath "$2")
shift 2 ;;
-b|--branch)
if [ ! -z "$buildstream_dir" ] || [ ! -z "$commit" ]; then
echo -e "${RED}Error: Cannot specify '$1' and '-d' or '-c'"
usage
exit 1
fi
branch="$2"
shift 2 ;;
-c|--commit)
if [ ! -z "$buildstream_dir" ] || [ ! -z "$branch" ]; then
echo -e "${RED}Error: Cannot specify '$1' and '-d' or '-b'"
usage
exit 1
fi
commit="$2"
shift 2 ;;
-i|--image)
image="$2"
shift 2 ;;
--no-source-cache)
keep_sources=false
shift ;;
--keep-artifacts)
keep_artifacts=true
shift ;;
*)
echo -e "${RED}Error: Unrecognized argument '${1:-}'${RESET}" 1>&2
usage
exit 1 ;;
esac
done
run_bst "$branch" "$keep_sources" "$keep_artifacts" "$buildstream_dir" "$commit" "$image"
}
abspath() {
local path="$1"
cd "$(dirname "$path")"
path="$(basename "$path")"
while [ -L "$path" ]; do
path="$(readlink "$path")"
cd "$(dirname "$path")"
path="$(basename "$path")"
done
echo "$(pwd -P)/$path"
}
run_bst() {
local branch="$1"
local keep_sources="$2"
local keep_artifacts="$3"
local buildstream_dir="$4"
local commit="$5"
local opt_args=""
local install_bst
if [ -z "$branch" ]; then
branch="master"
fi
if [ -z "$image" ]; then
image="${BUILDSTREAM_DOCKER_IMAGE:-buildstream/buildstream-fedora:latest}"
fi
# Install the version of buildstream that the user specified
if [ ! -z "$commit" ]; then
install_bst="(set -e;
git clone https://gitlab.com/BuildStream/buildstream.git /buildstream;
git -C /buildstream checkout $commit;
pip3 install --no-index /buildstream)"
elif [ ! -z "$buildstream_dir" ]; then
install_bst="(set -e; pip3 install --no-index -e /buildstream)"
opt_args="$opt_args --volume $buildstream_dir:/buildstream"
else
install_bst="(set -e;
git clone -b $branch https://gitlab.com/BuildStream/buildstream.git /buildstream;
pip3 install --no-index /buildstream)"
fi
# Create a volume to cache sources
if [ "$keep_sources" == true ]; then
opt_args="$opt_args --env BST_SOURCE_CACHE=/temp/bst_cache/buildstream/sources"
opt_args="$opt_args --env XDG_CACHE_HOME=/temp/bst_cache/"
opt_args="$opt_args --volume bst-test-sources:/temp/bst_cache/buildstream/sources"
docker volume create "bst-test-sources"
fi
# Create a volume to cache artifacts
if [ "$keep_artifacts" == true ]; then
opt_args="$opt_args --env XDG_CACHE_HOME=/temp/bst_cache"
opt_args="$opt_args --volume bst-test-artifacts:/temp/bst_cache/buildstream/artifacts"
docker volume create "bst-test-artifacts"
fi
# Run a container with a buildstream setup as specified.
#
# --privileged is required to run bst in docker
# --net="host" is used for local artifact cache server testing
# --device /dev/fuse is required to run bst in docker
# --security-opt seccomp=unconfined is required to run bst in docker
# --env PS1 is set to distinguish the shell from a normal shell
#
# Any un-escaped variables are argument lists - unfortunately we
# can't disable shellcheck warnings for these here.
#
exec docker run --rm -it \
--privileged \
--net="host" \
--device /dev/fuse \
--security-opt seccomp=unconfined \
--env PS1="${PS1:-bst-test:\u@\h \$ }" \
--volume "$PWD":/src \
${volumes// / --volume } \
${env// / --env } \
--workdir /src \
$opt_args \
"$image" \
/bin/bash -c "$install_bst; bash -i"
}
main "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment