Skip to content
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

feat: Dockerfile for new Bazel releases #1290

Merged
merged 5 commits into from
Jan 27, 2022
Merged
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
23 changes: 23 additions & 0 deletions bazel/oci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ATTENTION: use the build.sh script to build this image.
# ./build.sh <OCI_REPOSITORY> <BAZEL_VERSION>

FROM ubuntu:16.04@sha256:0f71fa8d4d2d4292c3c617fda2b36f6dabe5c8b6e34c3dc5b0d17d4e704bd39c AS base_image

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

FROM base_image AS downloader

ARG BAZEL_VERSION

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

FROM base_image

RUN useradd --system --create-home --home-dir=/home/ubuntu --shell=/bin/bash --gid=root --groups=sudo --uid=1000 ubuntu
USER ubuntu
WORKDIR /home/ubuntu
COPY --from=downloader /var/bazel/bazel /usr/local/bin/bazel
ENTRYPOINT ["/usr/local/bin/bazel"]
35 changes: 35 additions & 0 deletions bazel/oci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

readonly OCI_REPOSITORY=$1
readonly BAZEL_VERSION=$2

set -o errexit -o nounset -o pipefail

function print_usage() {
>&2 echo "Usage: $0 <OCI_REPOSITORY> <BAZEL_VERSION>"
}

if [ -z "${OCI_REPOSITORY}" ]; then
>&2 echo "ERROR: missing 'OCI_REPOSITORY' argument"
print_usage
exit 1
fi

if [ -z "${BAZEL_VERSION}" ]; then
>&2 echo "ERROR: missing 'BAZEL_VERSION' argument"
print_usage
exit 1
fi

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

if docker buildx version 2>&1 1>/dev/null; then
philwo marked this conversation as resolved.
Show resolved Hide resolved
buildx="buildx"
fi

docker ${buildx:+"${buildx}"} build \
--file "${GIT_ROOT}/bazel/oci/Dockerfile" \
--tag "${OCI_REPOSITORY}:${BAZEL_VERSION}" \
--build-arg BAZEL_VERSION="${BAZEL_VERSION}" \
"${GIT_ROOT}"
18 changes: 18 additions & 0 deletions bazel/oci/install_bazel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -o errexit -o nounset -o pipefail

curl \
--fail \
--location \
--remote-name \
"https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-x86_64"

curl \
--fail \
--location \
"https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-x86_64.sha256" \
| sha256sum --check

mv "bazel-${BAZEL_VERSION}-linux-x86_64" bazel
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this architecture aware to support containers that work on arm64, too?

chmod +x bazel
20 changes: 20 additions & 0 deletions bazel/oci/install_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -o errexit -o nounset -o pipefail

apt-get update

export DEBIAN_FRONTEND="noninteractive"
export TZ="Etc/UTC"

apt-get install --yes \
build-essential \
curl \
git \
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.

Should we use OpenJDK 11 now? Bazel itself at least no longer supports JDK 8 (although I think you can still use it to build stuff).

python3 \
python3-pip \
unzip \
zip

ln -s "$(which python3)" /usr/bin/python