Skip to content

Commit 064d91a

Browse files
committed
BuildPacks: support arm64 where possible (i.e. not R)
1 parent 33eee4a commit 064d91a

File tree

12 files changed

+84
-18
lines changed

12 files changed

+84
-18
lines changed

repo2docker/buildpacks/_r_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
Keeping this in r.py would lead to cyclic imports.
55
"""
66
from ..semver import parse_version as V
7+
from ..utils import get_platform
78

89

910
def rstudio_base_scripts(r_version):
1011
"""Base steps to install RStudio and shiny-server."""
1112

13+
if get_platform() != "linux-64":
14+
raise RuntimeError("RStudio is only available for linux-64")
15+
1216
# Shiny server (not the package!) seems to be the same version for all R versions
1317
shiny_server_url = "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.17.973-amd64.deb"
1418
shiny_proxy_version = "1.1"

repo2docker/buildpacks/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import escapism
1212
import jinja2
1313

14+
from ..utils import get_platform
15+
1416
# Only use syntax features supported by Docker 17.09
1517
TEMPLATE = r"""
1618
FROM buildpack-deps:bionic
@@ -229,6 +231,7 @@ def __init__(self):
229231
"Windows environment detected. Note that Windows "
230232
"support is experimental in repo2docker."
231233
)
234+
self.platform = get_platform()
232235

