|
1 |
| -FROM python:3.6-alpine as common |
| 1 | +FROM python:3.6-alpine as base |
2 | 2 |
|
3 |
| -LABEL maintainer= "Manuel Guidon <[email protected]" |
| 3 | +LABEL maintainer=mguidon |
4 | 4 |
|
5 |
| -WORKDIR /work/sidecar |
| 5 | +ARG DOCKER_GID_ARG=1001 |
6 | 6 |
|
7 |
| -RUN apk add --no-cache postgresql-dev gcc libc-dev |
| 7 | +RUN apk add --no-cache \ |
| 8 | + su-exec |
8 | 9 |
|
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 |
10 | 13 |
|
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 |
14 | 16 |
|
15 | 17 | EXPOSE 8000
|
| 18 | +VOLUME /home/scu/input |
| 19 | +VOLUME /home/scu/output |
| 20 | +VOLUME /home/scu/log |
16 | 21 |
|
17 |
| -FROM common as development |
| 22 | +WORKDIR /home/scu |
18 | 23 |
|
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 |
21 | 34 |
|
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 |
24 | 39 |
|
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 |
26 | 45 |
|
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 |
30 | 50 |
|
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 |
0 commit comments