Skip to content

Commit

Permalink
feat: Dockerfile for new Bazel releases (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rmiga authored Jan 27, 2022
1 parent 30708c0 commit 57bb5a0
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
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
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
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 \
python3 \
python3-pip \
unzip \
zip

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

0 comments on commit 57bb5a0

Please sign in to comment.