-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for building as root user #96
Comments
If you create a Dockerfile that includes I would love to support GitHub Actions better, because I'm slowing migrating my own projects over to it. But at the same time, I would strongly prefer to minimize any breakage of existing CI setups that use |
well yes, but actually no[t quite] - rustup installs toolchains per user (see rust-lang/rustup#313) in the image, the toolchain is installed for the RUN rustup toolchain list
USER root
RUN rustup toolchain list →
resp. Running |
This PR attempts to lay the groundwork to address #96. In particular, we install the Rust toolchain globally by abusing `rustup`. We still preserve the legacy `rust` user but we now encourage derived Dockerfiles to consider `USER root`. This PR also removes ARM support. We want to explore the idea of supporting ARM more reliably using a separate image, but perhaps it would be better to refer those users to one of the Rust cross-compilation toolchains. See #63 for discussion.
I have opened PR #100, which tries make I'm reluctant to actually make I'm actually planning to work on a GitHub-based build on Monday and I make have some new ideas then. But I'm also very interested in feedback. Please let me know if you have any other ideas about how to approach this. |
This is the minimal change needed to allow the docker image to be run with `--user root` and still build correctly. There may be better long-term ways of doing this, but hopefully this is small enough to be uncontroversial. This isn't a breaking change for users running normally (as the `rust` user) because these are already the default paths. Refs: emk#96 Refs: emk#100
Got running as root working (for similar CI needs) by setting i.e. adding |
I would also be happy if I wouldn't need to fiddle with file permissions. I can't think of a backwards-compatible way to change it though. Beyond the Based on @gibfahn's comment I used a Dockerfile starting with
and that seems to work. Of course it's not super elegant, but maybe useful for some. |
This should now be officially supported in the new 1.49.0 release! (I wanted to roll this out with a new Rust release so that anybody whose CI system breaks will still have to option of using 1.48.0, rather than replacing the existing 1.48.0 release.) You still need to do something like:
...but this should now work. See the We may eventually come up with a better system, but this is the current compromise to avoid breaking too many people's CI. |
@emk Replying to #105 (comment)
So it looks like you changed these from: CARGO_HOME=/home/rust/.cargo
RUSTUP_HOME=/home/rust/.rustup to CARGO_HOME=/opt/rust/cargo
RUSTUP_HOME=/opt/rust/rustup right? Now That breaks my existing scripts (e.g. this) as they're now setting The bigger issue (for me) is that this makes caching harder. My existing solution is to add these lines to my -v "${XDG_CACHE_HOME:-$HOME/.cache}"/docker/cargo/registry:/home/rust/.cargo/registry \
-v "${XDG_CACHE_HOME:-$HOME/.cache}"/docker/cargo/git:/home/rust/.cargo/git \ This caches the registry and git cargo caches (see Cargo caching docs), and makes running this image almost as fast as running locally. However now I have to change this based on whether the user is running as rust@ea12b164a783:~/.cargo$ ls ~/.cargo; ls /opt/rust/cargo
config git registry
bin config env Looking at rust-lang/rustup#2383 (linked to from 3ae8179#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557), it looks like the reason they suggest not setting CARGO_HOME is to allow multiple users on a shared machine to run at the same time. The second comment on that issue suggests that that's a bad idea, and in any case there's not much reason to do so in a docker container anyway. Having a consistent I'm unsure if there's something else I'm missing that makes using |
Removing `RUSTUP_HOME` makes `cargo build` work again, and the other changes fix up caching. Refs: emk/rust-musl-builder#96 (comment)
How could this project be improved?
In some scenarios it might be preferred to build the project as the root user instead of the lower privilege
rust
user. One such example would be GitHub Actions. The Docker image is executed in an ephemeral VM whose only purpose is to run the build and die. Using this image in its current state requires a lot of permission changes prior and post build especially when using the cache action.If you're interested in implementing this feature yourself, how could I help you?
I have made a very crude "fix" to the image in my fork which is used by this script run by this Action. Although this works it is rather hacky. A proper solution would probably be either a global installation of the toolchain in the image or a separate tag for a root-based image.
If you would be willing to accept such a change, I could spend some time in the next few weeks to sketch a PR for this.
The text was updated successfully, but these errors were encountered: