Skip to content

Commit 6b953aa

Browse files
committed
feat: don't rebuild container on bazel version change
This removes the `.bazelversion` as a dependency from the `Dockerfile`, meaning that bazel version bumps won't force the container to be rebuilt. The `.bazelversion` was only used to generate bash completion. The bash completion is now run only in interactive mode (if no command is run) and as the container is run (not built). (bazelisk is bumped to a recent version that contains the completion command)
1 parent 8f6c114 commit 6b953aa

File tree

3 files changed

+19
-38
lines changed

3 files changed

+19
-38
lines changed

ci/container/Dockerfile

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ RUN curl -fsSL https://github.com/FiloSottile/mkcert/releases/download/v${mkcert
4545
echo "$mkcert_sha /usr/local/bin/mkcert" | sha256sum --check && \
4646
chmod +x /usr/local/bin/mkcert
4747

48-
ARG bazelisk_sha=fd8fdff418a1758887520fa42da7e6ae39aefc788cf5e7f7bb8db6934d279fc4
49-
RUN curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-amd64 -o /usr/bin/bazel && \
48+
ARG bazelisk_sha=22e7d3a188699982f661cf4687137ee52d1f24fec1ec893d91a6c4d791a75de8
49+
RUN curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.28.1/bazelisk-linux-amd64 -o /usr/bin/bazel && \
5050
echo "$bazelisk_sha /usr/bin/bazel" | sha256sum --check && \
5151
chmod 777 /usr/bin/bazel
5252

@@ -84,22 +84,10 @@ RUN curl -L "https://apt.llvm.org/llvm-snapshot.gpg.key" | apt-key add - && \
8484
mv afl-fuzz afl-showmap /afl && \
8585
cd .. && rm -rf AFLplusplus
8686

87-
# Pre-populate the Bazel installation for root
88-
# (note: this is only used for bash completion; the actual bazel version comes from bazelisk)
89-
COPY .bazelversion /tmp/bazel/
90-
RUN cd /tmp/bazel && bazel version
91-
92-
COPY ./ci/container/files/generate-bazel-completion.sh /tmp/
93-
RUN USE_BAZEL_VERSION=$(tail -1 /tmp/bazel/.bazelversion) /tmp/generate-bazel-completion.sh && \
94-
echo "source /etc/bash_completion.d/bazel" >>/etc/bash.bashrc
95-
9687
USER ubuntu
9788
# Set PATH for ubuntu user
9889
ENV PATH=/ic/bin:/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:$PATH
9990

100-
# Pre-populate the Bazel installation for ubuntu
101-
RUN cd /tmp/bazel && bazel version
102-
10391
# Add Rust/Cargo support
10492
RUN mkdir -p /tmp/rust-version/
10593
COPY rust-toolchain.toml /tmp/rust-version/rust-toolchain.toml
@@ -141,4 +129,4 @@ RUN apt -yq update && \
141129
apt -yqq install $(sed -e "s/#.*//" "/tmp/$(basename $PACKAGE_DEV_FILE)") && \
142130
rm "/tmp/$(basename $PACKAGE_DEV_FILE)"
143131

144-
USER $CI_USER
132+
USER $CI_USER

ci/container/container-run.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,17 @@ while test $# -gt $CTR; do
8787
esac
8888
done
8989

90-
# option to pass in another shell if desired
9190
if [ $# -eq 0 ]; then
92-
cmd=("${USHELL:-/usr/bin/bash}")
91+
# if no command is specified, create an shell
92+
if [ -z "${USHELL:-}" ] || [ "$USHELL" == "bash" ]; then
93+
# bit of a hack: we source the completion by passing it as an rcfile.
94+
# The completion itself requires `.bazelversion` to exist.
95+
# We avoid generating the completion in the container _build_ so that
96+
# the container itself does not depend on the bazel version.
97+
cmd=("/usr/bin/bash" -c "exec bash --rcfile <(bazel completion bash)")
98+
else
99+
cmd=("$USHELL")
100+
fi
93101
else
94102
cmd=("$@")
95103
fi
@@ -134,6 +142,8 @@ USER=$(whoami)
134142

135143
PODMAN_RUN_ARGS=(
136144
-w "$WORKDIR"
145+
--rm # remove container after it ran
146+
--log-driver=none # by default podman logs all of stdout to the journal which is resource-consuming and wasteful
137147

138148
-u "ubuntu:ubuntu"
139149
-e HOSTUSER="$USER"
@@ -225,21 +235,14 @@ else
225235
eprintln "No ssh-agent to forward."
226236
fi
227237

228-
# Omit -t if not a tty.
229-
# Also shut up logging, because podman will by default log
230-
# every byte of standard output to the journal, and that
231-
# destroys the journal + wastes enormous amounts of CPU.
232-
# I witnessed journald and syslog peg 2 cores of my devenv
233-
# when running a simple cat /path/to/file.
238+
# if a user is attached, make it interactive and create tty
234239
if tty >/dev/null 2>&1; then
235-
tty_arg=-t
236-
else
237-
tty_arg=
240+
PODMAN_RUN_ARGS+=(-i -t)
238241
fi
239242

240243
# Privileged rootful podman is required due to requirements of IC-OS guest build;
241244
# additionally, we need to use hosts's cgroups and network.
242-
OTHER_ARGS=(--pids-limit=-1 -i $tty_arg --log-driver=none --rm --privileged --network=host --cgroupns=host)
245+
PODMAN_RUN_ARGS+=(--pids-limit=-1 --privileged --network=host --cgroupns=host)
243246

244247
if [ -f "$HOME/.container-run.conf" ]; then
245248
# conf file with user's custom PODMAN_RUN_USR_ARGS
@@ -255,4 +258,4 @@ if [ -f "$HOME/.container-run.conf" ]; then
255258
fi
256259

257260
set -x
258-
exec "${CONTAINER_CMD[@]}" run "${OTHER_ARGS[@]}" "${PODMAN_RUN_ARGS[@]}" -w "$WORKDIR" "$IMAGE" "${cmd[@]}"
261+
exec "${CONTAINER_CMD[@]}" run "${PODMAN_RUN_ARGS[@]}" -w "$WORKDIR" "$IMAGE" "${cmd[@]}"

ci/container/files/generate-bazel-completion.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)