Skip to content
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

R Dev Container: Multi-platform build of the Docker container #63

Open
hturner opened this issue Sep 5, 2024 · 3 comments
Open

R Dev Container: Multi-platform build of the Docker container #63

hturner opened this issue Sep 5, 2024 · 3 comments
Labels
Misc Issues that cannot be classified otherwise SIP 2024 Items reserved for R Dev Day @ SIP 2024

Comments

@hturner
Copy link
Member

hturner commented Sep 5, 2024

The R Dev Container was primarily built for use with GitHub Codespaces (now extended to Gitpod Workspaces), so the underlying Docker container is built for linux/amd64 architecture. This means that it doesn't work well on M+ macOS or Windows as discussed in issue 112 of the R Dev Container repo.

@StarTrooper08 has attempted to use buildx to build a linux/amd64 image but got stuck.

If anyone with experience in this area can help us make progress on this issue it would be appreciated!

@hturner hturner added Misc Issues that cannot be classified otherwise RSECon24 labels Sep 5, 2024
@hturner
Copy link
Member Author

hturner commented Sep 30, 2024

Notes from RSECon24 added to r-devel/r-dev-env#112. t

To summarise: The dockerfile uses the Ubuntu r-project repo to install r-base-core when building the container, but this doesn't have a recent arm build (most recent when we tried was 4.1.2). There may be a more recent arm build in the debian r-project repo, so that may be a potential solution.

@hturner hturner added SIP 2024 Items reserved for R Dev Day @ SIP 2024 and removed RSECon24 labels Sep 30, 2024
@sjimellor-jr
Copy link

sjimellor-jr commented Oct 9, 2024

A few findings from looking into this issue.

  • GitHub Actions do not support ARM for non-Enterprise customers (reference: GitHub Actions: Arm based hosted runners for OSS github/roadmap#970). We will not be able to natively build ARM containers in GitHub Hosted Actions for now.
  • The Debian OS packages do not include ARM builds of R (same issue as Ubuntu) - the ARM reference in the CRAN documentation is for some R packages available via Debian repos only. (tested with FROM mcr.microsoft.com/devcontainers/cpp:dev-debian-12 and suitable deb reference changes)
  • The dev container contains everything needed to build R if you stop just after apt -y build-dep r-base-dev, you just don't have any version of R installed to initially test with, and don't have the language server R packages installed yet. But once a build has completed within the container, you can continue - this avoids the missing r-base-dev dependency on ARM completely.
  • Docker builds can emulate ARM using QEMU via binfmt on x86_64 (reference: https://github.com/docker/buildx?tab=readme-ov-file#building-multi-platform-images). apt-src can be used to build r-base-dev instead of installing it, but this was extremely slow on non-ARM hardware although may complete if given ~24 hours (about 15 times the build time).
  • Cross compiling with https://github.com/tonistiigi/xx may provide native performance for a build, suitable for use in a GitHub Action, to provide R within a dev container. (about twice the build time)
  • Attempts to use apt-src in combination with xx to cross compile the r-base-dev Debian package source have not succeeded (dpkg-buildpackage fails with missing dependencies, because we used the x86 package source, or "No such file or directory", "clang: error: no input files" if we ignore missing dependencies)
  • A combination of using xx to build the source binary, and buildx to create an ARM container (copying in the stable build), may provide a fully functional dev container.

Current status:

  • An ARM native dev container can be built on non-ARM if an existing R build is not required within it.
  • An ARM native dev container with an R build inside it may be built if we had ARM hardware to do the build.
  • An ARM native dev container may be cross compiled with additional research, or emulated with a very long build time.

@hturner
Copy link
Member Author

hturner commented Oct 17, 2024

Thanks @sjimellor-jr for digging into this! Your (off GitHub) comment about "why there isn't an ARM build of the Debian/Ubuntu package in the first place" got me wondering and after some searching around I found from the rocker/r-ubuntu Dockerfile that they use "ppa:marutter/rrutter4.0" as the repository vs "https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/". I tried building from the R Dev Container Dockerfile with Michael Rutter's base R PPA as the R repository and the build was successful on my ARM machine!

I think we will now be able to get this working with buildx. I'll leave this issue open for the moment and hopefully update it when we've got that working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Misc Issues that cannot be classified otherwise SIP 2024 Items reserved for R Dev Day @ SIP 2024
Projects
None yet
Development

No branches or pull requests

2 participants