Skip to content

Commit

Permalink
[docker] add docker support (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjc13 authored and jwhui committed Sep 6, 2018
1 parent cf014e9 commit 7b9c3da
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 6 deletions.
48 changes: 48 additions & 0 deletions etc/Dockerfile
@@ -0,0 +1,48 @@
# Copyright (c) 2018, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

FROM ubuntu

WORKDIR /app/borderrouter

ADD . /app/borderrouter

RUN apt-get -y update

RUN apt-get install -y sudo lsb-core

RUN cd /app/borderrouter && NAT64=1 ./script/bootstrap && ./bootstrap

RUN cd /app/borderrouter && ./configure --with-dbusconfdir="/etc/" && make -j8 && make install

RUN cd /app/borderrouter && NAT64=1 ./script/setup

RUN chmod 644 /etc/bind/named.conf.options

ENTRYPOINT ["/app/borderrouter/script/docker_entrypoint.sh"]

EXPOSE 80
14 changes: 11 additions & 3 deletions script/_dns64
Expand Up @@ -66,23 +66,27 @@ dns64_install()
with NAT64 && with DNS64 || return 0

test -f $BIND_CONF_OPTIONS || die 'Cannot find bind9 configuration file!'
sudo sed -i '/^};/i\\tallow-recursion { any; };' $BIND_CONF_OPTIONS
sudo sed -i '/^};/i\\tlisten-on-v6 { any; };' $BIND_CONF_OPTIONS
sudo sed -i '/^};/i\\tallow-query { any; };' $BIND_CONF_OPTIONS
sudo sed -i '/^};/i\\tforwarders { 8.8.8.8; 8.8.8.4; };' $BIND_CONF_OPTIONS
sudo sed -i '/^};/i\\tforward only;' $BIND_CONF_OPTIONS
sudo sed -i '/^};/i\\t'"$DNS64_CONF" $BIND_CONF_OPTIONS

sudo sh -c "echo \"nameserver $DNS64_NAMESERVER_ADDR\" >> $RESOLV_CONF_HEAD"
[ -f /.dockerenv ] || sudo sh -c "echo \"nameserver $DNS64_NAMESERVER_ADDR\" >> $RESOLV_CONF_HEAD"

if have systemctl; then
sudo systemctl enable bind9 || true
sudo systemctl is-enabled bind9 || die 'Failed to enable bind9!'
sudo systemctl start bind9 || die 'Failed to start bind9!'
fi

dns64_update_resolvconf
[ -f /.dockerenv ] || dns64_update_resolvconf
}

dns64_uninstall()
{
with NAT64 && with DNS64 || return 0
[ ! -f /.dockerenv ] || return 0

dns64_stop
sudo sed -i '/^\tallow-recursion/d' $BIND_CONF_OPTIONS
Expand All @@ -104,6 +108,8 @@ dns64_start()

if have systemctl; then
sudo systemctl start bind9 || die 'Failed to start bind9!'
elif which service; then
sudo service bind9 start || die 'Failed to start bind9!'
fi
}

Expand All @@ -113,5 +119,7 @@ dns64_stop()

if have systemctl; then
sudo systemctl stop bind9 || true
elif which service; then
sudo service bind9 stop || true
fi
}
10 changes: 7 additions & 3 deletions script/_nat64
Expand Up @@ -38,7 +38,7 @@ WLAN_IFNAMES=eth0

# Currently solution was verified only on raspbian and ubuntu.
#
without NAT64 || test $PLATFORM = ubuntu || test $PLATFORM = raspbian || die "nat64 is not tested under $PLATFORM."
#without NAT64 || test $PLATFORM = ubuntu || test $PLATFORM = raspbian || die "nat64 is not tested under $PLATFORM."

nat64_install()
{
Expand Down Expand Up @@ -147,7 +147,9 @@ nat64_start()
{
with NAT64 || return 0

if have systemctl; then
if [ -f /.dockerenv ]; then
service tayga start || die 'Failed to start tayga'
elif have systemctl; then
sudo systemctl start tayga || die 'Failed to start tayga!'
sudo systemctl start otbr-nat44 || die 'Failed to start NAT44!'
fi
Expand All @@ -157,7 +159,9 @@ nat64_stop()
{
with NAT64 || return 0

if have systemctl; then
if [ -f /.dockerenv ]; then
service tayga stop || true
elif have systemctl; then
sudo systemctl stop tayga || true
sudo systemctl stop otbr-nat44 || true
fi
Expand Down
5 changes: 5 additions & 0 deletions script/bootstrap
Expand Up @@ -35,6 +35,11 @@
install_packages_apt()
{
sudo apt-get update
sudo apt-get install -y \
wget \
iproute2 \
inetutils-ping \
apt-utils
sudo apt-get install -y build-essential libtool git

with RELEASE || sudo apt-get install -y cmake
Expand Down
102 changes: 102 additions & 0 deletions script/docker_entrypoint.sh
@@ -0,0 +1,102 @@
#!/bin/bash
#
# Copyright (c) 2018, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH

function parse_args()
{
while [ $# -gt 0 ]
do
echo $1
case $1 in
--ncp-path)
NCP_PATH=$2
shift
shift
;;
--interface|-I)
TUN_INTERFACE_NAME=$2
shift
shift
;;
--nat64-prefix)
NAT64_PREFIX=$2
shift
shift
;;
--disable-default-prefix-route)
AUTO_PREFIX_ROUTE=false
shift
;;
--disable-default-prefix-slaac)
AUTO_PREFIX_SLAAC=false
shift
;;
*)
shift
;;
esac
done
}

parse_args "$@"

[ -n "$NCP_PATH" ] || NCP_PATH="/dev/ttyUSB0"
[ -n "$TUN_INTERFACE_NAME" ] || TUN_INTERFACE_NAME="wpan0"
[ -n "$AUTO_PREFIX_ROUTE" ] || AUTO_PREFIX_ROUTE=true
[ -n "$AUTO_PREFIX_SLAAC" ] || AUTO_PREFIX_SLAAC=true
[ -n "$NAT64_PREFIX" ] || NAT64_PREFIX="64:ff9b::/96"

echo "NCP_PATH:" $NCP_PATH
echo "TUN_INTERFACE_NAME:" $TUN_INTERFACE_NAME
echo "NAT64_PREFIX:" $NAT64_PREFIX
echo "AUTO_PREFIX_ROUTE:" $AUTO_PREFIX_ROUTE
echo "AUTO_PREFIX_SLAAC:" $AUTO_PREFIX_SLAAC

NAT64_PREFIX=${NAT64_PREFIX/\//\\\/}

sed -i "s/^prefix.*$/prefix $NAT64_PREFIX/" /etc/tayga.conf
sed -i "s/dns64.*{/dns64 $NAT64_PREFIX {/" /etc/bind/named.conf.options

service dbus start
service bind9 start
service tayga start
wpantund \
-o Config:NCP:SocketPath "$NCP_PATH" \
-o Config:TUN:InterfaceName $TUN_INTERFACE_NAME \
-o Daemon:SetDefaultRouteForAutoAddedPrefix $AUTO_PREFIX_ROUTE \
-o IPv6:SetSLAACForAutoAddedPrefix $AUTO_PREFIX_SLAAC &

sleep 5

/usr/local/sbin/otbr-agent -I $TUN_INTERFACE_NAME &

/usr/local/sbin/otbr-web -I $TUN_INTERFACE_NAME -p 80 &

wait

0 comments on commit 7b9c3da

Please sign in to comment.