|
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="Manuel Guidon guidon" |
| 4 | + |
| 5 | +ARG DOCKER_GID_ARG=1001 |
| 6 | + |
| 7 | +# create user 'scu' and adds it to host's docker group |
| 8 | +RUN adduser -D -u 8004 scu &&\ |
| 9 | + addgroup -g $DOCKER_GID_ARG docker &&\ |
| 10 | + addgroup scu docker |
| 11 | + |
| 12 | +ENV HOME /home/scu |
| 13 | +ENV PIP /home/scu/.venv/bin/pip3 |
| 14 | + |
| 15 | +EXPOSE 8000 |
| 16 | +VOLUME /home/scu/input |
| 17 | +VOLUME /home/scu/output |
| 18 | +VOLUME /home/scu/log |
| 19 | +#VOLUME /var/run/docker.sock TODO: PC->MaG is this using docker?? |
| 20 | + |
| 21 | +# -------------------------- Build stage ------------------- |
| 22 | +# Keeps same folder structure as in repo so we can reuse relative paths |
| 23 | +# |
| 24 | +# + /home/scu/ $HOME |
| 25 | +# + services/sidecar |
| 26 | +# ... |
| 27 | +# + packages |
| 28 | +# ... |
| 29 | +FROM base as build |
4 | 30 |
|
5 | 31 | RUN apk add --no-cache \
|
6 | 32 | postgresql-dev \
|
7 | 33 | gcc \
|
8 | 34 | libc-dev
|
9 | 35 |
|
10 |
| -RUN pip install --upgrade \ |
| 36 | +RUN python3 -m venv $HOME/.venv &&\ |
| 37 | + $PIP install --no-cache-dir --upgrade \ |
11 | 38 | pip \
|
12 | 39 | wheel \
|
13 | 40 | setuptools
|
14 | 41 |
|
15 |
| -WORKDIR /work |
| 42 | +WORKDIR /home/scu |
| 43 | + |
16 | 44 | # Buil context set at repo's root
|
17 |
| -COPY services/sidecar/requirements requirements |
| 45 | +COPY --chown=scu:scu services/sidecar/requirements requirements |
18 | 46 |
|
19 |
| -RUN pip install -r requirements/base.txt &&\ |
| 47 | +RUN $PIP install --no-cache-dir -r requirements/base.txt &&\ |
20 | 48 | rm -rf requirements
|
21 | 49 |
|
22 |
| -# Keeps same folder structure as in repo so we can reuse relative paths |
23 |
| -RUN mkdir -p /work/packages &&\ |
24 |
| - mkdir -p /work/services/sidecar |
| 50 | +# --------------------------Development stage ------------------- |
| 51 | +FROM build as development |
25 | 52 |
|
26 |
| -EXPOSE 8000 |
| 53 | +ARG HOST_GID_ARG=1000 |
27 | 54 |
|
| 55 | +# in dev-mode we give access to `scu` to host's mapped volumes |
| 56 | +RUN addgroup -g $HOST_GID_ARG hgrp &&\ |
| 57 | + addgroup scu hgrp && \ |
| 58 | + chown -R scu:scu $HOME/.venv |
28 | 59 |
|
29 |
| -# --------------------------Development stage ------------------- |
30 |
| -FROM common as development |
31 |
| - |
32 |
| -VOLUME /work/packages |
33 |
| -VOLUME /work/services/sidecar |
| 60 | +VOLUME /home/scu/packages |
| 61 | +VOLUME /home/scu/services/sidecar |
34 | 62 |
|
| 63 | +USER scu |
35 | 64 | ENV DEBUG 1
|
36 |
| -WORKDIR /work/services/sidecar |
| 65 | +WORKDIR /home/scu/services/sidecar |
37 | 66 | CMD ./boot.sh
|
38 |
| -# FIXME: executing this as root will create folders (e.g. eggs) in the mapped |
39 | 67 |
|
40 | 68 |
|
41 |
| -# --------------------------Production stage ------------------- |
42 |
| -FROM common as production |
| 69 | +# --------------------------Production mult-stage ------------------- |
| 70 | +FROM build as build-production |
43 | 71 |
|
44 | 72 | # Buil context set at repo's root
|
45 |
| -COPY packages /work/packages |
46 |
| -COPY services/sidecar /work/services/sidecar |
| 73 | +COPY --chown=scu:scu packages $HOME/packages |
| 74 | +COPY --chown=scu:scu services/sidecar $HOME/services/sidecar |
| 75 | + |
| 76 | +WORKDIR /home/scu/services/sidecar |
| 77 | +RUN $PIP --no-cache-dir install -r requirements/prod.txt ;\ |
| 78 | + $PIP list |
| 79 | + |
| 80 | +#------------------- |
| 81 | +FROM base as production |
47 | 82 |
|
48 |
| -WORKDIR /work/services/sidecar |
| 83 | +COPY --from=build-production --chown=scu:scu $HOME/services/sidecar/boot.sh $HOME |
| 84 | +COPY --from=build-production --chown=scu:scu $HOME/.venv $HOME/.venv |
49 | 85 |
|
50 |
| -RUN pip install -r requirements/prod.txt ;\ |
51 |
| - pip list &&\ |
52 |
| - mv boot.sh /work &&\ |
53 |
| - rm -rf /work/packages &&\ |
54 |
| - rm -rf /work/services/sidecar |
| 86 | +RUN . $HOME/.venv/bin/activate; pip list |
55 | 87 |
|
| 88 | +WORKDIR /home/scu |
| 89 | +USER scu |
56 | 90 | ENV DEBUG 0
|
57 |
| -WORKDIR /work |
58 | 91 | ENTRYPOINT ./boot.sh
|
0 commit comments