|
1 | | -#FROM ubuntu:20.04 as build_base |
2 | | -FROM ubuntu:20.04 as build_base_go |
3 | | -# PATH="/opt/PF_RING/userland/examples_zc:$PATH" |
4 | | -ARG GO_VERSION=1.15.2 |
5 | | -ARG CUSTOM_BUILD |
6 | | -ARG BRANCH=master |
7 | | -ENV PATH="/usr/local/go/bin:/root/.cargo/bin:${PATH}" \ |
8 | | - GOPATH="/root/go" \ |
9 | | - GOROOT="/usr/local/go" |
10 | | - |
11 | | -# Install dependencies: including rust and go |
12 | | -RUN apt-get update && \ |
13 | | - DEBIAN_FRONTEND="noninteractive" apt-get -y -q install wget git make gcc bison flex protobuf-compiler curl libssl-dev pkg-config libgmp3-dev libzmq3-dev && \ |
14 | | - apt-get clean all && \ |
15 | | - wget -q https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz && \ |
16 | | - tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \ |
17 | | - curl https://sh.rustup.rs -sSf -o install_rust.sh; sh install_rust.sh -y && \ |
18 | | - cargo install protobuf-codegen |
19 | | - |
20 | | -# Install PFRING to get libraries |
21 | | -RUN apt-get install -y -q software-properties-common wget && \ |
22 | | - add-apt-repository universe && \ |
23 | | - wget https://packages.ntop.org/apt-stable/20.04/all/apt-ntop-stable.deb && \ |
24 | | - apt install ./apt-ntop-stable.deb && \ |
25 | | - apt-get clean all && \ |
26 | | - apt-get update && \ |
27 | | - apt-get install -y -q pfring && \ |
28 | | - apt-get clean all |
29 | | - |
30 | | - |
31 | | -# Copy docker context dir. This is used as a source if CUSTOM_BUILD is enabled |
32 | | -COPY . /tmp/conjure |
33 | | - |
34 | | -# Get Conjure or copy a directory Dockerfile is in. Switched by CUSTOM_BUILD var |
35 | | -RUN go get -d github.com/refraction-networking/conjure/... ; \ |
36 | | - bash -c 'if [[ ! -z "$CUSTOM_BUILD" ]] ; then \ |
37 | | - rm -rf ${GOPATH}/src/github.com/refraction-networking/conjure; cp -r /tmp/conjure ${GOPATH}/src/github.com/refraction-networking/conjure ; \ |
38 | | - fi' |
39 | | - |
40 | | -# Checkout needed branch if not builing using CUSTOM_BUILD |
41 | | -RUN bash -c 'if [[ -z "CUSTOM_BUILD" ]] ; then \ |
42 | | - cd /root/go/src/github.com/refraction-networking/conjure && \ |
43 | | - git checkout ${BRANCH}; \ |
44 | | - fi' |
45 | | - |
46 | | -# Compile |
47 | | -RUN cd /root/go/src/github.com/refraction-networking/conjure && \ |
48 | | - go get ./... || true && \ |
49 | | - make |
50 | | - |
51 | | -# Copy results |
52 | | -RUN cp -r /root/go/src/github.com/refraction-networking/conjure /opt/conjure |
53 | | - |
54 | | - |
55 | | - |
56 | | -FROM ubuntu:20.04 as zbalance |
57 | | -ENV CJ_IFACE=lo \ |
58 | | - CJ_CLUSTER_ID=98 \ |
59 | | - CJ_CORECOUNT=1 \ |
60 | | - CJ_COREBASE=0 \ |
61 | | - ZBALANCE_HASH_MODE=1 |
62 | | -#COPY --from=build_base /opt/PF_RING /opt/PF_RING |
63 | | - |
64 | | -RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get -y -q install libelf1 |
65 | | - |
66 | | -COPY --from=build_base_go /usr/bin/zbalance_ipc /usr/bin/zbalance_ipc |
67 | | -COPY ./docker/zbalance-entrypoint.sh /entrypoint.sh |
68 | | -ENTRYPOINT ["bash", "/entrypoint.sh"] |
69 | | - |
70 | | - |
71 | | - |
72 | | - |
73 | | -FROM ubuntu:20.04 as detector |
74 | | -ENV CJ_CLUSTER_ID=98 \ |
75 | | - CJ_CORECOUNT=1 \ |
76 | | - CJ_COREBASE=0 \ |
77 | | - CJ_SKIP_CORE=-1 \ |
78 | | - CJ_QUEUE_OFFSET=0 \ |
79 | | - CJ_LOG_INTERVAL=5 \ |
80 | | - CJ_PRIVKEY=/opt/conjure/keys/privkey \ |
81 | | - CJ_STATION_CONFIG=/opt/conjure/application/config.toml \ |
82 | | - CJ_IP4_ADDR=127.0.0.1 \ |
83 | | - CJ_IP6_ADDR=[::1] |
84 | | -#COPY --from=build_base_go /opt/conjure/dark-decoy /opt/conjure/dark-decoy |
85 | | -COPY --from=build_base_go /opt/conjure/conjure /opt/conjure/conjure |
86 | | -COPY --from=build_base_go /opt/conjure/application/config.toml /opt/conjure/application/config.toml |
87 | | -COPY ./docker/detector-entrypoint.sh /entrypoint.sh |
88 | | -COPY --from=build_base_go /usr/local/lib/libpcap.so /usr/local/lib/libpcap.so |
89 | | - |
90 | | -RUN apt-get update && apt-get -y -q install libzmq3-dev iproute2 iptables && apt-get clean all |
91 | | -ENTRYPOINT [ "/entrypoint.sh"] |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | | -FROM ubuntu:20.04 as application |
97 | | -ENV CJ_STATION_CONFIG=/opt/conjure/application/config.toml \ |
98 | | - PHANTOM_SUBNET_LOCATION=/opt/conjure/sysconfig/phantom_subnets.toml |
99 | | -COPY --from=build_base_go /opt/conjure/application/application /opt/conjure/application/application |
100 | | -RUN apt-get update && apt-get -y -q install libzmq3-dev && apt-get clean all |
101 | | -COPY --from=build_base_go /opt/conjure/application/config.toml ${CJ_STATION_CONFIG} |
102 | | -COPY --from=build_base_go /opt/conjure/application/lib/test/phantom_subnets.toml ${PHANTOM_SUBNET_LOCATION} |
103 | | -#COPY ./docker/application-entrypoint.sh /entrypoint.sh |
104 | | -ENTRYPOINT [ "/opt/conjure/application/application"] |
| 1 | +# syntax=docker/dockerfile:1.3-labs |
| 2 | + |
| 3 | +FROM ubuntu:20.04 AS base_pfring |
| 4 | +ARG UNAME=conjure |
| 5 | +ARG UID=1000 |
| 6 | +ARG GID=1000 |
| 7 | +RUN groupadd -g $GID -o $UNAME |
| 8 | +RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME |
| 9 | + |
| 10 | +RUN apt-get update && apt-get install -yq sudo apt-utils software-properties-common |
| 11 | + |
| 12 | +# install pf_ring deps |
| 13 | + |
| 14 | +COPY scripts/install_pfring.sh / |
| 15 | +ARG pfring_ver="latest" |
| 16 | +RUN /usr/bin/sudo pfring_ver="${pfring_ver}" /install_pfring.sh |
| 17 | + |
| 18 | +# ------------------------------------------------------------------------------ |
| 19 | +# Development image |
| 20 | +# |
| 21 | +# Builds a common image that has all dependencies required to build and run |
| 22 | +# any piece of the station. Ideally we want to redo this as little as possible. |
| 23 | +# ------------------------------------------------------------------------------ |
| 24 | +FROM base_pfring AS dev_img |
| 25 | + |
| 26 | +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata |
| 27 | +COPY prereqs_once.sh /opt/conjure/ |
| 28 | + |
| 29 | +WORKDIR /opt/conjure |
| 30 | +ENV is_docker_build YES |
| 31 | +RUN /usr/bin/sudo ./prereqs_once.sh |
| 32 | + |
| 33 | +WORKDIR /opt/conjure |
| 34 | + |
| 35 | +COPY Makefile *.c *.h /opt/conjure/ |
| 36 | +COPY libtapdance/ /opt/conjure/libtapdance |
| 37 | +RUN make libtd |
| 38 | + |
| 39 | +# run cargo build to allow for dependencies to cached |
| 40 | +RUN PATH="$HOME/.cargo/bin:$PATH" cargo init --lib . |
| 41 | +COPY Cargo.toml build.rs /opt/conjure/ |
| 42 | +RUN --mount=type=cache,target=/usr/local/cargo/registry PATH="$HOME/.cargo/bin:$PATH" cargo build --release |
| 43 | + |
| 44 | +COPY src/ /opt/conjure/src |
| 45 | + |
| 46 | +# A bit of magic here! |
| 47 | +# * We're mounting that cache again to use during the build, otherwise it's not present and we'll have to download those again - bad! |
| 48 | +# * EOF syntax is neat but not without its drawbacks. We need to `set -e`, otherwise a failing command is going to continue on |
| 49 | +# * Rust here is a bit fiddly, so we'll touch the files (even though we copied over them) to force a new build |
| 50 | +RUN --mount=type=cache,target=/usr/local/cargo/registry <<EOF |
| 51 | +set -e |
| 52 | +# update timestamps to force a new build |
| 53 | +touch /opt/conjure/src/lib.rs |
| 54 | +PATH="$HOME/.cargo/bin:$PATH" make rust |
| 55 | +EOF |
| 56 | + |
| 57 | +RUN PATH="$HOME/.cargo/bin:$PATH" make conjure-sim && mv conjure conjure-sim |
| 58 | +RUN PATH="$HOME/.cargo/bin:$PATH" make conjure |
| 59 | + |
| 60 | +COPY go.* /opt/conjure/ |
| 61 | +COPY cmd/ /opt/conjure/cmd |
| 62 | +COPY application/ /opt/conjure/application |
| 63 | +COPY pkg/ /opt/conjure/pkg |
| 64 | + |
| 65 | +RUN PATH="$HOME/.go/bin/:$PATH" make app |
| 66 | +RUN PATH="$HOME/.go/bin/:$PATH" make registration-server |
| 67 | + |
| 68 | +# Add default configs and launch scripts |
| 69 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 70 | +COPY scripts/ /opt/conjure/bin |
| 71 | + |
| 72 | +# add application as default entrypoint for dev reasons. |
| 73 | +ENTRYPOINT /opt/conjure/application/application |
| 74 | + |
| 75 | + |
| 76 | +# ------------------------------------------------------------------------------ |
| 77 | +# Production image zbalance only |
| 78 | +# ------------------------------------------------------------------------------ |
| 79 | +FROM base_pfring as conjure_zbalance |
| 80 | +# Add default configs and launch scripts |
| 81 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 82 | +COPY scripts/ /opt/conjure/bin |
| 83 | + |
| 84 | +ENTRYPOINT /opt/conjure/bin/start_zbalance_ipc.sh |
| 85 | + |
| 86 | + |
| 87 | +# ------------------------------------------------------------------------------ |
| 88 | +# Production image detector only (kind of, requires pfring) |
| 89 | +# ------------------------------------------------------------------------------ |
| 90 | +FROM base_pfring as conjure_det |
| 91 | +# Add default configs and launch scripts |
| 92 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 93 | +COPY scripts/ /opt/conjure/bin |
| 94 | + |
| 95 | +RUN apt update && apt install -yq libzmq3-dev |
| 96 | +COPY --from=dev_img /opt/conjure/conjure /opt/conjure/bin/ |
| 97 | + |
| 98 | + |
| 99 | +# ------------------------------------------------------------------------------ |
| 100 | +# Production image application only |
| 101 | +# ------------------------------------------------------------------------------ |
| 102 | +FROM ubuntu:20.04 as conjure_app |
| 103 | +# Add default configs and launch scripts |
| 104 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 105 | +COPY scripts/ /opt/conjure/bin |
| 106 | +COPY application/ /opt/conjure/application |
| 107 | + |
| 108 | +RUN apt update && apt install -yq libzmq3-dev |
| 109 | +COPY --from=dev_img /opt/conjure/application/application /opt/conjure/bin/ |
| 110 | + |
| 111 | + |
| 112 | +# ------------------------------------------------------------------------------ |
| 113 | +# Production image registration server only |
| 114 | +# ------------------------------------------------------------------------------ |
| 115 | +FROM ubuntu:20.04 as conjure_reg |
| 116 | +# Add default configs and launch scripts |
| 117 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 118 | +COPY scripts/ /opt/conjure/bin |
| 119 | + |
| 120 | +RUN apt update && apt install -yq libzmq3-dev |
| 121 | +COPY --from=dev_img /opt/conjure/cmd/registration-server/registration-server /opt/conjure/bin/ |
| 122 | + |
| 123 | + |
| 124 | +# ------------------------------------------------------------------------------ |
| 125 | +# Simulation image (no pfring required) |
| 126 | +# ------------------------------------------------------------------------------ |
| 127 | +FROM ubuntu:20.04 as conjure_sim |
| 128 | +# Add default configs and launch scripts |
| 129 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 130 | +COPY scripts/ /opt/conjure/bin |
| 131 | + |
| 132 | +RUN apt update && apt install -yq libzmq3-dev |
| 133 | +COPY --from=dev_img /opt/conjure/conjure-sim /opt/conjure/bin/conjure |
| 134 | +COPY --from=dev_img /opt/conjure/cmd/registration-server/registration-server /opt/conjure/bin/ |
| 135 | +COPY --from=dev_img /opt/conjure/conjure /opt/conjure/bin/ |
| 136 | + |
| 137 | + |
| 138 | +# ------------------------------------------------------------------------------ |
| 139 | +# Production image all (default) |
| 140 | +# ------------------------------------------------------------------------------ |
| 141 | +FROM base_pfring as conjure |
| 142 | +# Add default configs and launch scripts |
| 143 | +COPY sysconfig/ /opt/conjure/sysconfig |
| 144 | +COPY scripts/ /opt/conjure/bin |
| 145 | +COPY application/ /opt/conjure/application |
| 146 | + |
| 147 | +RUN apt update && apt install -yq libzmq3-dev |
| 148 | +COPY --from=dev_img /opt/conjure/application/application /opt/conjure/bin/ |
| 149 | +COPY --from=dev_img /opt/conjure/cmd/registration-server/registration-server /opt/conjure/bin/ |
| 150 | +COPY --from=dev_img /opt/conjure/conjure /opt/conjure/bin/ |
| 151 | + |
| 152 | +# ENTRYPOINT /bin/bash |
0 commit comments