Skip to content

Avoid docker running as root - #2566

Merged
GMNGeoffrey merged 2 commits into
iree-org:mainfrom
GMNGeoffrey:nvidia-docker-fixup
Jul 22, 2020
Merged

GMNGeoffrey merged 2 commits into
iree-org:mainfrom
GMNGeoffrey:nvidia-docker-fixup

Conversation

@GMNGeoffrey

@GMNGeoffrey GMNGeoffrey commented Jul 17, 2020 •

Copy link
Copy Markdown
Member

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

@GMNGeoffrey

Copy link
Copy Markdown
Member Author

bazel: command not found

Lol bazel is only installed for root. Oh docker...

@GMNGeoffrey GMNGeoffrey changed the title Clean up nvidia-cmake docker file Avoid docker running as root Jul 18, 2020
@antiagainst

Copy link
Copy Markdown
Member

@GMNGeoffrey

Copy link
Copy Markdown
Member Author

So we are installing bazel by wget a installer.sh.. Why not use apt repo (docs.bazel.build/versions/master/install-ubuntu.html#install-on-ubuntu)?

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...

@GMNGeoffrey

Copy link
Copy Markdown
Member Author

Just look at the last commit. The first is from #2588. I'll rebase and drop that and switch everything back to prod images once #2583 is in.

# 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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Magic!! :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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...

GMNGeoffrey added a commit that referenced this pull request Jul 21, 2020
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)
@GMNGeoffrey

Copy link
Copy Markdown
Member Author

Updated the prod images after #2565, going to revert to using prod tags and double check this still works

@GMNGeoffrey
GMNGeoffrey force-pushed the nvidia-docker-fixup branch from 753d497 to cbe28d4 Compare July 21, 2020 23:35
@GMNGeoffrey
GMNGeoffrey merged commit f3af006 into iree-org:main Jul 22, 2020
@GMNGeoffrey
GMNGeoffrey deleted the nvidia-docker-fixup branch July 22, 2020 00:52
@rsuderman rsuderman mentioned this pull request Jul 22, 2020
This was referenced Jul 22, 2020
@GMNGeoffrey GMNGeoffrey added the infrastructure Relating to build systems, CI, or testing label Jul 24, 2020
@GMNGeoffrey

Copy link
Copy Markdown
Member Author

Somehow this seems to have made the integrations build take an hour instead of 20 minutes 😕

GMNGeoffrey added a commit that referenced this pull request Jul 24, 2020
For some reason #2566 made the
integrations build run three times as long. Reverting until we can
figure out the root cause.

See #2653

Confirmed presubmits now take 20 minutes
GMNGeoffrey added a commit that referenced this pull request Jul 27, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ci] Clean up the artifact directory for GPU bots

5 participants