Skip to content

Commit d339e66

Browse files
committed
feat: added renku service with cache and datasets
1 parent f11edf2 commit d339e66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3367
-189
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REDIS_HOST=redis
2+
REDIS_PORT=6379
3+
REDIS_DATABASE=0
4+
REDIS_PASSWORD=

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ target/
7373
renku-*.bottle.json
7474
renku-*.bottle.tar.gz
7575
renku.rb
76+
77+
.env

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ before_install:
6060
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
6161
sudo apt-get update;
6262
sudo apt-get -y install shellcheck;
63-
travis_retry python -m pip install --upgrade pip setuptools py;
63+
travis_retry python -m pip install --upgrade six pip setuptools py;
6464
travis_retry python -m pip install twine wheel coveralls requirements-builder;
6565
requirements-builder -e all --level=min setup.py > .travis-lowest-requirements.txt;
6666
requirements-builder -e all --level=pypi setup.py > .travis-release-requirements.txt;

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 bash && \
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
# limitations under the License.
1818

1919
# Check manifest will not automatically add these two files:
20+
include renku/service/.env-example
2021
include .dockerignore
2122
include .editorconfig
2223
include .tx/config
2324
include *.md
2425
prune docs/_build
2526
recursive-include renku *.po *.pot *.mo
26-
27+
recursive-include renku *.py
2728
# added by check_manifest.py
2829
include *.py
30+
include *.yml
2931
include *.rst
3032
include *.sh
3133
include *.txt
@@ -39,6 +41,7 @@ include babel.ini
3941
include brew.py
4042
include pytest.ini
4143
include snap/snapcraft.yaml
44+
recursive-include renku *.json
4245
recursive-include .github CODEOWNERS
4346
recursive-include .travis *.sh
4447
recursive-include docs *.bat
@@ -60,3 +63,4 @@ recursive-include renku *.json
6063
recursive-include renku Dockerfile
6164
recursive-include tests *.py *.gz *.yml *.json
6265
prune .github
66+
prune .env

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ brew-commit-bottle: *.bottle.json
6969

7070
brew-release:
7171
open "https://github.com/SwissDataScienceCenter/renku-python/releases/new?tag=v$(shell brew info --json=v1 renku | jq -r '.[0].versions.stable')"
72+
73+
service-container:
74+
docker build -f Dockerfile.svc -t renku-svc:`git rev-parse --short HEAD` .

Pipfile.lock

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

conftest.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import tempfile
2626
import time
2727
import urllib
28+
import uuid
2829
from pathlib import Path
2930

31+
import fakeredis
3032
import pytest
3133
import responses
3234
import yaml
@@ -510,3 +512,176 @@ def remote_project(data_repository, directory_tree):
510512
assert 0 == result.exit_code
511513

