Skip to content

Commit a27a279

Browse files
author
Pedro Crespo
committed
WIP #198: setup for sidecar
- created setup and requirements for dev&prod - installs package in docker (instead of reference via sys.path). this way all third-parties are installed. - minor cleanup of code
1 parent bbc7cb6 commit a27a279

File tree

10 files changed

+123
-19
lines changed

10 files changed

+123
-19
lines changed

services/sidecar/Dockerfile

+35-13
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,54 @@ FROM python:3.6-alpine as common
22

33
LABEL maintainer="Manuel Guidon <[email protected]"
44

5-
WORKDIR /work/sidecar
5+
RUN apk add --no-cache \
6+
postgresql-dev \
7+
gcc \
8+
libc-dev
69

7-
RUN apk add --no-cache postgresql-dev gcc libc-dev
10+
RUN pip install --upgrade \
11+
pip \
12+
wheel \
13+
setuptools
814

9-
COPY services/sidecar/requirements.txt requirements.txt
15+
WORKDIR /work
16+
# Buil context set at repo's root
17+
COPY services/sidecar/requirements requirements
1018

11-
RUN pip install --upgrade pip \
12-
&& pip install -r requirements.txt \
13-
&& pip list --format=columns
19+
RUN pip install -r requirements/base.txt &&\
20+
rm -rf requirements
21+
22+
# Keeps same folder structure as in repo so we can reuse relative paths
23+
RUN mkdir -p /work/packages &&\
24+
mkdir -p /work/services/sidecar
1425

1526
EXPOSE 8000
1627

28+
29+
# --------------------------Development stage -------------------
1730
FROM common as development
1831

19-
VOLUME /work/sidecar
2032
VOLUME /work/packages
33+
VOLUME /work/services/sidecar
34+
WORKDIR /work/services/sidecar
35+
36+
CMD pip install -r requirements/dev.txt &&\
37+
celery -A sidecar worker -c 2 --loglevel=info
2138

22-
# NO clue why this does not work without explicitly specifying
23-
ENTRYPOINT celery -A sidecar worker -c 2 --loglevel=info
2439

40+
# --------------------------Production stage -------------------
2541
FROM common as production
2642

27-
# the context for the build is the git repo root directory
28-
COPY services/sidecar/src /work
43+
# Buil context set at repo's root
2944
COPY packages /work/packages
45+
COPY services/sidecar /work/services/sidecar
46+
47+
WORKDIR /work/services/sidecar
48+
49+
RUN pip install -r requirements/prod.txt && pip list;\
50+
rm -rf /work/packages &&\
51+
rm -rf /work/services/sidecar
52+
53+
WORKDIR /work
3054

31-
# NO clue why this does not work without explicitly specifying
32-
ENV PYTHONPATH="/work/packages/simcore-sdk/src:/work/packages/s3wrapper/src"
3355
ENTRYPOINT celery -A sidecar worker -c 2 --loglevel=info

services/sidecar/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
# Sidecar
22

33
Use sidecar container to control computational service.
4+
5+
6+
7+
```bash
8+
9+
# create an prepare a clean virtual environment ...
10+
python3 -m venv .venv
11+
source .venv/bin/activate
12+
pip3 install --upgrade pip setuptools wheel
13+
# ..or
14+
make .venv
15+
source .venv/bin/activate
16+
17+
18+
cd services/sidecar
19+
20+
# for development (edit mode)
21+
# see how this packages is listed with a path to it src/ folder
22+
pip3 install -r requirements/dev.txt
23+
pip3 list
24+
25+
26+
# for production
27+
pip3 install -r requirements/prod.txt
28+
pip3 list
29+
```

services/sidecar/requirements.txt renamed to services/sidecar/requirements/base.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Common third party packages
2+
# Please keep alphabetical order
13
celery==4.1.0
24
docker==3.3.0
35
kombu==4.1.0

services/sidecar/requirements/dev.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-e .
2+
-e ../../packages/s3wrapper/
3+
-e ../../packages/simcore-sdk/
4+
5+
6+
# extra dev tools
7+
autopep8
8+
pylint
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.
2+
../../packages/s3wrapper/
3+
../../packages/simcore-sdk/

services/sidecar/setup.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
import sys
3+
import pathlib
4+
5+
from setuptools import (
6+
find_packages,
7+
setup,
8+
)
9+
10+
_CDIR = pathlib.Path(sys.argv[0] if __name__ == "__main__" else __file__).parent
11+
_PACKAGES_DIR = _CDIR.absolute().parent.parent / "packages"
12+
13+
def list_requirements_in(filename):
14+
requires = []
15+
with (_CDIR / "requirements" / filename).open() as fh:
16+
requires = [line.strip() for line in fh.readlines() if not line.lstrip().startswith("#")]
17+
return requires
18+
19+
20+
INSTALL_REQUIRES = list_requirements_in("base.txt")
21+
22+
# FIXME: not sure how to add these dependencies *here* and *only* in production. Now using requirements/prod.txt
23+
SC_PACKAGES = [
24+
"s3wrapper",
25+
"simcore-sdk"
26+
]
27+
28+
setup(
29+
name='simcore-service-sidecar',
30+
version='0.0.1',
31+
packages=find_packages(where='src'),
32+
package_dir={
33+
'': 'src',
34+
},
35+
install_requires=INSTALL_REQUIRES,
36+
python_requires='>=3.6',
37+
)
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .core import *

services/sidecar/src/sidecar/sidecar.py renamed to services/sidecar/src/sidecar/core.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
from sqlalchemy import and_, exc
1313
from sqlalchemy.orm.attributes import flag_modified
1414

15-
from sidecar_utils import (DbSettings, DockerSettings, ExecutorSettings,
16-
RabbitSettings, S3Settings, delete_contents,
17-
find_entry_point, is_node_ready)
1815
from simcore_sdk.config.rabbit import Config as rabbit_config
1916
from simcore_sdk.models.pipeline_models import (RUNNING, SUCCESS,
2017
ComputationalPipeline,
2118
ComputationalTask)
2219

20+
from .utils import (DbSettings, DockerSettings, ExecutorSettings,
21+
RabbitSettings, S3Settings, delete_contents,
22+
find_entry_point, is_node_ready)
23+
2324
rabbit_config = rabbit_config()
2425
celery= Celery(rabbit_config.name, broker=rabbit_config.broker, backend=rabbit_config.backend)
2526

services/web/server/setup.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ def list_requirements_in(filename):
2929
setup(
3030
name='simcore-web-server',
3131
version='0.0.0',
32-
package_dir={'': 'src'},
33-
packages=find_packages('src'),
32+
packages=find_packages(where='src'),
33+
package_dir={
34+
'': 'src',
35+
},
3436
include_package_data=True,
3537
package_data={
3638
'config': ['../config/*.yaml'] #FIXME: this is still not copied!??
3739
},
3840
entry_points={
39-
'console_scripts': ['service-web-server=server.__main__:main']},
41+
'console_scripts': [
42+
'service-web-server=server.__main__:main', ]
43+
},
4044
python_requires='>=3.6',
4145
install_requires=INSTALL_REQUIRES,
4246
tests_require=TESTS_REQUIRE,

0 commit comments

Comments
 (0)