Skip to content

Commit dec35c5

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 dec35c5

File tree

3 files changed

+18
-41
lines changed

3 files changed

+18
-41
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: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,18 @@ 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 interactive shell
92+
PODMAN_RUN_ARGS+=( -i -t ) # also assumes tty
93+
if [ -z "${USHELL:-}" ] || [ "$USHELL" == "bash" ]; then
94+
# bit of a hack: we source the completion by passing it as an rcfile.
95+
# The completion itself requires `.bazelversion` to exist.
96+
# We avoid generating the completion in the container _build_ so that
97+
# the container itself does not depend on the bazel version.
98+
cmd=("/usr/bin/bash" -c "exec bash --rcfile <(bazel completion bash)")
99+
else
100+
cmd=("$USHELL")
101+
fi
93102
else
94103
cmd=("$@")
95104
fi
@@ -134,6 +143,8 @@ USER=$(whoami)
134143

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

138149
-u "ubuntu:ubuntu"
139150
-e HOSTUSER="$USER"
@@ -225,21 +236,9 @@ else
225236
eprintln "No ssh-agent to forward."
226237
fi
227238

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.
234-
if tty >/dev/null 2>&1; then
235-
tty_arg=-t
236-
else
237-
tty_arg=
238-
fi
239-
240239
# Privileged rootful podman is required due to requirements of IC-OS guest build;
241240
# 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)
241+
PODMAN_RUN_ARGS+=(--pids-limit=-1 --privileged --network=host --cgroupns=host)
243242

244243
if [ -f "$HOME/.container-run.conf" ]; then
245244
# conf file with user's custom PODMAN_RUN_USR_ARGS
@@ -255,4 +254,4 @@ if [ -f "$HOME/.container-run.conf" ]; then
255254
fi
256255

257256
set -x
258-
exec "${CONTAINER_CMD[@]}" run "${OTHER_ARGS[@]}" "${PODMAN_RUN_ARGS[@]}" -w "$WORKDIR" "$IMAGE" "${cmd[@]}"
257+
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)