Skip to content

Commit 99125ab

Browse files
authored
Merge branch 'main' into feat/new-base
2 parents e956501 + 49162fc commit 99125ab

36 files changed

+1356
-457
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
# all previous steps always run in order to exercise them
5656
- name: Publish distribution to PyPI
5757
if: startsWith(github.ref, 'refs/tags')
58-
uses: pypa/gh-action-pypi-publish@v1.5.1
58+
uses: pypa/gh-action-pypi-publish@v1.6.4
5959
with:
6060
password: ${{ secrets.PYPI_PASSWORD }}
6161

@@ -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 }}

.pre-commit-config.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
repos:
1212
# Autoformat: Python code, syntax patterns are modernized
1313
- repo: https://github.com/asottile/pyupgrade
14-
rev: v3.2.2
14+
rev: v3.3.1
1515
hooks:
1616
- id: pyupgrade
1717
args:
@@ -23,7 +23,7 @@ repos:
2323

2424
# Autoformat: Python code
2525
- repo: https://github.com/psf/black
26-
rev: 22.10.0
26+
rev: 22.12.0
2727
hooks:
2828
- id: black
2929
args:
@@ -36,7 +36,7 @@ repos:
3636

3737
# Autoformat: Python code
3838
- repo: https://github.com/pycqa/isort
39-
rev: 5.10.1
39+
rev: 5.11.4
4040
hooks:
4141
- id: isort
4242
args:
@@ -48,3 +48,7 @@ repos:
4848
hooks:
4949
- id: prettier
5050
files: ".md"
51+
52+
# pre-commit.ci config reference: https://pre-commit.ci/#configuration
53+
ci:
54+
autoupdate_schedule: monthly

Dockerfile

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,29 @@
11
# syntax = docker/dockerfile:1.3
22
ARG ALPINE_VERSION=3.17
3-
FROM alpine:${ALPINE_VERSION} AS builder
3+
FROM alpine:${ALPINE_VERSION}
44

55
RUN apk add --no-cache git python3 python3-dev py3-pip py3-setuptools build-base
66

7-
# set pip's cache directory using this environment variable, and use
8-
# ARG instead of ENV to ensure its only set when the image is built
9-
ARG PIP_CACHE_DIR=/tmp/pip-cache
10-
117
# build wheels in first image
128
ADD . /tmp/src
139
RUN cd /tmp/src && git clean -xfd && git status
14-
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
15-
mkdir /tmp/wheelhouse \
10+
RUN mkdir /tmp/wheelhouse \
1611
&& cd /tmp/wheelhouse \
1712
&& pip3 install wheel \
18-
&& pip3 wheel /tmp/src \
13+
&& pip3 wheel --no-cache-dir /tmp/src \
1914
&& ls -l /tmp/wheelhouse
2015

2116
FROM alpine:${ALPINE_VERSION}
2217

2318
# install python, git, bash, mercurial
2419
RUN apk add --no-cache git git-lfs python3 py3-pip py3-setuptools bash docker mercurial
2520

26-
# repeat ARG from above
27-
ARG PIP_CACHE_DIR=/tmp/pip-cache
21+
# install hg-evolve (Mercurial extensions)
22+
RUN pip3 install hg-evolve --user --no-cache-dir
2823

2924
# install repo2docker
30-
# and hg-evolve (Mercurial extensions)
31-
# mount /tmp/wheelhouse from build stage
32-
# avoids extra layer when using COPY --from
33-
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
34-
--mount=type=cache,from=builder,source=/tmp/wheelhouse,target=/tmp/wheelhouse \
35-
pip3 install --ignore-installed --no-deps /tmp/wheelhouse/*.whl \
36-
&& pip3 install hg-evolve \
25+
COPY --from=0 /tmp/wheelhouse /tmp/wheelhouse
26+
RUN pip3 install --no-cache-dir --ignore-installed --no-deps /tmp/wheelhouse/*.whl \
3727
&& pip3 list
3828

3929
# add git-credential helper

docs/source/howto/user_interface.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ http://mybinder.org/v2/gh/binder-examples/r/HEAD?urlpath=rstudio
9797
Shiny
9898
=====
9999

100-
`Shiny lets you create interactive visualizaions with R <https://shiny.rstudio.com/>`_.
100+
`Shiny lets you create interactive visualizations with R <https://shiny.rstudio.com/>`_.
101101
Shiny is automatically enabled if a configuration file for
102102
R is detected (i.e. an R version specified in ``runtime.txt``). If
103103
this is detected, Shiny will be accessible by appending

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="""
@@ -795,6 +817,7 @@ def build(self):
795817
base_image=self.base_image
796818
)
797819

820+
picked_buildpack.platform = self.platform
798821
picked_buildpack.appendix = self.appendix
799822
# Add metadata labels
800823
picked_buildpack.labels["repo2docker.version"] = self.version
@@ -836,6 +859,7 @@ def build(self):
836859
build_args,
837860
self.cache_from,
838861
self.extra_build_kwargs,
862+
platform=self.platform,
839863
):
840864
if docker_client.string_output:
841865
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
@@ -232,6 +232,7 @@ def __init__(self, base_image):
232232
"Windows environment detected. Note that Windows "
233233
"support is experimental in repo2docker."
234234
)
235+
self.platform = ""
235236

236237
def get_packages(self):
237238
"""
@@ -565,6 +566,7 @@ def build(
565566
build_args,
566567
cache_from,
567568
extra_build_kwargs,
569+
platform=None,
568570
):
569571
tarf = io.BytesIO()
570572
tar = tarfile.open(fileobj=tarf, mode="w")
@@ -619,6 +621,7 @@ def _filter_tar(tar):
619621
buildargs=build_args,
620622
container_limits=limits,
621623
cache_from=cache_from,
624+
platform=platform,
622625
)
623626

624627
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)