test/docker: Support installing multiple plugins
Replace the non-generic '--depends-on-plugin-jar' option with a generic
'--plugin' option that can be specified multiple times to install
additional plugins for testing.
This also makes it easier to build CI systems that can use a common
testing interface.
Change-Id: I2bb2685491196360bd1f7ef5ed55244667167bf0
diff --git a/BUILD b/BUILD
index f02cbee..5cca9bf 100644
--- a/BUILD
+++ b/BUILD
@@ -86,7 +86,7 @@
size = "medium",
srcs = ["test/docker/run.sh"],
args = [
- "--depends-on-plugin-jar",
+ "--plugin", plugin_name,
"$(location :depends-on)",
],
data = [plugin_name] + glob(["test/**"]),
diff --git a/test/docker/gerrit/Dockerfile b/test/docker/gerrit/Dockerfile
index 67ddfa4..179348f 100755
--- a/test/docker/gerrit/Dockerfile
+++ b/test/docker/gerrit/Dockerfile
@@ -1,13 +1,14 @@
FROM gerritcodereview/gerrit:3.5.0.1-ubuntu20
+ENV GERRIT_SITE /var/gerrit
+COPY artifacts/plugins/ $GERRIT_SITE/plugins/
+
USER root
-ENV GERRIT_SITE /var/gerrit
RUN git config -f "$GERRIT_SITE/etc/gerrit.config" auth.type \
DEVELOPMENT_BECOME_ANY_ACCOUNT
-COPY artifacts /tmp/
-RUN cp /tmp/depends-on.jar "$GERRIT_SITE/plugins/depends-on.jar"
+COPY artifacts/bin/ /tmp/
RUN { [ -e /tmp/gerrit.war ] && cp /tmp/gerrit.war "$GERRIT_SITE/bin/gerrit.war" ; } || true
USER gerrit
diff --git a/test/docker/run.sh b/test/docker/run.sh
index 117f9e9..517baf3 100755
--- a/test/docker/run.sh
+++ b/test/docker/run.sh
@@ -3,7 +3,8 @@
readlink --canonicalize / &> /dev/null || readlink() { greadlink "$@" ; } # for MacOS
MYDIR=$(dirname -- "$(readlink -f -- "$0")")
ARTIFACTS=$MYDIR/gerrit/artifacts
-BAZEL_BUILT_JAR=$MYDIR/../../bazel-bin/depends-on.jar
+PLUGIN=depends-on
+BAZEL_BUILT_JAR=$MYDIR/../../bazel-bin/$PLUGIN.jar
die() { echo -e "\nERROR: $@" ; kill $$ ; exit 1 ; } # error_message
@@ -24,7 +25,7 @@
local prog=$(basename "$0")
cat <<EOF
Usage:
- $prog [--depends-on-plugin-jar|-t <FILE_PATH>] [--gerrit-war|-g <FILE_PATH>]
+ $prog [--plugin <plugin name> <JAR path>] [--gerrit-war|-g <FILE_PATH>]
This tool runs the plugin functional tests in a Docker environment built
from the gerritcodereview/gerrit base Docker image.
@@ -36,8 +37,10 @@
different MAJOR.MINOR version than the
default version in
test/docker/gerrit/Dockerfile.
- --depends-on-plugin-jar|-e optional path to depends-on plugin JAR file.
- Defaults to $BAZEL_BUILT_JAR
+ --plugin optional plugin name and path to JAR file
+ Defaults to 'depends-on' '$BAZEL_BUILT_JAR'
+ Can be repeated to install additional
+ plugins.
EOF
@@ -60,16 +63,36 @@
'/depends_on/test/docker/run_tests/start.sh'
}
+fetch_artifact() { # source_location output_path
+ if [[ "$1" =~ ^file://|^http://|^https:// ]] ; then
+ curl --silent --fail --netrc "$1" --output "$2" --create-dirs || die "unable to fetch $1"
+ else
+ cp -f "$1" "$2" || die "unable to copy $1"
+ fi
+}
+
+fetch_artifacts() {
+ local plugin_name
+ [ -n "$GERRIT_WAR" ] && fetch_artifact "$GERRIT_WAR" "$ARTIFACTS/bin/gerrit.war"
+ for plugin_name in "${!PLUGIN_JAR_BY_NAME[@]}" ; do
+ if [ -n "${PLUGIN_JAR_BY_NAME["$plugin_name"]}" ] ; then
+ fetch_artifact "${PLUGIN_JAR_BY_NAME[$plugin_name]}" \
+ "$ARTIFACTS/plugins/$plugin_name.jar"
+ fi
+ done
+}
+
cleanup() {
docker-compose "${COMPOSE_ARGS[@]}" down -v --rmi local 2>/dev/null
rm -rf "$ARTIFACTS"
}
+declare -A PLUGIN_JAR_BY_NAME
while (( "$#" )); do
case "$1" in
--help|-h) usage ;;
--gerrit-war|-g) shift ; GERRIT_WAR=$1 ;;
- --depends-on-plugin-jar|-e) shift ; DEPENDS_ON_PLUGIN_JAR=$1 ;;
+ --plugin) shift ; PLUGIN_JAR_BY_NAME["$1"]=$2 ; shift ;;
*) usage "invalid argument $1" ;;
esac
shift
@@ -79,15 +102,14 @@
COMPOSE_YAML="$MYDIR/docker-compose.yaml"
COMPOSE_ARGS=(--project-name "$PROJECT_NAME" -f "$COMPOSE_YAML")
check_prerequisite
-mkdir -p -- "$ARTIFACTS"
-if [ -n "$DEPENDS_ON_PLUGIN_JAR" ] ; then
- cp -f "$DEPENDS_ON_PLUGIN_JAR" "$ARTIFACTS/depends-on.jar"
-elif [ -e "$BAZEL_BUILT_JAR" ] ; then
- cp -f "$BAZEL_BUILT_JAR" "$ARTIFACTS/depends-on.jar"
-else
- usage "Cannot find plugin jar, did you forget --depends-on-plugin-jar?"
+mkdir -p -- "$ARTIFACTS/bin" "$ARTIFACTS/plugins"
+if [ -z "${PLUGIN_JAR_BY_NAME["$PLUGIN"]}" ] ; then
+ PLUGIN_JAR_BY_NAME["$PLUGIN"]=$BAZEL_BUILT_JAR
fi
-[ -n "$GERRIT_WAR" ] && cp -f "$GERRIT_WAR" "$ARTIFACTS/gerrit.war"
+if [ ! -e "${PLUGIN_JAR_BY_NAME["$PLUGIN"]}" ] ; then
+ usage "Cannot find plugin jar, did you forget --plugin?"
+fi
+progress "Fetching artifacts" fetch_artifacts
( trap cleanup EXIT SIGTERM
progress "Building docker images" build_images
run_depends_on_plugin_tests