Skip to content

Commit 9ef6b02

Browse files
author
Pedro Crespo
committed
Squashed commit of PR ITISFoundation#199 with the following:
commit 0df033b Author: Pedro Crespo <[email protected]> Date: Thu Aug 30 14:21:44 2018 +0200 Review feedback: removed unnecessary config sections commit bab7831 Author: Pedro Crespo <[email protected]> Date: Thu Aug 30 13:59:07 2018 +0200 Fixes missing dlls commit c0bc7d6 Author: Pedro Crespo <[email protected]> Date: Thu Aug 30 11:53:41 2018 +0200 Fixes access to docker socket: - cleanup Dockerfile - minor doc and logs commit 5b6f4c7 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 17:47:13 2018 +0200 Minor cleanup and doc commit 43f7305 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 15:52:30 2018 +0200 Minor change in web server commit 7f07022 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 15:52:16 2018 +0200 sidecar: starts as root (via entrypoint) but runs as scu (non-root) commit 90359c4 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 15:51:32 2018 +0200 Fixes sidecar: temporary fix to connection to other services commit 7619671 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 15:44:42 2018 +0200 Fixes host in server running inside a docker commit bdbf078 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 15:43:56 2018 +0200 Separating maintenance services commit 83e492d Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 13:46:55 2018 +0200 Fixes on web server: - removed usused cs_s4l from config - added env for rabbit commit 8fee402 Author: Pedro Crespo <[email protected]> Date: Wed Aug 29 11:48:46 2018 +0200 Fixes on webserver: - Tmp solution for production target based on production-build stage - Normalized naming of package and console script commit a5d8220 Author: Pedro Crespo <[email protected]> Date: Tue Aug 28 22:06:59 2018 +0200 Implements entry in ITISFoundation#186: - upgrades Dockerfile with .venv and pip installing 3rd parties commit 3c55bf3 Author: Pedro Crespo <[email protected]> Date: Tue Aug 28 18:46:57 2018 +0200 Setting up boot for web service and forgot configs commit 8003744 Author: Pedro Crespo <[email protected]> Date: Tue Aug 28 18:40:12 2018 +0200 Adding config data and retreiving it as resource commit 94de3d7 Author: Pedro Crespo <[email protected]> Date: Tue Aug 28 10:58:02 2018 +0200 Minor changes in docker after discussion with MaG commit e663a1e Author: Pedro Crespo <[email protected]> Date: Mon Aug 27 22:08:38 2018 +0200 Updated ownership commit bf486b3 Author: Pedro Crespo <[email protected]> Date: Mon Aug 27 21:53:12 2018 +0200 Fixes linting errors and added notes commit 752c7bf Author: Pedro Crespo <[email protected]> Date: Mon Aug 27 19:49:39 2018 +0200 WIP ITISFoundation#198: non-root user - all volumes bound to /home/scu - All modules pip installed (in dev w/ edit mode). - All files produce in dev mode on bound volumes are not deletable - Production stage is further optimized by taking only venv from base - Fixes sidecar access to input/output/log volumes commit ec755bc Author: Pedro Crespo <[email protected]> Date: Fri Aug 24 21:53:13 2018 +0200 WIP ITISFoundation#198: - added a boot.sh script to start celery worker - restructured package submodules. Otherwise got error (see comments in ITISFoundation#198) - commit 9bbfbde Author: Pedro Crespo <[email protected]> Date: Fri Aug 24 21:52:12 2018 +0200 Minor update commit 53c7707 Author: Pedro Crespo <[email protected]> Date: Fri Aug 24 20:29:26 2018 +0200 Fixes import failure of trafaret and updages vs sqalquemy commit a27a279 Author: Pedro Crespo <[email protected]> Date: Fri Aug 24 20:24:49 2018 +0200 WIP ITISFoundation#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 commit bbc7cb6 Author: Pedro Crespo <[email protected]> Date: Fri Aug 24 20:22:31 2018 +0200 Minor: sync req versions
1 parent f67f3a7 commit 9ef6b02

Some content is hidden

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

44 files changed

+1060
-251
lines changed

.env-devel

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# NOTE: write here host gid and docker gid.
2+
HOST_GID=1000
3+
DOCKER_GID=1001
4+
#--------
15
POSTGRES_ENDPOINT=postgres:5432
26
POSTGRES_USER=simcore
37
POSTGRES_PASSWORD=simcore

