Repository navigation
Avoid docker running as root - #2566
Conversation
Lol bazel is only installed for root. Oh docker... |
|
So we are installing bazel by |
Historical reasons I think from when this happened as part of a GitHub action. I think Scott spent quite some time trying to get Bazel to just install 😁 Let's see if apt just works now. I'm still dismayed by the apt-key warning though... |
ceae22a to
753d497
Compare
| # Requires that KOKORO_ROOT and KOKORO_ARTIFACTS_DIR have been set | ||
| # Sets the environment variable DOCKER_RUN_ARGS to be used by subsequent | ||
| # `docker run` invocations. | ||
| function docker_setup() { |
There was a problem hiding this comment.
Yeah.... I'm happy to refactor if you have a suggestion of a better way to do it. I'm not thrilled with this :-/ Bash just kinda sucks...
Enables running our Docker builds as an arbitrary non-root user. This allows usage of `docker run` without weird things like all the files created being owned by root. It also includes updates to make it possible to run the docker scripts locally provided the relevant env variables are set. This includes simplification of the Bazel installation to just use apt. I tried to get rid of the necessity for the scary-looking `APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE`, but I couldn't find any alternatives. The warning message it prints doesn't even make sense as a warning. Reworks the update script to allow updating multiple images at once including updating *all* images. Also institutes some general Docker best practices like [apt-get cache busting](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get) and [layer minimization](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#minimize-the-number-of-layers) (although note on the latter that it looks like we might want to investigate multi-stage builds). Part of #2565 Tested: Set build scripts to use the "latest" tag and ran all the presubmits, including manually triggering the linux_x86-turing_cmake, which is not enabled by default yet. See status for [`d44f343` (#2583)](d44f343) #2566 makes our Docker scripts actually run without root and use these images (including manually triggering builds that aren't running by default yet): - [linux_bazel_core](https://source.cloud.google.com/results/invocations/74af7fb4-1032-42ac-953a-314bf314c503) - [linux_bazel_bindings](https://source.cloud.google.com/results/invocations/f4da9656-5940-4481-9df3-be6a41a64356) - [linux_bazel_integrations](https://source.cloud.google.com/results/invocations/248d516a-6da6-45b4-84ef-bd7c9942ce3c) - [linux_cmake](https://source.cloud.google.com/results/invocations/d3cc69c0-4de7-40ce-84b4-6201bb350b38) - [android_arm64_cmake](https://source.cloud.google.com/results/invocations/1b07091e-533c-4edc-8385-f378f9084128/targets) - [linux_x86-turing_cmake](https://source.cloud.google.com/results/invocations/d73d847b-f56d-41a3-ad49-f2b9368685bd)
|
Updated the prod images after #2565, going to revert to using prod tags and double check this still works |
753d497 to
cbe28d4
Compare
|
Somehow this seems to have made the integrations build take an hour instead of 20 minutes 😕 |
Instead of mounting the user's existing Bazel cache, create a fake home directory under the Kokoro root directory. This is another attempt at #2566 which had to be rolled back for the Bazel integrations build because it made it three times slower. It turns out the root cause there is that the docker container volumes are by default mounted in /tmpfs which on Kokoro is a local-ssd. The home directory, on the other hand, is a persistent SSD. The integrations job is running Bazel with 64 cores, which means it's IO bound. The difference turns out to be substantial. Fixes #2653 Tested: Ran simulate_kokoro on the core build locally to confirm this doesn't break RBE cloud credentials. The integrations presubmit on this PR takes 20 minutes, as before.
This avoids everything having root permissions, created files being
owned by root, and other nastiness. This is made slightly more
complicated by Google linux machine's...creative... setup for user
management. All these scripts can be run locally provided the appropriate
env variables are set, which can be done with the script provided in
#2588.
This was the root cause for #2565.
The image we're using for the GPU builds doesn't have passwordless sudo
so we couldn't delete the Kokoro artifacts directory.
Fixes #2565