1#  Copyright (c) 2022, The OpenThread Authors.
2#  All rights reserved.
3#
4#  Redistribution and use in source and binary forms, with or without
5#  modification, are permitted provided that the following conditions are met:
6#  1. Redistributions of source code must retain the above copyright
7#     notice, this list of conditions and the following disclaimer.
8#  2. Redistributions in binary form must reproduce the above copyright
9#     notice, this list of conditions and the following disclaimer in the
10#     documentation and/or other materials provided with the distribution.
11#  3. Neither the name of the copyright holder nor the
12#     names of its contributors may be used to endorse or promote products
13#     derived from this software without specific prior written permission.
14#
15#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25#  POSSIBILITY OF SUCH DAMAGE.
26#
27
28ARG BASE_IMAGE=ubuntu:focal
29FROM ${BASE_IMAGE}
30
31ARG INFRA_IF_NAME
32ARG BORDER_ROUTING
33ARG BACKBONE_ROUTER
34ARG OTBR_OPTIONS
35ARG EXTERNAL_COMMISSIONER
36ARG DNS64
37ARG NAT64
38ARG NAT64_SERVICE
39ARG REFERENCE_DEVICE
40ARG REST_API
41ARG WEB_GUI
42ARG MDNS
43
44ENV INFRA_IF_NAME=${INFRA_IF_NAME:-eth0}
45ENV BORDER_ROUTING=${BORDER_ROUTING:-1}
46ENV BACKBONE_ROUTER=${BACKBONE_ROUTER:-1}
47ENV OTBR_MDNS=${MDNS:-mDNSResponder}
48ENV OTBR_OPTIONS=${OTBR_OPTIONS}
49ENV EXTERNAL_COMMISSIONER=${EXTERNAL_COMMISSIONER:-1}
50ENV DEBIAN_FRONTEND noninteractive
51ENV PLATFORM ubuntu
52ENV REFERENCE_DEVICE=${REFERENCE_DEVICE:-0}
53ENV NAT64=${NAT64:-1}
54ENV NAT64_SERVICE=${NAT64_SERVICE:-tayga}
55ENV DNS64=${DNS64:-0}
56ENV WEB_GUI=${WEB_GUI:-1}
57ENV REST_API=${REST_API:-1}
58ENV DOCKER 1
59
60RUN env
61
62COPY . /app
63WORKDIR /app
64
65# Required during build or run
66ENV OTBR_DOCKER_REQS sudo python2 python3 python-is-python2
67
68# Required during build, could be removed
69ENV OTBR_DOCKER_DEPS git ca-certificates python3-pip wget
70
71# Required during run python scripts
72ENV OTBR_PYTHON_REQS zeroconf
73
74# Required and installed during build (script/bootstrap), could be removed
75ENV OTBR_BUILD_DEPS apt-utils build-essential psmisc ninja-build cmake ca-certificates \
76  libreadline-dev libncurses-dev libcpputest-dev libdbus-1-dev libavahi-common-dev \
77  libavahi-client-dev libboost-dev libboost-filesystem-dev libboost-system-dev \
78  libnetfilter-queue-dev
79
80RUN apt-get update \
81  && cp -r ./root/. / \
82  && rm -rf ./root \
83  && apt-get install --no-install-recommends -y $OTBR_DOCKER_REQS $OTBR_DOCKER_DEPS \
84  && wget -P /tmp "https://bootstrap.pypa.io/pip/2.7/get-pip.py" \
85  && python2 /tmp/get-pip.py \
86  && pip2 install -r /tmp/requirements.txt \
87  && pip3 install $OTBR_PYTHON_REQS \
88  && ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
89  && ([ "${EXTERNAL_COMMISSIONER}" != "1" ] || ( \
90    git clone https://github.com/openthread/ot-commissioner.git --recurse-submodules --shallow-submodules --depth=1 \
91    && cd ot-commissioner \
92    && ./script/bootstrap.sh \
93    && mkdir -p build \
94    && cd build \
95    && cmake -GNinja -DCMAKE_INSTALL_PREFIX="/usr/local" -DOT_COMM_REFERENCE_DEVICE=ON .. \
96    && ninja \
97    && ninja install \
98    && cd /app \
99    && rm -rf ot-commissioner \
100  )) \
101  && ./script/bootstrap \
102  && ./script/setup \
103  && ([ "${DNS64}" = "0" ] || chmod 644 /etc/bind/named.conf.options) \
104  && mv ./script /tmp \
105  && mv ./etc /tmp \
106  && find . -delete \
107  && rm -rf /usr/include \
108  && mv /tmp/script . \
109  && mv /tmp/etc . \
110  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $OTBR_DOCKER_DEPS \
111  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $OTBR_BUILD_DEPS  \
112  && rm -rf /var/lib/apt/lists/* \
113  && rm -rf /tmp/* \
114  && sed -i "s/\/root/\/home\/pi/g" /etc/passwd
115  # The command above changes root home directory to /home/pi
116
117ENTRYPOINT ["/app/etc/docker/docker_entrypoint.sh"]
118
119EXPOSE 80
120