1
- FROM python:3.6-alpine as base-stage
1
+ FROM python:3.6-alpine as base
2
2
3
3
LABEL maintainer=pcrespov
4
4
@@ -9,18 +9,31 @@ LABEL maintainer=pcrespov
9
9
# REQUIRED: context expected at $(this-file-dir)/../../
10
10
# REQUIRED: client_qx:build image ready
11
11
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 -------------------
12
27
#
13
28
# + /home/scu/ $HOME
14
- # + client $SIMCORE_WEB_OUTDIR
29
+ # + packages
30
+ # + services/web/client $SIMCORE_WEB_OUTDIR
15
31
# - index.html
16
32
# ...
17
- # + packages * installed simcore/packages
18
- # + simcore_sdk
19
- # + server
20
- # + src *
33
+ # + services/web/server
34
+ # + src
21
35
# + tests
22
36
#
23
- # * = in PYTHONPATH
24
37
#
25
38
#
26
39
# TODO: try installing in .venv in $HOME would allow installing as non-root all 3rd, 2nd
@@ -30,109 +43,75 @@ LABEL maintainer=pcrespov
30
43
# could copy and then python setup.py install OR git clone into the container.
31
44
# This applies for both
32
45
#
33
-
34
- RUN adduser -D -u 8004 scu
46
+ FROM base as build
35
47
36
48
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
49
53
54
+ RUN python3 -m venv $HOME/.venv &&\
55
+ $PIP install --no-cache-dir --upgrade \
56
+ pip \
57
+ wheel \
58
+ setuptools
50
59
51
60
WORKDIR /home/scu
52
61
53
62
# 1. install base 3rd party packages
54
63
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 &&\
68
65
rm -rf requirements
69
66
70
- USER scu
67
+ # --------------------------Development stage -------------------
68
+ FROM build as development
71
69
72
- # 2. creates mounted volumes
73
- RUN mkdir $HOME/client && \
74
- mkdir $HOME/packages
70
+ ARG HOST_GID_ARG=1000
75
71
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
77
76
78
- VOLUME /home/scu/server/
79
- VOLUME /home/scu/client/
80
77
VOLUME /home/scu/packages
78
+ VOLUME /home/scu/services/web/server/
79
+ VOLUME /home/scu/services/webclient/
81
80
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
87
83
ENV DEBUG 1
84
+ WORKDIR /home/scu/services/web/server
88
85
CMD ./boot.sh
89
86
90
87
91
-
92
- # ------------------------------------------------------------------------------------------
93
- FROM base-stage as production
88
+ # --------------------------Production multi-stage -------------------
89
+ FROM build as build-production
94
90
95
91
ENV SIMCORE_WEB_CONFIG production
96
92
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
118
99
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
121
103
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
124
106
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!?
127
108
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
129
111
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
132
113
114
+ WORKDIR /home/scu
133
115
USER scu
134
-
135
- WORKDIR $HOME/server/src
136
-
137
116
ENV DEBUG 0
138
- CMD ./boot.sh
117
+ ENTRYPOINT ./boot.sh
0 commit comments