512514
yield runner, project_path
515+
516+
517+
@pytest.fixture(scope='function')
518+
def dummy_datapack():
519+
"""Creates dummy data folder."""
520+
temp_dir = tempfile.TemporaryDirectory()
521+
522+
data_file_txt = Path(temp_dir.name) / Path('file.txt')
523+
data_file_txt.write_text('my awesome data')
524+
525+
data_file_csv = Path(temp_dir.name) / Path('file.csv')
526+
data_file_csv.write_text('more,awesome,data')
527+
528+
yield temp_dir
529+
530+
531+
@pytest.fixture(scope='function')
532+
def datapack_zip(dummy_datapack):
533+
"""Returns dummy data folder as a zip archive."""
534+
from renku.core.utils.contexts import chdir
535+
workspace_dir = tempfile.TemporaryDirectory()
536+
with chdir(workspace_dir.name):
537+
shutil.make_archive('datapack', 'zip', dummy_datapack.name)
538+
539+
yield Path(workspace_dir.name) / 'datapack.zip'
540+
541+
542+
@pytest.fixture(scope='function')
543+
def datapack_tar(dummy_datapack):
544+
"""Returns dummy data folder as a tar archive."""
545+
from renku.core.utils.contexts import chdir
546+
workspace_dir = tempfile.TemporaryDirectory()
547+
with chdir(workspace_dir.name):
548+
shutil.make_archive('datapack', 'tar', dummy_datapack.name)
549+
550+
yield Path(workspace_dir.name) / 'datapack.tar'
551+
552+
553+
@pytest.fixture(scope='function')
554+
def mock_redis(monkeypatch):
555+
"""Monkey patch service cache with mocked redis."""
556+
from renku.service.cache import ServiceCache
557+
with monkeypatch.context() as m:
558+
m.setattr(ServiceCache, 'cache', fakeredis.FakeRedis())
559+
yield
560+
561+
562+
@pytest.fixture(scope='function')
563+
def svc_client(mock_redis):
564+
"""Renku service client."""
565+
from renku.service.entrypoint import create_app
566+
567+
flask_app = create_app()
568+
569+
testing_client = flask_app.test_client()
570+
testing_client.testing = True
571+
572+
ctx = flask_app.app_context()
573+
ctx.push()
574+
575+
yield testing_client
576+
577+
ctx.pop()
578+
579+
580+
@pytest.fixture(scope='function')
581+
def svc_client_with_repo(svc_client, mock_redis):
582+
"""Renku service remote repository."""
583+
remote_url = 'https://dev.renku.ch/gitlab/contact/integration-tests'
584+
headers = {
585+
'Content-Type': 'application/json',
586+
'Renku-User-Id': 'b4b4de0eda0f471ab82702bd5c367fa7',
587+
'Renku-User-FullName': 'Just Sam',
588+
'Renku-User-Email': '[email protected]',
589+
'Authorization': 'Bearer LkoLiyLqnhMCAa4or5qa',
590+
}
591+
592+
payload = {'git_url': remote_url}
593+
594+
response = svc_client.post(
595+
'/cache/project-clone',
596+
data=json.dumps(payload),
597+
headers=headers,
598+
)
599+
600+
assert response
601+
assert 'result' in response.json
602+
assert 'error' not in response.json
603+
project_id = response.json['result']['project_id']
604+
assert isinstance(uuid.UUID(project_id), uuid.UUID)
605+
606+
yield svc_client, headers, project_id
607+
608+
609+
@pytest.fixture(
610+
params=[
611+
{
612+
'url': '/cache/files-list',
613+
'allowed_method': 'GET',
614+
'headers': {
615+
'Content-Type': 'application/json',
616+
'accept': 'application/json',
617+
}
618+
},
619+
{
620+
'url': '/cache/files-upload',
621+
'allowed_method': 'POST',
622+
'headers': {}
623+
},
624+
{
625+
'url': '/cache/project-clone',
626+
'allowed_method': 'POST',
627+
'headers': {
628+
'Content-Type': 'application/json',
629+
'accept': 'application/json',
630+
}
631+
},
632+
{
633+
'url': '/cache/project-list',
634+
'allowed_method': 'GET',
635+
'headers': {
636+
'Content-Type': 'application/json',
637+
'accept': 'application/json',
638+
}
639+
},
640+
{
641+
'url': '/datasets/add',
642+
'allowed_method': 'POST',
643+
'headers': {
644+
'Content-Type': 'application/json',
645+
'accept': 'application/json',
646+
}
647+
},
648+
{
649+
'url': '/datasets/create',
650+
'allowed_method': 'POST',
651+
'headers': {
652+
'Content-Type': 'application/json',
653+
'accept': 'application/json',
654+
}
655+
},
656+
{
657+
'url': '/datasets/files-list',
658+
'allowed_method': 'GET',
659+
'headers': {
660+
'Content-Type': 'application/json',
661+
'accept': 'application/json',
662+
}
663+
},
664+
{
665+
'url': '/datasets/list',
666+
'allowed_method': 'GET',
667+
'headers': {
668+
'Content-Type': 'application/json',
669+
'accept': 'application/json',
670+
}
671+
},
672+
]
673+
)
674+
def service_allowed_endpoint(request, svc_client, mock_redis):
675+
"""Ensure allowed methods and correct headers."""
676+
methods = {
677+
'GET': svc_client.get,
678+
'POST': svc_client.post,
679+
'HEAD': svc_client.head,
680+
'PUT': svc_client.put,
681+
'DELETE': svc_client.delete,
682+
'OPTIONS': svc_client.options,
683+
'TRACE': svc_client.trace,
684+
'PATCH': svc_client.patch,
685+
}
686+
687+
yield methods, request.param, svc_client

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3'
2+
3+
services:
4+
redis:
5+
image: redis:5.0.3-alpine
6+
ports:
7+
- "6379:6379"
8+
9+
renku-svc:
10+
image: renku-svc:latest
11+
env_file: .env
12+
ports:
13+
- "8080:8080"

0 commit comments

Comments
 (0)