Skip to content

Commit a5d8220

Browse files
author
Pedro Crespo
committed
Implements entry in #186: - upgrades Dockerfile with .venv and pip installing 3rd parties
1 parent 3c55bf3 commit a5d8220

File tree

11 files changed

+123
-105
lines changed

11 files changed

+123
-105
lines changed

services/docker-compose.devel.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ services:
2020
build:
2121
target: development
2222
volumes:
23-
- ./web/server:/home/scu/server
24-
- ./web/client/source-output:/home/scu/client
23+
- ./web/server:/home/scu/services/web/server
24+
- ./web/client/source-output:/home/scu/services/web/client
2525
- ../packages:/home/scu/packages
2626
depends_on:
2727
- webclient

services/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ services:
3636
build:
3737
context: ../
3838
dockerfile: services/web/Dockerfile
39-
target: ci
39+
target: production
4040
ports:
4141
- '9081:8080'
4242
environment:

services/sidecar/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.6-alpine as base
22

3-
LABEL maintainer="mguidon"
3+
LABEL maintainer=mguidon
44

55
ARG DOCKER_GID_ARG=1001
66

@@ -41,7 +41,7 @@ RUN python3 -m venv $HOME/.venv &&\
4141

4242
WORKDIR /home/scu
4343

44-
# Buil context set at repo's root
44+
# Build context set at repo's root
4545
COPY --chown=scu:scu services/sidecar/requirements requirements
4646

4747
RUN $PIP install --no-cache-dir -r requirements/base.txt &&\
@@ -66,7 +66,7 @@ WORKDIR /home/scu/services/sidecar
6666
CMD ./boot.sh
6767

6868

69-
# --------------------------Production mult-stage -------------------
69+
# --------------------------Production multi-stage -------------------
7070
FROM build as build-production
7171

7272
# Buil context set at repo's root

services/web/Dockerfile

+62-83
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.6-alpine as base-stage
1+
FROM python:3.6-alpine as base
22

33
LABEL maintainer=pcrespov
44

@@ -9,18 +9,31 @@ LABEL maintainer=pcrespov
99
# REQUIRED: context expected at $(this-file-dir)/../../
1010
# REQUIRED: client_qx:build image ready
1111

12+
ARG DOCKER_GID_ARG=1001
13+
14+
# create user 'scu' and adds it to host's docker group
15+
RUN adduser -D -u 8004 scu &&\
16+
addgroup -g $DOCKER_GID_ARG docker &&\
17+
addgroup scu docker
18+
19+
ENV HOME /home/scu
20+
ENV PIP /home/scu/.venv/bin/pip3
21+
ENV SIMCORE_WEB_OUTDIR $HOME/services/web/client
22+
ENV IS_CONTAINER_CONTEXT Yes
23+
24+
EXPOSE 8080
25+
26+
# -------------------------- Build stage -------------------
1227
#
1328
# + /home/scu/ $HOME
14-
# + client $SIMCORE_WEB_OUTDIR
29+
# + packages
30+
# + services/web/client $SIMCORE_WEB_OUTDIR
1531
# - index.html
1632
# ...
17-
# + packages * installed simcore/packages
18-
# + simcore_sdk
19-
# + server
20-
# + src *
33+
# + services/web/server
34+
# + src
2135
# + tests
2236
#
23-
# * = in PYTHONPATH
2437
#
2538
#
2639
# TODO: try installing in .venv in $HOME would allow installing as non-root all 3rd, 2nd
@@ -30,109 +43,75 @@ LABEL maintainer=pcrespov
3043
# could copy and then python setup.py install OR git clone into the container.
3144
# This applies for both
3245
#
33-
34-
RUN adduser -D -u 8004 scu
46+
FROM base as build
3547

