gerrit: get files from bazel build dir

bazel likes to build everything in ~/.cache and then symlink bazel-*
"convience symlinks" in the workspace/build directory.  This causes a
problem for building docker images where we run in the context of the
build directory; docker will not follow the symlinks out of build
directory.

Currently the bazelisk-build copies parts of the build to the
top-level; this means the bazelisk-build role is gerrit specific,
rather than generic as the name implies.

We modify the gerrit build step to break build output symlink and move
it into the top level of the build tree, which is the context the
docker build runs in later.  Since this is now just a normal
directory, we can copy from it at will there.

This is useful in follow-on builds where we want to start copying more
than just the release.war file from the build tree, e.g. polygerrit
plugin output.

While we're here, remove the javamelody things that were only for 2.X
series gerrit, which we don't build any more.

[1] https://docs.bazel.build/versions/master/output_directories.html

Change-Id: I00abe437925d805bd88824d653eec38fa95e4fcd
This commit is contained in:
Ian Wienand 2020-12-17 10:05:10 +11:00 committed by Clark Boylan
parent e80893eb3d
commit 951c2f4cde
3 changed files with 28 additions and 13 deletions

View File

@ -17,15 +17,10 @@
FROM docker.io/opendevorg/gerrit-base as gerrit
COPY release.war /var/gerrit/bin/gerrit.war
COPY bazel-bin/release.war /var/gerrit/bin/gerrit.war
# Install plugins
RUN mkdir /var/gerrit/plugins && \
unzip -jo /var/gerrit/bin/gerrit.war WEB-INF/plugins/* -d /var/gerrit/plugins
COPY opendevtheme.html /var/gerrit/plugins/opendevtheme.html
FROM gerrit as gerrit-2
# Only Gerrit 2.14, 2.15, and 2.16 need this COPY
COPY javamelody-deps_deploy.jar /var/gerrit/lib/javamelody-deps_deploy.jar

View File

@ -12,6 +12,28 @@
vars:
zuul_work_dir: /home/zuul/src/gerrit.googlesource.com/gerrit
# Bazel makes "convenience symlinks" [1] starting with bazel-* to
# the actual build output. The problem is that we want to use the
# source tree as the context/build dir for our Docker container,
# and Docker refuses to follow symlinks for COPY commands; i.e. we
# can't copy stuff from the build output into the container.
# Therefore break the bazel-bin link and move to the top level so
# we can copy the built bits (jars, plugins, etc) into the
# container easily.
#
# [1] https://docs.bazel.build/versions/master/user-manual.html
- name: Make bazel-bin docker friendly
shell:
cmd: |
if [ ! -L bazel-bin ]; then
echo "bazel-bin not a symlink?"
exit 1
fi
target=$(readlink bazel-bin)
rm bazel-bin
mv $target bazel-bin
chdir: /home/zuul/src/gerrit.googlesource.com/gerrit
- name: Install OpenDev theme plugin
copy:
src: opendevtheme.html

View File

@ -3,13 +3,11 @@
set -x
java -fullversion
{{ bazelisk_executable }} version
{{ bazelisk_executable }} build --spawn_strategy=standalone --genrule_strategy=standalone {{ bazelisk_targets|join(' ') }}
if [[ -f bazel-bin/plugins/javamelody/javamelody-deps_deploy.jar ]] ; then
# versions 2.14, 2.15, and 2.16 generate this file
cp bazel-bin/plugins/javamelody/javamelody-deps_deploy.jar javamelody-deps_deploy.jar
fi
# release.war is a symlink. We want an actual file so that docker copy works right.
cp bazel-bin/release.war release.war
{{ bazelisk_executable }} \
build \
--spawn_strategy=standalone \
--genrule_strategy=standalone \
{{ bazelisk_targets|join(' ') }}
args:
executable: /bin/bash
chdir: "{{ zuul_work_dir }}"