1
- # TODO: this is still not finished!!
2
1
FROM python:3.6-alpine as base
3
2
4
3
LABEL maintainer={{ cookiecutter.github_username }}
@@ -17,11 +16,13 @@ RUN apk add --no-cache \
17
16
su-exec
18
17
19
18
ENV HOME /home/scu
20
- ENV PIP /home/scu/.venv/bin/pip3
19
+ # TODO: Workaround for https://github.com/pypa/pip/issues/6197: Added explicit --cache-dir that is removed at the end of the build
20
+ ENV PIP /home/scu/.venv/bin/pip3 --cache-dir=/pipcache
21
21
22
22
EXPOSE 8080
23
23
24
24
# -------------------------- Build stage -------------------
25
+ # Common stage between production and development targets
25
26
#
26
27
# + /home/scu/ $HOME
27
28
# + packages
@@ -44,7 +45,7 @@ RUN apk add --no-cache \
44
45
libffi-dev
45
46
46
47
RUN python3 -m venv $HOME/.venv &&\
47
- $PIP install --no-cache-dir -- upgrade \
48
+ $PIP install --upgrade \
48
49
pip \
49
50
wheel \
50
51
setuptools
@@ -56,16 +57,19 @@ COPY --chown=scu:scu services/{{ cookiecutter.project_slug }}/requirements/base.
56
57
COPY --chown=scu:scu services/{{ cookiecutter.project_slug }}/docker docker
57
58
RUN chmod +x docker/boot.sh &&\
58
59
chmod +x docker/entrypoint.sh
59
- RUN $PIP install --no-cache-dir - r requirements-base.txt
60
+ RUN $PIP install -r requirements-base.txt
60
61
61
62
# --------------------------Development stage -------------------
63
+ # Source code accessible in host but runs in container
64
+ #
65
+
62
66
FROM build as development
63
67
64
68
ARG HOST_GID_ARG=1000
65
69
66
70
# install test 3rd party packages to accelerate runtime installs
67
71
COPY --chown=scu:scu services/{{ cookiecutter.project_slug }}/requirements/ci.txt requirements-ci.txt
68
- RUN $PIP install --no-cache-dir - r requirements-ci.txt
72
+ RUN $PIP install -r requirements-ci.txt
69
73
70
74
# in dev mode we give access to `scu` to host's mapped volumes
71
75
RUN addgroup -g $HOST_GID_ARG hgrp &&\
@@ -80,37 +84,31 @@ ENTRYPOINT [ "/bin/sh", "docker/entrypoint.sh" ]
80
84
CMD docker/boot.sh
81
85
82
86
83
- # --------------------------Production multi-stage -------------------
84
- # FROM build as build-production
85
- FROM build as production
86
-
87
- ENV SIMCORE_WEB_CONFIG production
87
+ # --------------------------Cache stage -------------------
88
+ # CI in master buils & pushes this target to speed-up image build
89
+ #
90
+ FROM build as cache
88
91
89
- # 2nd party packages
90
92
COPY --chown=scu:scu packages $HOME/packages
91
- # server
92
93
COPY --chown=scu:scu services/{{ cookiecutter.project_slug }} $HOME/services/{{ cookiecutter.project_slug }}
93
94
94
95
WORKDIR /home/scu/services/{{ cookiecutter.project_slug }}
95
- RUN $PIP install --no-cache-dir - r requirements/base.txt &&\
96
- $PIP install --no-cache-dir . &&\
96
+ RUN $PIP install -r requirements/base.txt &&\
97
+ $PIP install . &&\
97
98
$PIP list
98
99
99
- # -------------------
100
- # FROM base as production
101
- # TODO: PC some basic package missing
102
-
103
- # COPY --from=build-production --chown=scu:scu $HOME/services/server/boot.sh $HOME
104
- # COPY --from=build-production --chown=scu:scu $HOME/.venv $HOME/.venv
105
- # RUN . $HOME/.venv/bin/activate; pip list
106
-
107
- # FIXME: temporary solution until found missing packages
108
100
WORKDIR /home/scu
101
+ ENV BOOT_MODE production
102
+
103
+ # --------------------------Production stage -------------------
104
+ # Clean up to reduce image size
105
+ #
106
+ FROM cache as production
109
107
110
108
RUN . $HOME/.venv/bin/activate; pip list &&\
111
109
rm -rf $HOME/packages &&\
112
- rm -rf $HOME/services/{{ cookiecutter.project_slug }}
110
+ rm -rf $HOME/services/{{ cookiecutter.project_slug }} &&\
111
+ rm -rf /pipcache
113
112
114
- ENV BOOT_MODE production
115
113
ENTRYPOINT [ "/bin/sh" , "docker/entrypoint.sh" ]
116
- CMD docker/boot.sh
114
+ CMD [ "/bin/sh" , " docker/boot.sh" ]
0 commit comments