Skip to content

Add a flag to specify the JDK version to package with Bazel when building the container image #2187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bazel/oci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

FROM ubuntu:20.04 AS base_image

ARG JAVA_VERSION

RUN --mount=source=bazel/oci/install_packages.sh,target=/mnt/install_packages.sh,type=bind \
/mnt/install_packages.sh

Expand Down
9 changes: 9 additions & 0 deletions bazel/oci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ To build and publish docker container for new Bazel LTS release to `gcr.io/bazel
$ ./build.sh gcr.io/bazel-public/bazel <bazel version>
```

Note: this installs the Java 8 JDK on the docker container image. To build an image with a more recent JDK version,
specify the package name of the JDK to install as the third argument, for instance:

```bash
$ ./build.sh gcr.io/bazel-public/bazel <bazel version> openjdk-21-jdk
```

This will append the JDK version to the tag of the Bazel container image.

### 2. Push the docker container to `gcr.io/bazel-public/bazel`
```bash
$ docker push gcr.io/bazel-public/bazel:<bazel version>
Expand Down
10 changes: 8 additions & 2 deletions bazel/oci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

readonly OCI_REPOSITORY=$1
readonly BAZEL_VERSION=$2
JAVA_VERSION=$3
TAG=$BAZEL_VERSION-$JAVA_VERSION

set -o errexit -o nounset -o pipefail

Expand All @@ -21,6 +23,10 @@ if [ -z "${BAZEL_VERSION}" ]; then
exit 1
fi

if [ -z "$JAVA_VERSION" ]; then
JAVA_VERSION="openjdk-8-jdk"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no hurt to upgrade the default JDK version to 11 or even 21?

fi

GIT_ROOT=$(git rev-parse --show-toplevel)
readonly GIT_ROOT

Expand All @@ -30,6 +36,6 @@ fi

docker ${buildx:+"${buildx}"} build \
--file "${GIT_ROOT}/bazel/oci/Dockerfile" \
--tag "${OCI_REPOSITORY}:${BAZEL_VERSION}" \
--build-arg BAZEL_VERSION="${BAZEL_VERSION}" \
--tag "${OCI_REPOSITORY}:${TAG}" \
--build-arg BAZEL_VERSION="${BAZEL_VERSION}" --build-arg JAVA_VERSION="${JAVA_VERSION}"\
"${GIT_ROOT}"
4 changes: 3 additions & 1 deletion bazel/oci/install_packages.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

echo "Using Java version: $JAVA_VERSION"

set -o errexit -o nounset -o pipefail

apt-get update
Expand All @@ -11,7 +13,7 @@ apt-get install --yes \
build-essential \
curl \
git \
openjdk-8-jdk \
"$JAVA_VERSION" \
python3 \
python3-pip \
unzip \
Expand Down