Skip to content

Commit 5bde977

Browse files
author
Pedro Crespo
committed
Adds pip workaround as in ITISFoundation/osparc-simcore#540
Cleans up Dockerfile target `cache`
1 parent b8e7cc1 commit 5bde977

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

{{cookiecutter.project_slug}}/Dockerfile

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO: this is still not finished!!
21
FROM python:3.6-alpine as base
32

43
LABEL maintainer={{ cookiecutter.github_username }}
@@ -17,11 +16,13 @@ RUN apk add --no-cache \
1716
su-exec
1817

1918
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
2121

2222
EXPOSE 8080
2323

2424
# -------------------------- Build stage -------------------
25+
# Common stage between production and development targets
2526
#
2627
# + /home/scu/ $HOME
2728
# + packages
@@ -44,7 +45,7 @@ RUN apk add --no-cache \
4445
libffi-dev
4546

4647
RUN python3 -m venv $HOME/.venv &&\
47-
$PIP install --no-cache-dir --upgrade \
48+
$PIP install --upgrade \
4849
pip \
4950
wheel \
5051
setuptools
@@ -56,16 +57,19 @@ COPY --chown=scu:scu services/{{ cookiecutter.project_slug }}/requirements/base.
5657
COPY --chown=scu:scu services/{{ cookiecutter.project_slug }}/docker docker
5758
RUN chmod +x docker/boot.sh &&\
5859
chmod +x docker/entrypoint.sh
59-
RUN $PIP install --no-cache-dir -r requirements-base.txt
60+
RUN $PIP install -r requirements-base.txt
6061

6162
# --------------------------Development stage -------------------
63+
# Source code accessible in host but runs in container
64+
#
65+
6266
FROM build as development
6367

6468
ARG HOST_GID_ARG=1000
6569

6670
# install test 3rd party packages to accelerate runtime installs
6771
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
6973

7074
# in dev mode we give access to `scu` to host's mapped volumes
7175
RUN addgroup -g $HOST_GID_ARG hgrp &&\
@@ -80,37 +84,31 @@ ENTRYPOINT [ "/bin/sh", "docker/entrypoint.sh" ]
8084
CMD docker/boot.sh
8185

8286

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
8891

89-
# 2nd party packages
9092
COPY --chown=scu:scu packages $HOME/packages
91-
# server
9293
COPY --chown=scu:scu services/{{ cookiecutter.project_slug }} $HOME/services/{{ cookiecutter.project_slug }}
9394

9495
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 . &&\
9798
$PIP list
9899

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
108100
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
109107

110108
RUN . $HOME/.venv/bin/activate; pip list &&\
111109
rm -rf $HOME/packages &&\
112-
rm -rf $HOME/services/{{ cookiecutter.project_slug }}
110+
rm -rf $HOME/services/{{ cookiecutter.project_slug }} &&\
111+
rm -rf /pipcache
113112

114-
ENV BOOT_MODE production
115113
ENTRYPOINT [ "/bin/sh", "docker/entrypoint.sh" ]
116-
CMD docker/boot.sh
114+
CMD ["/bin/sh", "docker/boot.sh"]

{{cookiecutter.project_slug}}/docker/boot.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ then
1111
echo "INFO: Workdir :`pwd`"
1212

1313
cd $HOME/services/{{ cookiecutter.project_slug }}
14-
pip install -r requirements/ci.txt
15-
pip install -e .
16-
pip list
14+
$PIP install -r requirements/ci.txt
15+
$PIP install -e .
16+
$PIP list
1717

1818
cd $HOME/
1919
{{ cookiecutter.command_line_interface_bin_name }} --config config-host-dev.yaml

0 commit comments

Comments
 (0)