3648
RUN apk add --no-cache \
37-
postgresql-dev \
38-
gcc \
39-
libc-dev \
40-
libffi-dev
41-
42-
43-
ENV HOME /home/scu
44-
ENV SIMCORE_WEB_OUTDIR $HOME/client
45-
#ENV SIMCORE_WEB_OUTDIR $HOME/src/static
46-
ENV IS_CONTAINER_CONTEXT Yes
47-
# FIXME: install packages instead of reference it!
48-
ENV PYTHONPATH "$HOME/server/src:$HOME/packages/simcore-sdk/src:$HOME/packages/s3wrapper/src"
49+
postgresql-dev \
50+
gcc \
51+
libc-dev \
52+
libffi-dev
4953

54+
RUN python3 -m venv $HOME/.venv &&\
55+
$PIP install --no-cache-dir --upgrade \
56+
pip \
57+
wheel \
58+
setuptools
5059

5160
WORKDIR /home/scu
5261

5362
# 1. install base 3rd party packages
5463
COPY --chown=scu:scu services/web/server/requirements requirements
55-
RUN pip3 install --no-cache-dir -r requirements/base.txt
56-
57-
EXPOSE 8080
58-
59-
#ENTRYPOINT ["python3", "-m", "aiohttp.web"]
60-
61-
# ------------------------------------------------------------------------------------------
62-
FROM base-stage as development
63-
64-
ENV SIMCORE_WEB_CONFIG development
65-
66-
# 1.1 install packages needed for testing
67-
RUN pip3 install --no-cache-dir -r requirements/tests.txt && \
64+
RUN $PIP install --no-cache-dir -r requirements/base.txt &&\
6865
rm -rf requirements
6966

70-
USER scu
67+
# --------------------------Development stage -------------------
68+
FROM build as development
7169

72-
# 2. creates mounted volumes
73-
RUN mkdir $HOME/client && \
74-
mkdir $HOME/packages
70+
ARG HOST_GID_ARG=1000
7571

76-
WORKDIR $HOME/server/src
72+
# in dev-mode we give access to `scu` to host's mapped volumes
73+
RUN addgroup -g $HOST_GID_ARG hgrp &&\
74+
addgroup scu hgrp && \
75+
chown -R scu:scu $HOME/.venv
7776

78-
VOLUME /home/scu/server/
79-
VOLUME /home/scu/client/
8077
VOLUME /home/scu/packages
78+
VOLUME /home/scu/services/web/server/
79+
VOLUME /home/scu/services/webclient/
8180

82-
# TODO: add watch functionality in dev mode
83-
#CMD ["-H", "0.0.0.0", \
84-
# "-P", "8080", \
85-
# "server.main:init_app"]
86-
81+
USER scu
82+
ENV SIMCORE_WEB_CONFIG development
8783
ENV DEBUG 1
84+
WORKDIR /home/scu/services/web/server
8885
CMD ./boot.sh
8986

9087

91-
92-
# ------------------------------------------------------------------------------------------
93-
FROM base-stage as production
88+
# --------------------------Production multi-stage -------------------
89+
FROM build as build-production
9490

9591
ENV SIMCORE_WEB_CONFIG production
9692

97-
# 2. install 2nd party packages
98-
COPY --chown=scu:scu packages packages
99-
100-
# 3. install client
101-
COPY --from=services_webclient:build --chown=scu:scu /home/scu/client/build-output client
102-
103-
# 4. install server
104-
COPY --chown=scu:scu services/web/server/src server/src
105-
106-
USER scu
107-
108-
WORKDIR $HOME/server/src
109-
110-
ENV DEBUG 0
111-
CMD ./boot.sh
112-
113-
114-
# ------------------------------------------------------------------------------------------
115-
FROM base-stage as ci
116-
117-
ENV SIMCORE_WEB_CONFIG production
93+
# 2. 2nd party packages
94+
COPY --chown=scu:scu packages $HOME/packages
95+
# 3. client
96+
COPY --from=services_webclient:build --chown=scu:scu /home/scu/client/build-output $HOME/services/client
97+
# 4. server
98+
COPY --chown=scu:scu services/web/server $HOME/services/web/server
11899

