-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added renku service with cache and datasets
- Loading branch information
Showing
41 changed files
with
3,367 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
REDIS_HOST=redis | ||
REDIS_PORT=6379 | ||
REDIS_DATABASE=0 | ||
REDIS_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,3 +73,5 @@ target/ | |
renku-*.bottle.json | ||
renku-*.bottle.tar.gz | ||
renku.rb | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM python:3.7-alpine | ||
|
||
RUN apk add --update --no-cache alpine-sdk g++ gcc linux-headers libxslt-dev python3-dev build-base openssl-dev libffi-dev git bash && \ | ||
pip install --no-cache --upgrade pip setuptools pipenv requirements-builder | ||
|
||
RUN apk add --no-cache --allow-untrusted \ | ||
--repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/community \ | ||
--repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/main \ | ||
--repository http://nl.alpinelinux.org/alpine/edge/community \ | ||
git-lfs && \ | ||
git lfs install | ||
|
||
COPY . /code/renku | ||
WORKDIR /code/renku | ||
RUN requirements-builder -e all --level=pypi setup.py > requirements.txt && pip install -r requirements.txt && pip install -e . && pip install gunicorn | ||
|
||
|
||
ENTRYPOINT ["gunicorn", "renku.service.entrypoint:app", "-b", "0.0.0.0:8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,10 @@ | |
import tempfile | ||
import time | ||
import urllib | ||
import uuid | ||
from pathlib import Path | ||
|
||
import fakeredis | ||
import pytest | ||
import responses | ||
import yaml | ||
|
@@ -510,3 +512,176 @@ def remote_project(data_repository, directory_tree): | |
assert 0 == result.exit_code | ||
|
||
yield runner, project_path | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def dummy_datapack(): | ||
"""Creates dummy data folder.""" | ||
temp_dir = tempfile.TemporaryDirectory() | ||
|
||
data_file_txt = Path(temp_dir.name) / Path('file.txt') | ||
data_file_txt.write_text('my awesome data') | ||
|
||
data_file_csv = Path(temp_dir.name) / Path('file.csv') | ||
data_file_csv.write_text('more,awesome,data') | ||
|
||
yield temp_dir | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def datapack_zip(dummy_datapack): | ||
"""Returns dummy data folder as a zip archive.""" | ||
from renku.core.utils.contexts import chdir | ||
workspace_dir = tempfile.TemporaryDirectory() | ||
with chdir(workspace_dir.name): | ||
shutil.make_archive('datapack', 'zip', dummy_datapack.name) | ||
|
||
yield Path(workspace_dir.name) / 'datapack.zip' | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def datapack_tar(dummy_datapack): | ||
"""Returns dummy data folder as a tar archive.""" | ||
from renku.core.utils.contexts import chdir | ||
workspace_dir = tempfile.TemporaryDirectory() | ||
with chdir(workspace_dir.name): | ||
shutil.make_archive('datapack', 'tar', dummy_datapack.name) | ||
|
||
yield Path(workspace_dir.name) / 'datapack.tar' | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def mock_redis(monkeypatch): | ||
"""Monkey patch service cache with mocked redis.""" | ||
from renku.service.cache import ServiceCache | ||
with monkeypatch.context() as m: | ||
m.setattr(ServiceCache, 'cache', fakeredis.FakeRedis()) | ||
yield | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def svc_client(mock_redis): | ||
"""Renku service client.""" | ||
from renku.service.entrypoint import create_app | ||
|
||
flask_app = create_app() | ||
|
||
testing_client = flask_app.test_client() | ||
testing_client.testing = True | ||
|
||
ctx = flask_app.app_context() | ||
ctx.push() | ||
|
||
yield testing_client | ||
|
||
ctx.pop() | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def svc_client_with_repo(svc_client, mock_redis): | ||
"""Renku service remote repository.""" | ||
remote_url = 'https://dev.renku.ch/gitlab/contact/integration-tests' | ||
headers = { | ||
'Content-Type': 'application/json', | ||
'Renku-User-Id': 'b4b4de0eda0f471ab82702bd5c367fa7', | ||
'Renku-User-FullName': 'Just Sam', | ||
'Renku-User-Email': '[email protected]', | ||
'Authorization': 'Bearer LkoLiyLqnhMCAa4or5qa', | ||
} | ||
|
||
payload = {'git_url': remote_url} | ||
|
||
response = svc_client.post( | ||
'/cache/project-clone', | ||
data=json.dumps(payload), | ||
headers=headers, | ||
) | ||
|
||
assert response | ||
assert 'result' in response.json | ||
assert 'error' not in response.json | ||
project_id = response.json['result']['project_id'] | ||
assert isinstance(uuid.UUID(project_id), uuid.UUID) | ||
|
||
yield svc_client, headers, project_id | ||
|
||
|
||
@pytest.fixture( | ||
params=[ | ||
{ | ||
'url': '/cache/files-list', | ||
'allowed_method': 'GET', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
{ | ||
'url': '/cache/files-upload', | ||
'allowed_method': 'POST', | ||
'headers': {} | ||
}, | ||
{ | ||
'url': '/cache/project-clone', | ||
'allowed_method': 'POST', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
{ | ||
'url': '/cache/project-list', | ||
'allowed_method': 'GET', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
{ | ||
'url': '/datasets/add', | ||
'allowed_method': 'POST', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
{ | ||
'url': '/datasets/create', | ||
'allowed_method': 'POST', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
{ | ||
'url': '/datasets/files-list', | ||
'allowed_method': 'GET', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
{ | ||
'url': '/datasets/list', | ||
'allowed_method': 'GET', | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
'accept': 'application/json', | ||
} | ||
}, | ||
] | ||
) | ||
def service_allowed_endpoint(request, svc_client, mock_redis): | ||
"""Ensure allowed methods and correct headers.""" | ||
methods = { | ||
'GET': svc_client.get, | ||
'POST': svc_client.post, | ||
'HEAD': svc_client.head, | ||
'PUT': svc_client.put, | ||
'DELETE': svc_client.delete, | ||
'OPTIONS': svc_client.options, | ||
'TRACE': svc_client.trace, | ||
'PATCH': svc_client.patch, | ||
} | ||
|
||
yield methods, request.param, svc_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3' | ||
|
||
services: | ||
redis: | ||
image: redis:5.0.3-alpine | ||
ports: | ||
- "6379:6379" | ||
|
||
renku-svc: | ||
image: renku-svc:latest | ||
env_file: .env | ||
ports: | ||
- "8080:8080" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.