.github/CODEOWNERS

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# files and folders recursively
44
/docs/ @pcrespov
5-
/services/web/client @odeimaiz
6-
/services/web/server @pcrespov
7-
/services/modeling @sanderegg
85
/services/authentication @pcrespov
96
/services/computation @mguidon
7+
/services/dy* @sanderegg
8+
/services/sidecar @pcrespov, @mguidon
9+
/services/web/client @odeimaiz
10+
/services/web/server @pcrespov
1011

1112
# any change in travis
1213
/.travis.yml @odeimaiz

packages/simcore-sdk/setup.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from setuptools import setup
1+
from setuptools import (
2+
setup,
3+
find_packages
4+
)
25

36
INSTALL_REQUIRES = [
47
'networkx==2.1',
58
'psycopg2==2.7.4',
6-
'sqlalchemy==1.2.8',
7-
'tenacity==4.12.0'
9+
'sqlalchemy==1.2.9',
10+
'tenacity==4.12.0',
811
'trafaret-config==2.0.1'
912
]
1013

@@ -21,11 +24,13 @@
2124
setup(
2225
name='simcore-sdk',
2326
version='0.1.0',
24-
package_dir={'': 'src'},
25-
packages=['simcore_sdk'],
27+
packages=find_packages(where='src'),
28+
package_dir={
29+
'': 'src',
30+
},
2631
python_requires='>=3.6',
27-
INSTALL_REQUIRES=INSTALL_REQUIRES,
28-
TEST_REQUIRE=TEST_REQUIRE,
32+
install_requires=INSTALL_REQUIRES,
33+
tests_require=TEST_REQUIRE,
2934
extras_require= {
3035
'test': TEST_REQUIRE
3136
},

services/docker-compose.devel.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ services:
1818
webserver:
1919
image: services_webserver:dev
2020
build:
21+
args:
22+
- HOST_GID_ARG=${HOST_GID:?Undefined host gid}
2123
target: development
2224
volumes:
23-
- ./web/server:/home/scu/server
24-
- ./web/client/source-output:/home/scu/client
25+
- ./web/server:/home/scu/services/web/server
26+
- ./web/client/source-output:/home/scu/services/web/client
2527
- ../packages:/home/scu/packages
2628
depends_on:
2729
- webclient
2830
#--------------------------------------------------------------------
2931
sidecar:
3032
image: services_sidecar:dev
3133
build:
34+
args:
35+
- HOST_GID_ARG=${HOST_GID:?Undefined host gid}
3236
target: development
3337
volumes:
34-
- ./sidecar/src/sidecar:/work/sidecar
35-
- ../packages:/work/packages
38+
- ./sidecar:/home/scu/services/sidecar
39+
- ../packages:/home/scu/packages

services/docker-compose.swarm.yml.template

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ services:
8787
- S3_SECRET_KEY=<enter secret key>
8888
- S3_BUCKET_NAME=simcore
8989
volumes:
90-
- input:/input
91-
- output:/output
92-
- log:/log
90+
- input:/home/scu/input
91+
- output:/home/scu/output
92+
- log:/home/scu/log
9393
- /var/run/docker.sock:/var/run/docker.sock
9494
ports:
9595
- "8000:8000"

services/docker-compose.tools.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3.4'
2+
services:
3+
# Maintenance services
4+
#--------------------------------------------------------------------
5+
flower:
6+
image: ondrejit/flower:latest
7+
command: --broker=amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@rabbit:5672
8+
ports:
9+
- 5555:5555
10+
depends_on:
11+
- rabbit
12+
#--------------------------------------------------------------------
13+
adminer:
14+
image: adminer
15+
ports:
16+
- 18080:8080
17+
depends_on:
18+
- postgres
19+
#--------------------------------------------------------------------

services/docker-compose.yml

+12-24
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,24 @@ services:
3636
build:
3737
context: ../
3838
dockerfile: services/web/Dockerfile
39-
target: ci
39+
target: production
4040
ports:
4141
- '9081:8080'
4242
environment:
4343
- DIRECTOR_HOST=director
4444
- DIRECTOR_PORT=8001
45+
- POSTGRES_ENDPOINT=${POSTGRES_ENDPOINT}
46+
- POSTGRES_USER=${POSTGRES_USER}
47+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
48+
- POSTGRES_DB=${POSTGRES_DB}
4549
- RABBITMQ_USER=${RABBITMQ_USER}
4650
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
51+
- RABBITMQ_PROGRESS_CHANNEL=${RABBITMQ_PROGRESS_CHANNEL}
52+
- RABBITMQ_LOG_CHANNEL=${RABBITMQ_LOG_CHANNEL}
4753
- S3_ENDPOINT=${S3_ENDPOINT}
4854
- S3_ACCESS_KEY=${S3_ACCESS_KEY}
4955
- S3_SECRET_KEY=${S3_SECRET_KEY}
5056
- S3_BUCKET_NAME=${S3_BUCKET_NAME}
51-
- POSTGRES_ENDPOINT=${POSTGRES_ENDPOINT}
52-
- POSTGRES_USER=${POSTGRES_USER}
53-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
54-
- POSTGRES_DB=${POSTGRES_DB}
5557
depends_on:
5658
- webclient
5759
#--------------------------------------------------------------------
@@ -63,14 +65,6 @@ services:
6365
ports:
6466
- "15672:15672"
6567
#--------------------------------------------------------------------
66-
# flower:
67-
# image: ondrejit/flower:latest
68-
# command: --broker=amqp://${RABBITMQ_USER}:${RABBITMQ_PASSWORD}@rabbit:5672
69-
# ports:
70-
# - 5555:5555
71-
# depends_on:
72-
# - rabbit
73-
#--------------------------------------------------------------------
7468
postgres:
7569
image: postgres:10
7670
environment:
@@ -82,29 +76,23 @@ services:
8276
ports:
8377
- "5432:5432"
8478
#--------------------------------------------------------------------
85-
adminer:
86-
image: adminer
87-
ports:
88-
- 18080:8080
89-
depends_on:
90-
- postgres
91-
#--------------------------------------------------------------------
9279
sidecar:
9380
build:
9481
# the context for the build is the git repo root directory, this allows to copy
9582
# the packages directory into any docker image
9683
context: ../
9784
dockerfile: services/sidecar/Dockerfile
85+
args:
86+
- DOCKER_GID_ARG=${DOCKER_GID:?Undefined docker gid in host}
9887
target: production
9988
volumes:
100-
- input:/input
101-
- output:/output
102-
- log:/log
89+
- input:/home/scu/input
90+
- output:/home/scu/output
91+
- log:/home/scu/log
10392
- /var/run/docker.sock:/var/run/docker.sock
10493
ports:
10594
- "8000:8000"
10695
environment:
107-
- PYTHONPATH=/work/packages/simcore-sdk/src:/work/packages/s3wrapper/src
10896
- RABBITMQ_USER=${RABBITMQ_USER}
10997
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
11098
- POSTGRES_ENDPOINT=${POSTGRES_ENDPOINT}

services/dy-2Dgraph/use-cases/kember/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ networkx==2.1
55
pandas==0.22.0
66
plotly==2.6.0
77
psycopg2-binary==2.7.4
8-
sqlalchemy==1.2.8
9-
tenacity==4.12.0
8+
sqlalchemy==1.2.9
9+
tenacity==4.12.0
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
minio==4.0.0
22
networkx==2.1
33
psycopg2-binary==2.7.4
4-
sqlalchemy==1.2.8
4+
sqlalchemy==1.2.9
55
tenacity==4.12.0
6-
docker==3.3.0
6+
docker==3.3.0
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
# This entrypoint script:
4+
#
5+
# - Executes with root privileges *inside* of the container upon start
6+
# - Allows starting the container as root to perform some root-level operations at runtime
7+
# (e.g. on volumes mapped inside)
8+
# - Notice that this way, the container *starts* as root but *runs* as scu (non-root user)
9+
#
10+
# See https://stackoverflow.com/questions/39397548/how-to-give-non-root-user-in-docker-container-access-to-a-volume-mounted-on-the
11+
12+
13+
addgroup scu docker
14+
15+
chown -R scu:scu /home/scu/input
16+
chown -R scu:scu /home/scu/output
17+
chown -R scu:scu /home/scu/log
18+
19+
su-exec scu "$@"

services/sidecar/Dockerfile

+90-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,103 @@
1-
FROM python:3.6-alpine as common
1+
FROM python:3.6-alpine as base
22

3-
LABEL maintainer="Manuel Guidon <[email protected]"
3+
LABEL maintainer=mguidon
44

5-
WORKDIR /work/sidecar
5+
ARG DOCKER_GID_ARG=1001
66

7-
RUN apk add --no-cache postgresql-dev gcc libc-dev
7+
RUN apk add --no-cache \
8+
su-exec
89

9-
COPY services/sidecar/requirements.txt requirements.txt
10+
# create user `scu` and `docker` group (with same id as in host)
11+
RUN adduser -D -u 8004 scu &&\
12+
addgroup -g $DOCKER_GID_ARG docker
1013

11-
RUN pip install --upgrade pip \
12-
&& pip install -r requirements.txt \
13-
&& pip list --format=columns
14+
ENV HOME /home/scu
15+
ENV PIP /home/scu/.venv/bin/pip3
1416

1517
EXPOSE 8000
18+
VOLUME /home/scu/input
19+
VOLUME /home/scu/output
20+
VOLUME /home/scu/log
1621

17-
FROM common as development
22+
WORKDIR /home/scu
1823

19-
VOLUME /work/sidecar
20-
VOLUME /work/packages
24+
# -------------------------- Build stage -------------------
25+
#
26+
# - Preserves relative folder structure
27+
#
28+
# + /home/scu/ $HOME
29+
# + services/sidecar
30+
# ...
31+
# + packages
32+
# ...
33+
FROM base as build
2134

22-
# NO clue why this does not work without explicitly specifying
23-
ENTRYPOINT celery -A sidecar worker -c 2 --loglevel=info
35+
RUN apk add --no-cache \
36+
postgresql-dev \
37+
gcc \
38+
libc-dev
2439

25-
FROM common as production
40+
RUN python3 -m venv $HOME/.venv &&\
41+
$PIP install --no-cache-dir --upgrade \
42+
pip \
43+
wheel \
44+
setuptools
2645

27-
# the context for the build is the git repo root directory
28-
COPY services/sidecar/src /work
29-
COPY packages /work/packages
46+
# TODO: check if scu:scu copy is necessary!?
47+
COPY --chown=scu:scu services/sidecar/requirements/base.txt requirements-base.txt
48+
RUN $PIP install --no-cache-dir -r requirements-base.txt &&\
49+
rm requirements-base.txt
3050

31-
# NO clue why this does not work without explicitly specifying
32-
ENV PYTHONPATH="/work/packages/simcore-sdk/src:/work/packages/s3wrapper/src"
33-
ENTRYPOINT celery -A sidecar worker -c 2 --loglevel=info
51+
COPY --chown=scu:scu services/sidecar/.docker .docker
52+
COPY --chown=scu:scu services/sidecar/boot.sh boot.sh
53+
54+
# --------------------------Development stage -------------------
55+
FROM build as development
56+
57+
ARG HOST_GID_ARG=1000
58+
59+
# in dev-mode we give access to `scu` to host's mapped volumes
60+
# FIXME: files created by scu cannot be deleted by host! we need to do the same group in host?
61+
RUN addgroup -g $HOST_GID_ARG hgrp &&\
62+
addgroup scu hgrp && \
63+
chown -R scu:scu $HOME/.venv
64+
65+
VOLUME /home/scu/packages
66+
VOLUME /home/scu/services/sidecar
67+
68+
ENV DEBUG 1
69+
USER root
70+
ENTRYPOINT [ "/bin/sh", ".docker/entrypoint.sh" ]
71+
CMD ./boot.sh
72+
73+
74+
# --------------------------Production multi-stage -------------------
75+
#FROM build as build-production
76+
FROM build as production
77+
78+
# TODO: check if scu:scu copy is necessary in all cases!? since we are just installing?
79+
COPY --chown=scu:scu packages $HOME/packages
80+
COPY --chown=scu:scu services/sidecar $HOME/services/sidecar
81+
82+
WORKDIR /home/scu/services/sidecar
83+
RUN $PIP --no-cache-dir install -r requirements/prod.txt ;\
84+
$PIP list
85+
86+
#-------------------
87+
#FROM base as production
88+
89+
# TODO: PC Reduce docker size by installing only non-dev
90+
91+
#COPY --from=build-production --chown=scu:scu $HOME/boot.sh boot.sh
92+
#COPY --from=build-production --chown=scu:scu $HOME/.venv .venv
93+
#COPY --from=build-production --chown=scu:scu $HOME/.docker .docker
94+
95+
WORKDIR /home/scu/
96+
97+
RUN . $HOME/.venv/bin/activate; pip list &&\
98+
rm -rf $HOME/services
99+
100+
ENV DEBUG 0
101+
USER root
102+
ENTRYPOINT [ "/bin/sh", ".docker/entrypoint.sh" ]
103+
CMD ./boot.sh

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+
TODO: See issue #198
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+
```

0 commit comments

Comments
 (0)