119-
# 2. install 2nd party packages
120-
COPY --chown=scu:scu packages packages
100+
WORKDIR /home/scu/services/web/server
101+
RUN $PIP --no-cache-dir install -r requirements/prod.txt ;\
102+
$PIP list
121103

122-
# 3. install client
123-
COPY --from=services_webclient:build --chown=scu:scu /home/scu/client/build-output client
104+
#-------------------
105+
FROM base as production
124106

125-
# 4. copy all server
126-
COPY --chown=scu:scu services/web/server server
107+
# TODO: PC->MaG some postgresql missing? install non-dev package!?
127108

128-
WORKDIR $HOME/server/
109+
COPY --from=build-production --chown=scu:scu $HOME/services/web/server/boot.sh $HOME
110+
COPY --from=build-production --chown=scu:scu $HOME/.venv $HOME/.venv
129111

130-
# 5. installs all packages
131-
RUN pip3 install --no-cache-dir -r requirements/docker-ci.txt
112+
RUN . $HOME/.venv/bin/activate; pip list
132113

114+
WORKDIR /home/scu
133115
USER scu
134-
135-
WORKDIR $HOME/server/src
136-
137116
ENV DEBUG 0
138-
CMD ./boot.sh
117+
ENTRYPOINT ./boot.sh

services/web/server/boot.sh

100644100755
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/sh
2-
#echo "activating python virtual env..."
3-
#source /home/scu/venv/bin/activate
2+
echo "activating python virtual env..."
3+
source $HOME/.venv/bin/activate
44

55
if [[ ${DEBUG} == "1" ]]
66
then
77
echo "Booting in development mode ..."
8+
pip install -r requirements/dev.txt
89
service-web-server --config server-docker-dev.yaml
910
else
1011
echo "Booting in production mode ..."

services/web/server/requirements-dev.txt

-5
This file was deleted.
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# continuous integration mode
2-
-e ".[test]"
2+
.[test]
33

4-
-e ../../../packages/s3wrapper/
5-
-e ../../../packages/simcore-sdk/
4+
../../../packages/s3wrapper/
5+
../../../packages/simcore-sdk/
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# development mode
2+
# continuous integration mode
3+
-e ".[test]"
4+
5+
-e ../../../packages/s3wrapper/
6+
-e ../../../packages/simcore-sdk/
7+
8+
aiohttp-devtools==0.10.1
9+
autopep8>=1.3.5

services/web/server/requirements/docker-ci.txt

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.
2+
../../../packages/s3wrapper/
3+
../../../packages/simcore-sdk/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Runs insides a container
2+
---
3+
version: "1.0"
4+
app:
5+
host: 127.0.0.1
6+
port: 8080
7+
client_outdir: ${SIMCORE_WEB_OUTDIR}
8+
log_level: DEBUG
9+
testing: True
10+
director:
11+
host: ${DIRECTOR_HOST}
12+
port: ${DIRECTOR_PORT}
13+
postgres:
14+
database: ${POSTGRES_DB}
15+
endpoint: ${POSTGRES_ENDPOINT}
16+
user: ${POSTGRES_USER}
17+
password: ${POSTGRES_PASSWORD}
18+
host: null
19+
port: null
20+
rabbit:
21+
user: ${RABBITMQ_USER}
22+
password: ${RABBITMQ_PASSWORD}
23+
channels:
24+
progress: ${RABBITMQ_PROGRESS_CHANNEL}
25+
log: ${RABBITMQ_LOG_CHANNEL}
26+
s3:
27+
endpoint: ${S3_ENDPOINT}
28+
access_key: ${S3_ACCESS_KEY}
29+
secret_key: ${S3_SECRET_KEY}
30+
bucket_name: ${S3_BUCKET_NAME}
31+
cs_s4l:
32+
host: ${CS_S4L_HOSTNAME}
33+
app:
34+
port: ${CS_S4L_PORT_APP}
35+
modeler:
36+
port: ${CS_S4L_PORT_MOD}
37+
...

0 commit comments

Comments
 (0)