Skip to content

Commit 84408ef

Browse files
authored
Merge pull request #976 from bollwyvl/add-target-repo-dir-perms
Allow REPO_DIR to be a non-existing folder by creating it and providing the user with permissions
2 parents be7fc8a + 2f13af8 commit 84408ef

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

repo2docker/buildpacks/base.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
2828
locale-gen
2929
30-
ENV LC_ALL en_US.UTF-8
31-
ENV LANG en_US.UTF-8
32-
ENV LANGUAGE en_US.UTF-8
30+
ENV LC_ALL=en_US.UTF-8 \
31+
LANG=en_US.UTF-8 \
32+
LANGUAGE=en_US.UTF-8
3333
3434
# Use bash as default shell, rather than sh
35-
ENV SHELL /bin/bash
35+
ENV SHELL=/bin/bash
3636
3737
# Set up user
3838
ARG NB_USER
3939
ARG NB_UID
40-
ENV USER ${NB_USER}
41-
ENV HOME /home/${NB_USER}
40+
ENV USER=${NB_USER} \
41+
HOME=/home/${NB_USER}
4242
4343
RUN groupadd \
4444
--gid ${NB_UID} \
@@ -81,13 +81,13 @@
8181
{% if build_env -%}
8282
# Environment variables required for build
8383
{% for item in build_env -%}
84-
ENV {{item[0]}} {{item[1]}}
84+
ENV {{item[0]}}={{item[1]}}
8585
{% endfor -%}
8686
{% endif -%}
8787
8888
{% if path -%}
8989
# Special case PATH
90-
ENV PATH {{ ':'.join(path) }}:${PATH}
90+
ENV PATH={{ ':'.join(path) }}:${PATH}
9191
{% endif -%}
9292
9393
{% if build_script_files -%}
@@ -105,7 +105,12 @@
105105
106106
# Allow target path repo is cloned to be configurable
107107
ARG REPO_DIR=${HOME}
108-
ENV REPO_DIR ${REPO_DIR}
108+
ENV REPO_DIR=${REPO_DIR}
109+
# Create a folder and grant the user permissions if it doesn't exist
110+
RUN if [ ! -d "${REPO_DIR}" ]; then \
111+
/usr/bin/install -o ${NB_USER} -g ${NB_USER} -d "${REPO_DIR}"; \
112+
fi
113+
109114
WORKDIR ${REPO_DIR}
110115
RUN chown ${NB_USER}:${NB_USER} ${REPO_DIR}
111116
@@ -117,12 +122,12 @@
117122
#
118123
# The XDG standard suggests ~/.local/bin as the path for local user-specific
119124
# installs. See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
120-
ENV PATH ${HOME}/.local/bin:${REPO_DIR}/.local/bin:${PATH}
125+
ENV PATH=${HOME}/.local/bin:${REPO_DIR}/.local/bin:${PATH}
121126
122127
{% if env -%}
123128
# The rest of the environment
124129
{% for item in env -%}
125-
ENV {{item[0]}} {{item[1]}}
130+
ENV {{item[0]}}={{item[1]}}
126131
{% endfor -%}
127132
{% endif -%}
128133
@@ -144,7 +149,7 @@
144149
USER root
145150
146151
# Copy stuff.
147-
COPY --chown={{ user }}:{{ user }} src/ ${REPO_DIR}
152+
COPY --chown={{ user }}:{{ user }} src/ ${REPO_DIR}/
148153
149154
# Run assemble scripts! These will actually turn the specification
150155
# in the repository into an image.
@@ -173,7 +178,7 @@
173178
# Add start script
174179
{% if start_script is not none -%}
175180
RUN chmod +x "{{ start_script }}"
176-
ENV R2D_ENTRYPOINT "{{ start_script }}"
181+
ENV R2D_ENTRYPOINT="{{ start_script }}"
177182
{% endif -%}
178183
179184
# Add entrypoint

tests/conda/r3.6-target-repo-dir-flag/verify.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import sys
33
import os
4+
from glob import glob
45

56
# conda should still be in /srv/conda
67
# and Python should still be in $NB_PYTHON_PREFIX
@@ -15,3 +16,12 @@
1516

1617
# Repo should be writable
1718
assert os.access("/srv/repo", os.W_OK)
19+
20+
# All files in repo dir should be readable and writeable
21+
for path in glob("/src/repo/**/*", recursive=True):
22+
assert os.access(path, os.R_OK)
23+
assert os.access(path, os.W_OK)
24+
25+
# Should be able to make a new file
26+
with open("/srv/repo/writeable", "w") as fp:
27+
fp.write("writeable")

tests/conftest.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
"""
22
Custom test collector for our integration tests.
33
4-
Each directory that has a script named 'verify' is considered
5-
a test. jupyter-repo2docker is run on that directory,
6-
and then ./verify is run inside the built container. It should
7-
return a non-zero exit code for the test to be considered a
8-
success.
4+
5+
Test lifecycle:
6+
- Find all directories that contain `verify` or `*.repos.yaml`
7+
- If `verify` is found:
8+
- Run `jupyter-repo2docker` on the test directory.
9+
- Extra arguments may be added as YAML list of strings in `extra-args.yaml`.
10+
- Run `./verify` inside the built container.
11+
- It should return a non-zero exit code for the test to be considered a
12+
successful.
13+
- If a `*.repos.yaml` is found:
14+
- For each entry of the form `{name, url, ref, verify}`
15+
- Run `jupyter-repo2docker` with the `url` and `ref`
16+
- Run the `verify` inside the built container
917
"""
1018

1119
import os

0 commit comments

Comments
 (0)