Skip to content

Commit 3c2bc8d

Browse files
committed
feat: added renku service with cache and datasets
1 parent 6084c87 commit 3c2bc8d

File tree

22 files changed

+1930
-83
lines changed

22 files changed

+1930
-83
lines changed

Dockerfile renamed to Dockerfile.cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.6-alpine as base
1+
FROM python:3.7-alpine as base
22

33
RUN apk add --no-cache git && \
44
pip install --no-cache --upgrade pip

Dockerfile.svc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.7-alpine
2+
3+
RUN apk add --update --no-cache alpine-sdk g++ gcc linux-headers libxslt-dev python3-dev build-base openssl-dev libffi-dev git && \
4+
pip install --no-cache --upgrade pip setuptools pipenv requirements-builder
5+
6+
RUN apk add --no-cache --allow-untrusted \
7+
--repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/community \
8+
--repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/main \
9+
--repository http://nl.alpinelinux.org/alpine/edge/community \
10+
git-lfs && \
11+
git lfs install
12+
13+
COPY . /code/renku
14+
WORKDIR /code/renku
15+
RUN requirements-builder -e all --level=pypi setup.py > requirements.txt && pip install -r requirements.txt && pip install -e . && pip install gunicorn
16+
17+
18+
ENTRYPOINT ["gunicorn", "renku.service.entrypoint:app", "-b", "0.0.0.0:8080"]

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ include babel.ini
3939
include brew.py
4040
include pytest.ini
4141
include snap/snapcraft.yaml
42+
recursive-include renku *.json
4243
recursive-include .github CODEOWNERS
4344
recursive-include .travis *.sh
4445
recursive-include docs *.bat

Pipfile.lock

Lines changed: 124 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conftest.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import responses
3131
from click.testing import CliRunner
3232

33+
from renku.service.entrypoint import create_app
34+
3335

3436
@pytest.fixture(scope='module')
3537
def renku_path(tmpdir_factory):
@@ -474,3 +476,40 @@ def sleep_after():
474476
import time
475477
yield
476478
time.sleep(0.5)
479+
480+
481+
@pytest.fixture(scope='module')
482+
def svc_client():
483+
"""Renku service client."""
484+
flask_app = create_app()
485+
486+
testing_client = flask_app.test_client()
487+
testing_client.testing = True
488+
489+
ctx = flask_app.app_context()
490+
ctx.push()
491+
492+
yield testing_client
493+
494+
ctx.pop()
495+
496+
497+
@pytest.fixture(scope='function')
498+
def svc_client_with_repo(svc_client):
499+
"""Renku service remote repository."""
500+
access_token = 'contact:EcfPJvEqjJepyu6XyqKZ'
501+
remote_url = 'https://{0}@renkulab.io/gitlab/contact/integration-tests.git'
502+
headers = {'Authorization': 'Bearer b4b4de0eda0f471ab82702bd5c367fa7'}
503+
504+
params = {'git_url': remote_url.format(access_token), 'force': 1}
505+
506+
response = svc_client.get(
507+
'/cache/project-clone', query_string=params, headers=headers
508+
)
509+
510+
assert response
511+
assert 'result' in response.json
512+
assert 'error' not in response.json
513+
assert 'integration-tests' == response.json['result']['project_id']
514+
515+
yield svc_client, headers

renku/core/commands/client.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import yaml
2626

2727
from renku.core.management import LocalClient
28+
from renku.core.management.config import RENKU_HOME
29+
from renku.core.management.repository import default_path
2830

2931
from .git import get_git_isolation
3032

@@ -63,8 +65,17 @@ def pass_local_client(
6365
)
6466

6567
def new_func(*args, **kwargs):
66-
ctx = click.get_current_context()
67-
client = ctx.ensure_object(LocalClient)
68+
ctx = click.get_current_context(silent=True)
69+
if not ctx:
70+
client = LocalClient(
71+
path=default_path(),
72+
renku_home=RENKU_HOME,
73+
use_external_storage=True,
74+
)
75+
ctx = click.Context(click.Command(method))
76+
else:
77+
client = ctx.ensure_object(LocalClient)
78+
6879
stack = contextlib.ExitStack()
6980

7081
# Handle --isolation option:
@@ -85,8 +96,11 @@ def new_func(*args, **kwargs):
8596
if lock or (lock is None and commit):
8697
stack.enter_context(client.lock)
8798

88-
with stack:
89-
result = ctx.invoke(method, client, *args, **kwargs)
99+
result = None
100+
if ctx:
101+
with stack:
102+
result = ctx.invoke(method, client, *args, **kwargs)
103+
90104
return result
91105

92106
return functools.update_wrapper(new_func, method)

renku/core/commands/dataset.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def create_dataset(client, name, handle_duplicate_fn=None):
106106
:raises: ``renku.core.errors.ParameterError``
107107
"""
108108
existing = client.load_dataset(name=name)
109-
if (not existing or handle_duplicate_fn and handle_duplicate_fn(existing)):
109+
if not existing or handle_duplicate_fn and handle_duplicate_fn(existing):
110110
with client.with_dataset(name=name) as dataset:
111111
creator = Creator.from_git(client.repo)
112112
if creator not in dataset.creator:
@@ -143,9 +143,12 @@ def add_file(
143143
sources=(),
144144
destination='',
145145
with_metadata=None,
146-
urlscontext=contextlib.nullcontext
146+
urlscontext=contextlib.nullcontext,
147+
use_external_storage=True
147148
):
148149
"""Add data file to a dataset."""
150+
client.use_external_storage = use_external_storage
151+
149152
add_to_dataset(
150153
client, urls, name, link, force, sources, destination, with_metadata,
151154
urlscontext

renku/core/management/datasets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ def _add_from_url(self, dataset, dataset_path, url, link, destination):
296296
mode = dst.stat().st_mode & 0o777
297297
dst.chmod(mode & ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
298298

299-
self.track_paths_in_storage(str(dst.relative_to(self.path)))
299+
if self.has_external_storage:
300+
self.track_paths_in_storage(str(dst.relative_to(self.path)))
300301

301302
return [{
302303
'path': dst.relative_to(self.path),

renku/core/management/repository.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ def default_path():
4747
return '.'
4848

4949

50+
def path_converter(path):
51+
"""Converter for path in PathMixin."""
52+
return Path(path).resolve()
53+
54+
5055
@attr.s
5156
class PathMixin:
5257
"""Define a default path attribute."""
5358

5459
path = attr.ib(
5560
default=default_path,
56-
converter=lambda arg: Path(arg).resolve().absolute(),
61+
converter=path_converter,
5762
)
5863

5964
@path.validator

renku/service/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM python:3.6
2+
ADD . /app
3+
WORKDIR /app
4+
RUN pip install -e .
5+
EXPOSE 8000
6+
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app"]

0 commit comments

Comments
 (0)