233236
def get_packages(self):
234237
"""

repo2docker/buildpacks/conda/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def get_build_env(self):
5959
# this exe should be used for installs after bootstrap with micromamba
6060
# switch this to /usr/local/bin/micromamba to use it for all installs
6161
("MAMBA_EXE", "${CONDA_DIR}/bin/mamba"),
62+
("CONDA_PLATFORM", self.platform),
6263
]
6364
if self._nb_requirements_file:
6465
env.append(("NB_REQUIREMENTS_FILE", self._nb_requirements_file))
@@ -160,13 +161,13 @@ def get_build_script_files(self):
160161
# major Python versions during upgrade.
161162
# If no version is specified or no matching X.Y version is found,
162163
# the default base environment is used.
163-
frozen_name = "environment.lock"
164+
frozen_name = f"environment-{self.platform}.lock"
164165
pip_frozen_name = "requirements.txt"
165166
if py_version:
166167
if self.python_version == "2.7":
167168
# python 2 goes in a different env
168169
files[
169-
"conda/environment.py-2.7.lock"
170+
"conda/environment.py-2.7-linux-64.lock"
170171
] = self._kernel_environment_file = "/tmp/env/kernel-environment.lock"
171172
# additional pip requirements for kernel env
172173
if os.path.exists(os.path.join(HERE, "requirements.py-2.7.txt")):
@@ -176,12 +177,14 @@ def get_build_script_files(self):
176177
self._kernel_requirements_file
177178
) = "/tmp/env/kernel-requirements.txt"
178179
else:
179-
py_frozen_name = f"environment.py-{py_version}.lock"
180+
py_frozen_name = f"environment.py-{py_version}-{self.platform}.lock"
180181
if os.path.exists(os.path.join(HERE, py_frozen_name)):
181182
frozen_name = py_frozen_name
182183
pip_frozen_name = f"requirements.py-{py_version}.pip"
183184
else:
184-
raise ValueError(f"Python version {py_version} is not supported!")
185+
raise ValueError(
186+
f"Python version {py_version} {self.platform} is not supported!"
187+
)
185188
files[
186189
"conda/" + frozen_name
187190
] = self._nb_environment_file = "/tmp/env/environment.lock"

repo2docker/buildpacks/conda/freeze.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def set_python(py_env_file, py):
131131
for platform in args.platform:
132132
env_file = pathlib.Path(str(ENV_FILE_T).format(py=py))
133133
set_python(env_file, py)
134-
frozen_file = pathlib.Path(os.path.splitext(env_file)[0] + f"-{platform}.lock")
134+
frozen_file = pathlib.Path(
135+
os.path.splitext(env_file)[0] + f"-{platform}.lock"
136+
)
135137
freeze(env_file, frozen_file, platform)
136138
if py == default_py:
137139
shutil.copy(frozen_file, FROZEN_FILE_T.format(platform=platform))

repo2docker/buildpacks/conda/install-base-env.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cd $(dirname $0)
88
export MAMBA_VERSION=1.0.0
99
export CONDA_VERSION=4.13.0
1010

11-
URL="https://anaconda.org/conda-forge/micromamba/${MAMBA_VERSION}/download/linux-64/micromamba-${MAMBA_VERSION}-0.tar.bz2"
11+
URL="https://anaconda.org/conda-forge/micromamba/${MAMBA_VERSION}/download/${CONDA_PLATFORM}/micromamba-${MAMBA_VERSION}-0.tar.bz2"
1212

1313
# make sure we don't do anything funky with user's $HOME
1414
# since this is run as root

repo2docker/buildpacks/julia/julia_project.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,25 @@ def get_build_env(self):
7979
will be installed
8080
- `JULIA_DEPOT_PATH`: path where Julia libraries are installed.
8181
- `JULIA_VERSION`: default version of julia to be installed
82+
- `JULIA_ARCH`: machine architecture used in Julia download URLs
83+
- `JULIA_ARCH_SHORT`: machine architecture used in Julia download URLs
8284
- `JUPYTER`: environment variable required by IJulia to point to
8385
the `jupyter` executable
8486
8587
For example, a tuple may be `('JULIA_VERSION', '0.6.0')`.
8688
8789
"""
90+
if self.platform == "linux-aarch64":
91+
julia_arch = julia_arch_short = "aarch64"
92+
else:
93+
julia_arch = "x86_64"
94+
julia_arch_short = "x64"
8895
return super().get_build_env() + [
8996
("JULIA_PATH", "${APP_BASE}/julia"),
9097
("JULIA_DEPOT_PATH", "${JULIA_PATH}/pkg"),
9198
("JULIA_VERSION", self.julia_version),
99+
("JULIA_ARCH", julia_arch),
100+
("JULIA_ARCH_SHORT", julia_arch_short),
92101
("JUPYTER", "${NB_PYTHON_PREFIX}/bin/jupyter"),
93102
("JUPYTER_DATA_DIR", "${NB_PYTHON_PREFIX}/share/jupyter"),
94103
]
@@ -129,7 +138,7 @@ def get_build_scripts(self):
129138
"root",
130139
r"""
131140
mkdir -p ${JULIA_PATH} && \
132-
curl -sSL "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-x86_64.tar.gz" | tar -xz -C ${JULIA_PATH} --strip-components 1
141+
curl -sSL "https://julialang-s3.julialang.org/bin/linux/${JULIA_ARCH_SHORT}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${JULIA_ARCH}.tar.gz" | tar -xz -C ${JULIA_PATH} --strip-components 1
133142
""",
134143
),
135144
(

repo2docker/buildpacks/julia/julia_require.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,28 @@ def get_build_env(self):
6969
- `JULIA_DEPOT_PATH`: path where Julia libraries are installed.
7070
Similar to JULIA_PKGDIR, used in 1.x.
7171
- `JULIA_VERSION`: default version of julia to be installed
72+
- `JULIA_ARCH`: machine architecture used in Julia download URLs
73+
- `JULIA_ARCH_SHORT`: machine architecture used in Julia download URLs
7274
- `JUPYTER`: environment variable required by IJulia to point to
7375
the `jupyter` executable
7476
7577
For example, a tuple may be `('JULIA_VERSION', '0.6.0')`.
7678
7779
"""
80+
if self.platform == "linux-aarch64":
81+
julia_arch = julia_arch_short = "aarch64"
82+
else:
83+
julia_arch = "x86_64"
84+
julia_arch_short = "x64"
7885
return super().get_build_env() + [
7986
("JULIA_PATH", "${APP_BASE}/julia"),
8087
("JULIA_HOME", "${JULIA_PATH}/bin"), # julia <= 0.6
8188
("JULIA_BINDIR", "${JULIA_HOME}"), # julia >= 0.7
8289
("JULIA_PKGDIR", "${JULIA_PATH}/pkg"),
8390
("JULIA_DEPOT_PATH", "${JULIA_PKGDIR}"), # julia >= 0.7
8491
("JULIA_VERSION", self.julia_version),
92+
("JULIA_ARCH", julia_arch),
93+
("JULIA_ARCH_SHORT", julia_arch_short),
8594
("JUPYTER", "${NB_PYTHON_PREFIX}/bin/jupyter"),
8695
]
8796

@@ -111,7 +120,7 @@ def get_build_scripts(self):
111120
"root",
112121
r"""
113122
mkdir -p ${JULIA_PATH} && \
114-
curl -sSL "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-x86_64.tar.gz" | tar -xz -C ${JULIA_PATH} --strip-components 1
123+
curl -sSL "https://julialang-s3.julialang.org/bin/linux/${JULIA_ARCH_SHORT}/${JULIA_VERSION%[.-]*}/julia-${JULIA_VERSION}-linux-${JULIA_ARCH}.tar.gz" | tar -xz -C ${JULIA_PATH} --strip-components 1
115124
""",
116125
),
117126
(

repo2docker/buildpacks/nix/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def get_path(self):
1313

1414
def get_env(self):
1515
"""Ordered list of environment variables to be set for this image"""
16+
1617
return super().get_env() + [
1718
("NIX_PATH", "nixpkgs=/home/${NB_USER}/.nix-defexpr/channels/nixpkgs"),
1819
("NIX_SSL_CERT_FILE", "/etc/ssl/certs/ca-certificates.crt"),
@@ -30,6 +31,10 @@ def get_build_scripts(self):
3031
- install nix package manager for user
3132
3233
"""
34+
if self.platform == "linux-aarch64":
35+
nix_arch = "aarch64"
36+
else:
37+
nix_arch = "x86_64"
3338
return super().get_build_scripts() + [
3439
(
3540
"root",
@@ -43,9 +48,9 @@ def get_build_scripts(self):
4348
),
4449
(
4550
"${NB_USER}",
46-
"""
47-
bash /home/${NB_USER}/.local/bin/install-nix.bash && \
48-
rm /home/${NB_USER}/.local/bin/install-nix.bash
51+
f"""
52+
NIX_ARCH={nix_arch} bash /home/${{NB_USER}}/.local/bin/install-nix.bash && \
53+
rm /home/${{NB_USER}}/.local/bin/install-nix.bash
4954
""",
5055
),
5156
]

repo2docker/buildpacks/nix/install-nix.bash

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
set -ex
44

55
NIX_VERSION="2.3.9"
6-
NIX_SHA256="49763fd7fa06bcb712ced2f3f11afd275e3a4d7bc5ff0d6fd1d50a4c3ce7bbf4"
6+
if [ "$NIX_ARCH" = "aarch64" ]; then
7+
NIX_SHA256="733a26911193fdd44d5d68342075af5924d8c0701aae877e51a38d74ee9f4ff8"
8+
else
9+
NIX_SHA256="49763fd7fa06bcb712ced2f3f11afd275e3a4d7bc5ff0d6fd1d50a4c3ce7bbf4"
10+
fi
711

812
# Do all our operations in /tmp, since we can't rely on current directory being writeable yet.
913
cd /tmp
10-
wget --quiet https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.xz
11-
echo "$NIX_SHA256 nix-$NIX_VERSION-x86_64-linux.tar.xz" | sha256sum -c
12-
tar xJf nix-*-x86_64-linux.tar.xz
13-
sh nix-*-x86_64-linux/install
14-
rm -r nix-*-x86_64-linux*
14+
wget --quiet https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-$NIX_ARCH-linux.tar.xz
15+
echo "$NIX_SHA256 nix-$NIX_VERSION-$NIX_ARCH-linux.tar.xz" | sha256sum -c
16+
tar xJf nix-*-$NIX_ARCH-linux.tar.xz
17+
sh nix-*-$NIX_ARCH-linux/install
18+
rm -r nix-*-$NIX_ARCH-linux*

repo2docker/buildpacks/r.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import requests
66

77
from ..semver import parse_version as V
8+
from ..utils import get_platform
89
from ._r_base import rstudio_base_scripts
910
from .python import PythonBuildPack
1011

@@ -277,6 +278,8 @@ def get_build_scripts(self):
277278

278279
cran_mirror_url = self.get_cran_mirror_url(self.checkpoint_date)
279280

281+
if get_platform() != "linux-64":
282+
raise RuntimeError("RStudio is only available for linux-64")
280283
scripts = [
281284
(
282285
"root",

0 commit comments

Comments
 (0)