|
1 |
| -# syntax = tonistiigi/dockerfile:runmount20180618 # enables --mount option for run |
2 |
| -FROM polycubebot/base_image:latest |
| 1 | +# syntax = tonistiigi/dockerfile:runmount20180618 |
| 2 | +############################################### |
| 3 | +# STEP 1: using an Ubuntu 18.04 image to install the entire Polycube framework with all dependencies. |
| 4 | +# |
| 5 | +# During this step an ubuntu image is used to compile Polycube with all its dependencies. |
| 6 | +# This dockerfile is reused for all the DEFAULT_MODE (default, pcn-iptables, pcn-k8s) which, thanks to install.sh and pre-requirements.sh scripts, |
| 7 | +# enable/disable Polycube services and install specific tools. |
| 8 | +FROM ubuntu:18.04 AS builder |
| 9 | + |
3 | 10 | ARG DEFAULT_MODE=default
|
4 | 11 | ENV MODE=$DEFAULT_MODE
|
5 |
| -RUN echo "The mode is $MODE" |
6 |
| -RUN rm -rf /tmp/polycube |
7 |
| -RUN --mount=target=/polycube cp -r /polycube /tmp/polycube && \ |
8 |
| -cd /tmp/polycube && \ |
| 12 | +RUN --mount=target=/polycube cp -r /polycube /tmp/polycube && cd /tmp/polycube && \ |
| 13 | +mkdir -p /usr/local/share/polycube /usr/local/include/polycube /opt/cni/bin /cni && touch /cni-conf /pcn_k8s /opt/cni/bin/polycube && \ |
9 | 14 | SUDO="" USER="root" WORKDIR="/tmp/dev" ./scripts/install.sh $MODE && \
|
10 |
| -# install pcn-kubernetes only components |
| 15 | +# install pcn-k8s only components |
11 | 16 | if [ "$MODE" = "pcn-k8s" ] ; then \
|
12 | 17 | cd /tmp && mkdir -p tmp && cd tmp && \
|
13 | 18 | curl -sS -L https://storage.googleapis.com/kubernetes-release/network-plugins/cni-0799f5732f2a11b329d9e3d51b9c8f2e3759f2ff.tar.gz -o cni.tar.gz && \
|
14 | 19 | tar -xvf cni.tar.gz && \
|
15 |
| - mkdir /cni && \ |
16 | 20 | cp bin/loopback /cni && \
|
17 | 21 | cd /tmp/polycube/src/components/k8s/cni/polycube && \
|
18 | 22 | GOOS=linux go build -o /opt/cni/bin/polycube . && \
|
19 | 23 | cd /tmp/polycube/src/components/k8s/cni/conf && \
|
20 | 24 | GOOS=linux go build -o /cni-conf . && \
|
21 | 25 | cd /tmp/polycube/src/components/k8s/pcn_k8s/ && \
|
22 | 26 | GOOS=linux go build -o /pcn_k8s . ; \
|
23 |
| -fi && \ |
24 |
| -apt-get purge --auto-remove -y git bison cmake flex \ |
25 |
| -libllvm5.0 llvm-5.0-dev libclang-5.0-dev uuid-dev autoconf software-properties-common golang-go \ |
26 |
| -libtool curl && \ |
27 |
| -apt-get clean && \ |
28 |
| -rm -fr /root /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/local/go/* |
29 |
| -# TODO: which other apt-get packages can be removed? |
| 27 | +fi |
| 28 | + |
| 29 | +# copying cni scripts (will be removed if not needed) |
| 30 | +ADD src/components/k8s/cni/cni-install.sh src/components/k8s/cni/cni-uninstall.sh src/components/k8s/pcn_k8s/cleanup.sh src/components/k8s/pcn_k8s/init.sh / |
| 31 | + |
| 32 | +############################################### |
| 33 | +# STEP 2: using an Ubuntu 18.04 image and extracting executables obtained by the image created at STEP 1. |
| 34 | +# |
| 35 | +# During this final step a new fresh ubuntu image is used and all the previously generated executables/libraries are copied. |
| 36 | +# This way, this final image contains only the result of the compilation and NOT the entire softwares/scripts needed at compile-time. |
| 37 | +# Moreover, depending on the DEFAULT_MODE, some tools that are needed at runtime (like iptables and iproute2 for the DEFAULT_MODE=pcn-k8s) are |
| 38 | +# installed. |
| 39 | + |
| 40 | +FROM ubuntu:18.04 |
30 | 41 |
|
31 |
| -ADD src/components/k8s/cni/cni-install.sh /cni-install.sh |
32 |
| -ADD src/components/k8s/cni/cni-uninstall.sh /cni-uninstall.sh |
33 |
| -ADD src/components/k8s/pcn_k8s/cleanup.sh /cleanup.sh |
34 |
| -ADD src/components/k8s/pcn_k8s/init.sh /init.sh |
| 42 | +ARG DEFAULT_MODE=default |
| 43 | +ENV MODE=$DEFAULT_MODE |
| 44 | +# copying binaries |
| 45 | +COPY --from=builder /usr/local/bin /usr/local/bin |
| 46 | +COPY --from=builder /usr/local/share/polycube /usr/local/share/polycube |
| 47 | +# copying polycube services |
| 48 | +COPY --from=builder /usr/lib/lib*.so /usr/lib/ |
| 49 | +# copying libpistache libyang libtins libprometheus .so |
| 50 | +COPY --from=builder /usr/local/lib/lib*.so /usr/local/lib/ |
| 51 | +# copying libyang folder containing plugins (needed for yanglint) |
| 52 | +COPY --from=builder /usr/local/lib/libyang /usr/local/lib/libyang |
| 53 | +# copying main OS libraries |
| 54 | +COPY --from=builder /usr/lib/x86_64-linux-gnu/libnl*.so /usr/lib/x86_64-linux-gnu/libcrypto*.so\ |
| 55 | + /usr/lib/x86_64-linux-gnu/libelf*.so /usr/lib/x86_64-linux-gnu/libssl*.so \ |
| 56 | + /usr/lib/x86_64-linux-gnu/libpcap*.so /usr/lib/x86_64-linux-gnu/ |
| 57 | +COPY --from=builder /lib/x86_64-linux-gnu/libnl*.so /lib/x86_64-linux-gnu/ |
| 58 | +# copying base yang model |
| 59 | +COPY --from=builder /usr/local/include/polycube /usr/local/include/polycube |
| 60 | +# copying k8s scripts and cni if present |
| 61 | +COPY --from=builder /*.sh /cni* /pcn_k8s / |
| 62 | +COPY --from=builder /opt/cni/bin/polycube /opt/cni/bin/ |
| 63 | +# creating log dir and file + configuring links for libraries + installing essential runtime tools |
| 64 | +RUN mkdir -p /var/log/polycube && touch /var/log/polycube/polycubed.log && \ |
| 65 | +# install pcn-k8s only essential tools, else remove useless scripts |
| 66 | +if [ "$MODE" = "pcn-k8s" ] ; then \ |
| 67 | + apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -yq iptables iproute2 && \ |
| 68 | + apt-get purge --auto-remove && apt-get clean ; \ |
| 69 | +else \ |
| 70 | + rm -rf /opt/cni/bin/polycube /*.sh /pcn_k8s /cni*; \ |
| 71 | +fi && ldconfig |
35 | 72 |
|
36 | 73 | # by running nsenter --mount=/host/proc/1/ns/mnt polycubed, the daemon has a complete view of the namespaces of the host and it is able to manipulate them (needed for shadow services)
|
37 | 74 | CMD ["nsenter","--mount=/host/proc/1/ns/mnt","polycubed"]
|
0 commit comments