Skip to content

Commit 49162fc

Browse files
authored
Merge pull request #1228 from manics/arm64
Add ARM64 support where possible
2 parents cde0126 + 8f81864 commit 49162fc

33 files changed

+1340
-435
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ jobs:
125125
uses: docker/build-push-action@v3
126126
with:
127127
context: .
128-
platforms: linux/amd64
128+
platforms: linux/amd64,linux/arm64
129129
push: true
130130
tags: ${{ env.TAGS }}

repo2docker/app.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import tempfile
1717
import time
18+
import warnings
1819
from urllib.parse import urlparse
1920

2021
import entrypoints
@@ -36,7 +37,7 @@
3637
RBuildPack,
3738
)
3839
from .engine import BuildError, ContainerEngineException, ImageLoadError
39-
from .utils import ByteSpecification, R2dState, chdir
40+
from .utils import ByteSpecification, R2dState, chdir, get_platform
4041

4142

4243
class Repo2Docker(Application):
@@ -250,6 +251,27 @@ def _user_name_default(self):
250251
config=True,
251252
)
252253

254+
platform = Unicode(
255+
config=True,
256+
help="""
257+
Platform to build for, linux/amd64 (recommended) or linux/arm64 (experimental).
258+
""",
259+
)
260+
261+
@default("platform")
262+
def _platform_default(self):
263+
"""
264+
Default platform
265+
"""
266+
p = get_platform()
267+
if p == "linux/arm64":
268+
warnings.warn(
269+
"Building for linux/arm64 is experimental. "
270+
"To use the recommended platform set --Repo2Docker.platform=linux/amd64. "
271+
"To silence this warning set --Repo2Docker.platform=linux/arm64."
272+
)
273+
return p
274+
253275
extra_build_args = Dict(
254276
{},
255277
help="""
@@ -778,6 +800,7 @@ def build(self):
778800
else:
779801
picked_buildpack = self.default_buildpack()
780802

803+
picked_buildpack.platform = self.platform
781804
picked_buildpack.appendix = self.appendix
782805
# Add metadata labels
783806
picked_buildpack.labels["repo2docker.version"] = self.version
@@ -819,6 +842,7 @@ def build(self):
819842
build_args,
820843
self.cache_from,
821844
self.extra_build_kwargs,
845+
platform=self.platform,
822846
):
823847
if docker_client.string_output:
824848
self.log.info(l, extra=dict(phase=R2dState.BUILDING))

repo2docker/buildpacks/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def __init__(self):
229229
"Windows environment detected. Note that Windows "
230230
"support is experimental in repo2docker."
231231
)
232+
self.platform = ""
232233

233234
def get_packages(self):
234235
"""
@@ -559,6 +560,7 @@ def build(
559560
build_args,
560561
cache_from,
561562
extra_build_kwargs,
563+
platform=None,
562564
):
563565
tarf = io.BytesIO()
564566
tar = tarfile.open(fileobj=tarf, mode="w")
@@ -613,6 +615,7 @@ def _filter_tar(tar):
613615
buildargs=build_args,
614616
container_limits=limits,
615617
cache_from=cache_from,
618+
platform=platform,
616619
)
617620

618621
build_kwargs.update(extra_build_kwargs)

repo2docker/buildpacks/conda/__init__.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class CondaBuildPack(BaseImage):
3535
# extra pip requirements.txt for the notebook env
3636
_nb_requirements_file = ""
3737

38+
def _conda_platform(self):
39+
"""Return the conda platform name for the current platform"""
40+
if self.platform == "linux/amd64":
41+
return "linux-64"
42+
if self.platform == "linux/arm64":
43+
return "linux-aarch64"
44+
raise ValueError(f"Unknown platform {self.platform}")
45+
3846
def get_build_env(self):
3947
"""Return environment variables to be set.
4048
@@ -59,6 +67,7 @@ def get_build_env(self):
5967
# this exe should be used for installs after bootstrap with micromamba
6068
# switch this to /usr/local/bin/micromamba to use it for all installs
6169
("MAMBA_EXE", "${CONDA_DIR}/bin/mamba"),
70+
("CONDA_PLATFORM", self._conda_platform()),
6271
]
6372
if self._nb_requirements_file:
6473
env.append(("NB_REQUIREMENTS_FILE", self._nb_requirements_file))
@@ -160,13 +169,18 @@ def get_build_script_files(self):
160169
# major Python versions during upgrade.
161170
# If no version is specified or no matching X.Y version is found,
162171
# the default base environment is used.
163-
frozen_name = "environment.lock"
172+
frozen_name = f"environment-{self._conda_platform()}.lock"
164173
pip_frozen_name = "requirements.txt"
165174
if py_version:
166175
if self.python_version == "2.7":
176+
if "linux-64" != self._conda_platform():
177+
raise ValueError(
178+
f"Python version 2.7 {self._conda_platform()} is not supported!"
179+
)
180+
167181
# python 2 goes in a different env
168182
files[
169-
"conda/environment.py-2.7.lock"
183+
"conda/environment.py-2.7-linux-64.lock"
170184
] = self._kernel_environment_file = "/tmp/env/kernel-environment.lock"
171185
# additional pip requirements for kernel env
172186
if os.path.exists(os.path.join(HERE, "requirements.py-2.7.txt")):
@@ -176,12 +190,16 @@ def get_build_script_files(self):
176190
self._kernel_requirements_file
177191
) = "/tmp/env/kernel-requirements.txt"
178192
else:
179-
py_frozen_name = f"environment.py-{py_version}.lock"
193+
py_frozen_name = (
194+
f"environment.py-{py_version}-{self._conda_platform()}.lock"
195+
)
180196
if os.path.exists(os.path.join(HERE, py_frozen_name)):
181197
frozen_name = py_frozen_name
182198
pip_frozen_name = f"requirements.py-{py_version}.pip"
183199
else:
184-
raise ValueError(f"Python version {py_version} is not supported!")
200+
raise ValueError(
201+
f"Python version {py_version} {self._conda_platform()} is not supported!"
202+
)
185203
files[
186204
"conda/" + frozen_name
187205
] = self._nb_environment_file = "/tmp/env/environment.lock"
@@ -366,6 +384,10 @@ def get_env_scripts(self):
366384
""",
367385
)
368386
)
387+
if self.platform != "linux/amd64":
388+
raise RuntimeError(
389+
f"RStudio is only available for linux/amd64 ({self.platform})"
390+
)
369391
scripts += rstudio_base_scripts(self.r_version)
370392
scripts += [
371393
(

0 commit comments

Comments
 (0)