From cab217128384821f9a256574e6046d6925d6a1e4 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Thu, 9 Dec 2021 10:47:26 +0800 Subject: [PATCH 1/9] Update submodule Alcor to latest version --- alcor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alcor b/alcor index f3fd109c..97fc7b84 160000 --- a/alcor +++ b/alcor @@ -1 +1 @@ -Subproject commit f3fd109c65b6b80a960ef4aabb743f8a92788047 +Subproject commit 97fc7b8482320f121889dd4211f71b29a77d6275 From d5286cbd62014ac684c56ac058dd7344f26a2d13 Mon Sep 17 00:00:00 2001 From: VanderChen Date: Wed, 30 Mar 2022 16:12:01 +0800 Subject: [PATCH 2/9] Split download and install --- build/aca-machine-init-local.sh | 263 ++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100755 build/aca-machine-init-local.sh diff --git a/build/aca-machine-init-local.sh b/build/aca-machine-init-local.sh new file mode 100755 index 00000000..a9d86e21 --- /dev/null +++ b/build/aca-machine-init-local.sh @@ -0,0 +1,263 @@ +#!/bin/bash + +# MIT License +# Copyright(c) 2020 Futurewei Cloud +# +# Permission is hereby granted, +# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +# to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +echo "build path is $BUILD" + +function download_dependencis { + rm -rf /var/local/git + mkdir -p /var/local/git + + echo "d.3--- re-downloading cppkafka ---" && \ + rm -rf /var/local/git/cppkafka + git clone https://github.com/mfontanini/cppkafka.git /var/local/git/cppkafka + + GRPC_RELEASE_TAG="v1.24.x" + echo "d.5--- re-downloading grpc repo ---" && \ + rm -rf /var/local/git/grpc && \ + git clone -b $GRPC_RELEASE_TAG https://github.com/grpc/grpc /var/local/git/grpc + cd /var/local/git/grpc && \ + git submodule update --init && \ + cd /var/local/git/grpc/third_party/cares/cares && \ + git fetch origin && \ + git checkout cares-1_15_0 && \ + + + echo "d.6--- re-downloading openvswitch ---" && \ + rm -rf /var/local/git/openvswitch && \ + git clone -b "branch-2.12" https://github.com/openvswitch/ovs.git /var/local/git/openvswitch && \ + cd /var/local/git/openvswitch && \ + wget https://www.openvswitch.org/releases/openvswitch-2.9.8.tar.gz && \ + tar -xvzf openvswitch-2.9.8.tar.gz + + echo "d.7--- re-dowloading marl---" && \ + rm -rf /var/local/git/marl && \ + mkdir -p /var/local/git/marl && \ + cd /var/local/git/marl && \ + git clone https://github.com/google/marl.git && \ + cd /var/local/git/marl/marl && \ + git submodule update --init + + PULSAR_RELEASE_TAG='pulsar-2.8.1' + echo "d.8--- re-downloading pulsar dependacies ---" && \ + mkdir -p /var/local/git/pulsar && \ + wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client.deb -O /var/local/git/pulsar/apache-pulsar-client.deb && \ + wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client-dev.deb -O /var/local/git/pulsar/apache-pulsar-client-dev.deb +} + +function install_dependencis { + + # TODO: remove the unneeded dependencies + echo "1--- installing common dependencies ---" && \ + apt-get update -y && apt-get install -y \ + rpcbind \ + rsyslog \ + build-essential \ + make \ + g++ \ + unzip \ + cmake \ + clang-9 \ + llvm-9 \ + libelf-dev \ + doxygen \ + zlib1g-dev \ + libssl-dev \ + libboost-program-options-dev \ + libboost-all-dev \ + iproute2 \ + net-tools \ + iputils-ping \ + ethtool \ + curl \ + python3 \ + python3-pip \ + netcat \ + libcmocka-dev \ + lcov \ + git \ + autoconf \ + automake \ + dh-autoreconf \ + pkg-config \ + libtool \ + wget \ + uuid-dev + pip3 install httpserver netaddr + + echo "2--- installing librdkafka ---" && \ + apt-get update -y && apt-get install -y --no-install-recommends\ + librdkafka-dev \ + doxygen \ + libssl-dev \ + zlib1g-dev \ + libboost-program-options-dev \ + libboost-all-dev \ + && apt-get clean + + echo "3--- installing cppkafka ---" && \ + apt-get update -y && apt-get install -y cmake + cd /var/local/git/cppkafka && \ + mkdir build && \ + cd build && \ + cmake .. && \ + make && \ + make install && \ + ldconfig && \ + cd ~ + + echo "4--- installing grpc dependencies ---" && \ + apt-get update -y && apt-get install -y \ + cmake libssl-dev \ + autoconf git pkg-config \ + automake libtool make g++ unzip + + # installing grpc and its dependencies + echo "5--- cloning grpc repo ---" && \ + echo "--- installing c-ares ---" && \ + cd /var/local/git/grpc/third_party/cares/cares && \ + mkdir -p cmake/build && \ + cd cmake/build && \ + cmake -DCMAKE_BUILD_TYPE=Release ../.. && \ + make -j4 install && \ + cd ../../../../.. && \ + echo "--- installing protobuf ---" && \ + cd /var/local/git/grpc/third_party/protobuf && \ + mkdir -p cmake/build && \ + cd cmake/build && \ + cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. && \ + make -j4 install && \ + cd ../../../.. && \ + echo "--- installing grpc ---" && \ + cd /var/local/git/grpc && \ + mkdir -p cmake/build && \ + cd cmake/build && \ + cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. && \ + make -j4 install && \ + echo "--- installing google test ---" && \ + cd /var/local/git/grpc/third_party/googletest && \ + cmake -Dgtest_build_samples=ON -DBUILD_SHARED_LIBS=ON . && \ + make && \ + make install && \ + cd ~ + + OVS_INCLUDE_HEADERS="include/openvswitch/compiler.h \ + include/openvswitch/dynamic-string.h \ + include/openvswitch/hmap.h \ + include/openvswitch/flow.h \ + include/openvswitch/geneve.h \ + include/openvswitch/json.h \ + include/openvswitch/list.h \ + include/openvswitch/netdev.h \ + include/openvswitch/match.h \ + include/openvswitch/meta-flow.h \ + include/openvswitch/ofpbuf.h \ + include/openvswitch/ofp-actions.h \ + include/openvswitch/ofp-ed-props.h \ + include/openvswitch/ofp-errors.h \ + include/openvswitch/ofp-msgs.h \ + include/openvswitch/ofp-parse.h \ + include/openvswitch/ofp-print.h \ + include/openvswitch/ofp-prop.h \ + include/openvswitch/ofp-util.h \ + include/openvswitch/packets.h \ + include/openvswitch/poll-loop.h \ + include/openvswitch/rconn.h \ + include/openvswitch/shash.h \ + include/openvswitch/thread.h \ + include/openvswitch/token-bucket.h \ + include/openvswitch/tun-metadata.h \ + include/openvswitch/type-props.h \ + include/openvswitch/types.h \ + include/openvswitch/util.h \ + include/openvswitch/uuid.h \ + include/openvswitch/version.h \ + include/openvswitch/vconn.h \ + include/openvswitch/vlog.h \ + include/openvswitch/nsh.h " + OPENFLOW_HEADERS="include/openflow/intel-ext.h \ + include/openflow/netronome-ext.h \ + include/openflow/nicira-ext.h \ + include/openflow/openflow-1.0.h \ + include/openflow/openflow-1.1.h \ + include/openflow/openflow-1.2.h \ + include/openflow/openflow-1.3.h \ + include/openflow/openflow-1.4.h \ + include/openflow/openflow-1.5.h \ + include/openflow/openflow-1.6.h \ + include/openflow/openflow-common.h \ + include/openflow/openflow.h " + echo "6--- installing openvswitch dependancies ---" && \ + sudo rm -f /tmp/get-pip.py > /dev/null 2>&1 && \ + sudo apt-get install -y python2.7 && \ + sudo wget https://bootstrap.pypa.io/pip/2.7/get-pip.py -O /tmp/get-pip.py && \ + sudo python2.7 /tmp/get-pip.py && \ + sudo pip2 install six && \ + apt-get install -y libevent-dev && \ + mkdir -p /var/local/git/openvswitch && \ + cd /var/local/git/openvswitch && \ + ./boot.sh && \ + ./configure --prefix=/usr/local --localstatedir=/var --sysconfdir=/etc --enable-shared --enable-ndebug && \ + make && \ + make install && \ + cp ./lib/vconn-provider.h /usr/local/include/openvswitch && \ + cp ./include/openvswitch/namemap.h /usr/local/include/openvswitch && \ + cd /var/local/git/openvswitch && \ + cd openvswitch-2.9.8 && \ + ./configure && make && \ + cp $OVS_INCLUDE_HEADERS /usr/local/include/openvswitch && \ + cp $OPENFLOW_HEADERS /usr/local/include/openflow && \ + cp ./lib/.libs/libopenvswitch.a /usr/local/lib/ && \ + test -f /usr/bin/ovs-vsctl && rm -rf /usr/local/sbin/ov* /usr/local/bin/ov* /usr/local/bin/vtep* && \ + cd ~ + + echo "7--- installing marl ---" && \ + cd /var/local/git/marl/marl && \ + mkdir /var/local/git/marl/marl/build && \ + cd /var/local/git/marl/marl/build && \ + cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 && \ + make && \ + cd ~ + + PULSAR_RELEASE_TAG='pulsar-2.8.1' + echo "8--- installing pulsar dependacies ---" && \ + cd /var/local/git/pulsar && \ + apt install -y ./apache-pulsar-client*.deb + cd ~ + + echo "9--- building alcor-control-agent" + cd $BUILD/.. && cmake . && \ + # after cmake ., modify the generated link.txt s so that the "-lssl" and "-lcrypto" appears after the openvswitch, so that it can compile + sed -i 's/\(-ldl -lrt -lm -lpthread\)/-lssl -lcrypto \1/' src/CMakeFiles/AlcorControlAgent.dir/link.txt && \ + sed -i 's/\(-ldl -lrt -lm -lpthread\)/-lssl -lcrypto \1/' test/CMakeFiles/aca_tests.dir/link.txt && \ + sed -i 's/\(-ldl -lrt -lm -lpthread\)/-lssl -lcrypto \1/' test/CMakeFiles/gs_tests.dir/link.txt && \ + make + if [ -n "$1" -a "$1" = "delete-bridges" ]; then + echo "10--- deleting br-tun and br-int if requested" + PATH=$PATH:/usr/local/share/openvswitch/scripts \ + LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib + ovs-ctl --system-id=random --delete-bridges restart + fi + + echo "11--- running alcor-control-agent" + # kill current AlcorControlAgent process if any + pkill -f AlcorControlAgent + # launch newly built AlcorControlAgent with default debug mode as 'false' + # sends output to null device, but stderr to console + nohup $BUILD/bin/AlcorControlAgent > /dev/null 2>&1 & +} + +download_dependencis \ No newline at end of file From 070b0385470987ec4f8dc91a59418f6c903491ee Mon Sep 17 00:00:00 2001 From: Min Chen Date: Fri, 1 Apr 2022 11:54:14 +0800 Subject: [PATCH 3/9] Update aca-machine-init-local.sh --- build/aca-machine-init-local.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/aca-machine-init-local.sh b/build/aca-machine-init-local.sh index a9d86e21..f7ce30f7 100755 --- a/build/aca-machine-init-local.sh +++ b/build/aca-machine-init-local.sh @@ -260,4 +260,5 @@ function install_dependencis { nohup $BUILD/bin/AlcorControlAgent > /dev/null 2>&1 & } -download_dependencis \ No newline at end of file +#download_dependencis +install_dependencis From 36d75608942660dad16de8c1b592333b0cf68c72 Mon Sep 17 00:00:00 2001 From: VanderChen Date: Thu, 21 Apr 2022 14:16:07 +0800 Subject: [PATCH 4/9] Update aca-init scripts --- build/aca-machine-init-local.sh | 103 +++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/build/aca-machine-init-local.sh b/build/aca-machine-init-local.sh index f7ce30f7..b5ca6bb0 100755 --- a/build/aca-machine-init-local.sh +++ b/build/aca-machine-init-local.sh @@ -14,48 +14,45 @@ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -echo "build path is $BUILD" - function download_dependencis { - rm -rf /var/local/git - mkdir -p /var/local/git + rm -rf ${DEP_PATH} + mkdir -p ${DEP_PATH} echo "d.3--- re-downloading cppkafka ---" && \ - rm -rf /var/local/git/cppkafka - git clone https://github.com/mfontanini/cppkafka.git /var/local/git/cppkafka + rm -rf ${DEP_PATH}/cppkafka + git clone https://github.com/mfontanini/cppkafka.git ${DEP_PATH}/cppkafka GRPC_RELEASE_TAG="v1.24.x" echo "d.5--- re-downloading grpc repo ---" && \ - rm -rf /var/local/git/grpc && \ - git clone -b $GRPC_RELEASE_TAG https://github.com/grpc/grpc /var/local/git/grpc - cd /var/local/git/grpc && \ + rm -rf ${DEP_PATH}/grpc && \ + git clone -b $GRPC_RELEASE_TAG https://github.com/grpc/grpc ${DEP_PATH}/grpc + cd ${DEP_PATH}/grpc && \ git submodule update --init && \ - cd /var/local/git/grpc/third_party/cares/cares && \ + cd ${DEP_PATH}/grpc/third_party/cares/cares && \ git fetch origin && \ - git checkout cares-1_15_0 && \ + git checkout cares-1_15_0 echo "d.6--- re-downloading openvswitch ---" && \ - rm -rf /var/local/git/openvswitch && \ - git clone -b "branch-2.12" https://github.com/openvswitch/ovs.git /var/local/git/openvswitch && \ - cd /var/local/git/openvswitch && \ + rm -rf ${DEP_PATH}/openvswitch && \ + git clone -b "branch-2.12" https://github.com/openvswitch/ovs.git ${DEP_PATH}/openvswitch && \ + cd ${DEP_PATH}/openvswitch && \ wget https://www.openvswitch.org/releases/openvswitch-2.9.8.tar.gz && \ tar -xvzf openvswitch-2.9.8.tar.gz echo "d.7--- re-dowloading marl---" && \ - rm -rf /var/local/git/marl && \ - mkdir -p /var/local/git/marl && \ - cd /var/local/git/marl && \ + rm -rf ${DEP_PATH}/marl && \ + mkdir -p ${DEP_PATH}/marl && \ + cd ${DEP_PATH}/marl && \ git clone https://github.com/google/marl.git && \ - cd /var/local/git/marl/marl && \ + cd ${DEP_PATH}/marl/marl && \ git submodule update --init PULSAR_RELEASE_TAG='pulsar-2.8.1' echo "d.8--- re-downloading pulsar dependacies ---" && \ - mkdir -p /var/local/git/pulsar && \ - wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client.deb -O /var/local/git/pulsar/apache-pulsar-client.deb && \ - wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client-dev.deb -O /var/local/git/pulsar/apache-pulsar-client-dev.deb + mkdir -p ${DEP_PATH}/pulsar && \ + wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client.deb -O ${DEP_PATH}/pulsar/apache-pulsar-client.deb && \ + wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client-dev.deb -O ${DEP_PATH}/pulsar/apache-pulsar-client-dev.deb } function install_dependencis { @@ -110,7 +107,7 @@ function install_dependencis { echo "3--- installing cppkafka ---" && \ apt-get update -y && apt-get install -y cmake - cd /var/local/git/cppkafka && \ + cd ${DEP_PATH}/cppkafka && \ mkdir build && \ cd build && \ cmake .. && \ @@ -128,27 +125,27 @@ function install_dependencis { # installing grpc and its dependencies echo "5--- cloning grpc repo ---" && \ echo "--- installing c-ares ---" && \ - cd /var/local/git/grpc/third_party/cares/cares && \ + cd ${DEP_PATH}/grpc/third_party/cares/cares && \ mkdir -p cmake/build && \ cd cmake/build && \ cmake -DCMAKE_BUILD_TYPE=Release ../.. && \ make -j4 install && \ cd ../../../../.. && \ echo "--- installing protobuf ---" && \ - cd /var/local/git/grpc/third_party/protobuf && \ + cd ${DEP_PATH}/grpc/third_party/protobuf && \ mkdir -p cmake/build && \ cd cmake/build && \ cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. && \ make -j4 install && \ cd ../../../.. && \ echo "--- installing grpc ---" && \ - cd /var/local/git/grpc && \ + cd ${DEP_PATH}/grpc && \ mkdir -p cmake/build && \ cd cmake/build && \ cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. && \ make -j4 install && \ echo "--- installing google test ---" && \ - cd /var/local/git/grpc/third_party/googletest && \ + cd ${DEP_PATH}/grpc/third_party/googletest && \ cmake -Dgtest_build_samples=ON -DBUILD_SHARED_LIBS=ON . && \ make && \ make install && \ @@ -207,15 +204,15 @@ function install_dependencis { sudo python2.7 /tmp/get-pip.py && \ sudo pip2 install six && \ apt-get install -y libevent-dev && \ - mkdir -p /var/local/git/openvswitch && \ - cd /var/local/git/openvswitch && \ + mkdir -p ${DEP_PATH}/openvswitch && \ + cd ${DEP_PATH}/openvswitch && \ ./boot.sh && \ ./configure --prefix=/usr/local --localstatedir=/var --sysconfdir=/etc --enable-shared --enable-ndebug && \ make && \ make install && \ cp ./lib/vconn-provider.h /usr/local/include/openvswitch && \ cp ./include/openvswitch/namemap.h /usr/local/include/openvswitch && \ - cd /var/local/git/openvswitch && \ + cd ${DEP_PATH}/openvswitch && \ cd openvswitch-2.9.8 && \ ./configure && make && \ cp $OVS_INCLUDE_HEADERS /usr/local/include/openvswitch && \ @@ -225,16 +222,16 @@ function install_dependencis { cd ~ echo "7--- installing marl ---" && \ - cd /var/local/git/marl/marl && \ - mkdir /var/local/git/marl/marl/build && \ - cd /var/local/git/marl/marl/build && \ + cd ${DEP_PATH}/marl/marl && \ + mkdir ${DEP_PATH}/marl/marl/build && \ + cd ${DEP_PATH}/marl/marl/build && \ cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 && \ make && \ cd ~ PULSAR_RELEASE_TAG='pulsar-2.8.1' echo "8--- installing pulsar dependacies ---" && \ - cd /var/local/git/pulsar && \ + cd ${DEP_PATH}/pulsar && \ apt install -y ./apache-pulsar-client*.deb cd ~ @@ -260,5 +257,39 @@ function install_dependencis { nohup $BUILD/bin/AlcorControlAgent > /dev/null 2>&1 & } -#download_dependencis -install_dependencis + +BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +echo "build path is $BUILD" +DEP_PATH="/var/local/git" + +while getopts "dD:iI:" opt; do +case $opt in + d) + echo "Download dependencis" + download_dependencis + ;; + D) + echo "Download dependencis to $OPTARG" + DEP_PATH=$OPTARG + download_dependencis + ;; + i) + echo "Install dependencis" + install_dependencis + ;; + I) + echo "Install dependencis from $OPTARG" + DEP_PATH=$OPTARG + install_dependencis + ;; + \?) + echo "Invalid arguements" +esac +done + +if [ $OPTIND -eq 1 ]; then + echo "Download and install dependencis" + download_dependencis + install_dependencis +fi +shift $((OPTIND-1)) \ No newline at end of file From ac183885a622e2641f3719792ce66de8f0b1f8fc Mon Sep 17 00:00:00 2001 From: VanderChen Date: Wed, 27 Apr 2022 18:38:02 +0800 Subject: [PATCH 5/9] Add lxd container build scripts --- build/aca-machine-init-local.sh | 13 ++- build/build-lxd.sh | 35 ++++++ build/lxd.yaml | 200 ++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+), 6 deletions(-) create mode 100644 build/build-lxd.sh create mode 100644 build/lxd.yaml diff --git a/build/aca-machine-init-local.sh b/build/aca-machine-init-local.sh index b5ca6bb0..8b652c9c 100755 --- a/build/aca-machine-init-local.sh +++ b/build/aca-machine-init-local.sh @@ -262,7 +262,8 @@ BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" echo "build path is $BUILD" DEP_PATH="/var/local/git" -while getopts "dD:iI:" opt; do +# while getopts "dD:iI:" opt; do +while getopts "dD:i" opt; do case $opt in d) echo "Download dependencis" @@ -277,11 +278,11 @@ case $opt in echo "Install dependencis" install_dependencis ;; - I) - echo "Install dependencis from $OPTARG" - DEP_PATH=$OPTARG - install_dependencis - ;; +# I) +# echo "Install dependencis from $OPTARG" +# DEP_PATH=$OPTARG +# install_dependencis +# ;; \?) echo "Invalid arguements" esac diff --git a/build/build-lxd.sh b/build/build-lxd.sh new file mode 100644 index 00000000..19416d38 --- /dev/null +++ b/build/build-lxd.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# MIT License +# Copyright(c) 2020 Futurewei Cloud +# +# Permission is hereby granted, +# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +# to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +echo "build path is $BUILD" +DEP_PATH="/var/local/git" + +$HOME/go/bin/distrobuilder build-lxd lxd.yaml && \ +lxc image import lxd.tar.xz rootfs.squashfs --alias aca && \ +rm -rf lxd.tar.xz \ + rootfs.squashfs \ + *.service \ + ignite && \ +lxc launch aca aca +lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh" +lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh" +chown -R 100000:100000 /etc/run/openvswitch +lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \ + lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \ + lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \ + lxc config device add aca run disk source=/var/run/openvswitch path=/var/run/openvswitch && \ + lxc config device add aca etc disk source=/etc/openvswitch path=/etc/openvswitch diff --git a/build/lxd.yaml b/build/lxd.yaml new file mode 100644 index 00000000..e40e5ca3 --- /dev/null +++ b/build/lxd.yaml @@ -0,0 +1,200 @@ +image: + name: ubuntu-bionic-x86_64 + distribution: ubuntu + release: bionic + description: |- + Alcor Control Agent + architecture: x86_64 + +source: + downloader: debootstrap + same_as: gutsy + url: http://archive.ubuntu.com/ubuntu + keyserver: keyserver.ubuntu.com + keys: + - 0x790BC7277767219C42C86F933B4FE6ACC0B21F32 + - 0xf6ecb3762474eda9d21b7022871920d1991bc93c + +targets: + lxc: + create-message: |- + You just created an {{ image.description }} container. + + To enable SSH, run: apt install openssh-server + No default root or user password are set by LXC. + config: + - type: all + before: 5 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.common.conf + + - type: user + before: 5 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.userns.conf + + - type: all + after: 4 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/common.conf + + - type: user + after: 4 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/userns.conf + + - type: all + content: |- + lxc.arch = {{ image.architecture_personality }} + +files: +- path: /etc/hostname + generator: hostname + +- path: /etc/hosts + generator: hosts + +- path: /etc/resolvconf/resolv.conf.d/original + generator: remove + +- path: /etc/resolvconf/resolv.conf.d/tail + generator: remove + +- path: /etc/machine-id + generator: dump + +- path: /etc/user/profile + generator: copy + source: /etc/profile + +- path: /var/lib/dbus/machine-id + generator: remove + +- path: /etc/netplan/10-lxc.yaml + generator: dump + content: |- + network: + version: 2 + ethernets: + eth0: + dhcp4: true + dhcp-identifier: mac + releases: + - bionic + types: + - container + variants: + - default + +- path: /etc/netplan/10-lxc.yaml + generator: dump + content: |- + network: + version: 2 + ethernets: + enp5s0: + dhcp4: true + dhcp-identifier: mac + releases: + - bionic + types: + - vm + variants: + - default + +- name: meta-data + generator: cloud-init + variants: + - cloud + +- name: network-config + generator: cloud-init + variants: + - cloud + +- name: user-data + generator: cloud-init + variants: + - cloud + +- name: vendor-data + generator: cloud-init + variants: + - cloud + +- name: ext4 + generator: fstab + types: + - vm + +- name: lxd-agent + generator: lxd-agent + types: + - vm + +- path: /etc/default/grub.d/50-lxd.cfg + generator: dump + content: |- + GRUB_RECORDFAIL_TIMEOUT=0 + GRUB_TIMEOUT=0 + GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} console=tty1 console=ttyS0" + GRUB_TERMINAL=console + types: + - vm + +- path: /etc/sudoers.d/90-lxd + generator: dump + mode: 0440 + content: |- + # User rules for ubuntu + ubuntu ALL=(ALL) NOPASSWD:ALL + variants: + - default + +- path: /root/aca + generator: copy + source: ./aca + +- path: /root/dependencis + generator: copy + source: ./dependencis + +packages: + manager: apt + update: true + cleanup: true + sets: + - packages: + - openssh-client + - vim + - build-essential + - iputils-ping + - iperf + - net-tools + - inetutils-telnet + - iperf + - openssh-server + action: install + + repositories: + - name: sources.list + url: |- + deb http://archive.ubuntu.com/ubuntu {{ image.release }} main restricted universe multiverse + deb http://archive.ubuntu.com/ubuntu {{ image.release }}-updates main restricted universe multiverse + deb http://security.ubuntu.com/ubuntu {{ image.release }}-security main restricted universe multiverse + architectures: + - amd64 + +# TODO: actions part is provided by official but not working +# actions: +# - trigger: post-files +# action: |- +# #!/bin/bash +# chmod +x /root/ignite/bin/ignite.sh +# systemctl daemon-reload +# systemctl enable ignite +# systemctl enable dpm + + +mappings: + architecture_map: debian \ No newline at end of file From f4fc26142c65ed2e5ab915780a4de37978cec804 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Sat, 14 May 2022 17:15:48 +0800 Subject: [PATCH 6/9] Update build-lxd.sh --- build/build-lxd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build-lxd.sh b/build/build-lxd.sh index 19416d38..fb60b7e4 100644 --- a/build/build-lxd.sh +++ b/build/build-lxd.sh @@ -27,7 +27,7 @@ rm -rf lxd.tar.xz \ lxc launch aca aca lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh" lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh" -chown -R 100000:100000 /etc/run/openvswitch +chown -R lxd /etc/run/openvswitch lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \ lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \ lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \ From f2785045295042450986744c9b5d87125bd8bb58 Mon Sep 17 00:00:00 2001 From: VanderChen Date: Sat, 14 May 2022 17:31:42 +0800 Subject: [PATCH 7/9] Update lxd container build scripts --- build/build-lxd.sh | 35 -------------- build/lxd-container/build-lxd.sh | 73 ++++++++++++++++++++++++++++++ build/{ => lxd-container}/lxd.yaml | 0 3 files changed, 73 insertions(+), 35 deletions(-) delete mode 100644 build/build-lxd.sh create mode 100644 build/lxd-container/build-lxd.sh rename build/{ => lxd-container}/lxd.yaml (100%) diff --git a/build/build-lxd.sh b/build/build-lxd.sh deleted file mode 100644 index fb60b7e4..00000000 --- a/build/build-lxd.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# MIT License -# Copyright(c) 2020 Futurewei Cloud -# -# Permission is hereby granted, -# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons -# to whom the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -echo "build path is $BUILD" -DEP_PATH="/var/local/git" - -$HOME/go/bin/distrobuilder build-lxd lxd.yaml && \ -lxc image import lxd.tar.xz rootfs.squashfs --alias aca && \ -rm -rf lxd.tar.xz \ - rootfs.squashfs \ - *.service \ - ignite && \ -lxc launch aca aca -lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh" -lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh" -chown -R lxd /etc/run/openvswitch -lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \ - lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \ - lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \ - lxc config device add aca run disk source=/var/run/openvswitch path=/var/run/openvswitch && \ - lxc config device add aca etc disk source=/etc/openvswitch path=/etc/openvswitch diff --git a/build/lxd-container/build-lxd.sh b/build/lxd-container/build-lxd.sh new file mode 100644 index 00000000..e642c508 --- /dev/null +++ b/build/lxd-container/build-lxd.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# MIT License +# Copyright(c) 2020 Futurewei Cloud +# +# Permission is hereby granted, +# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +# to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +function install_distrobuilder { + apt update &&\ + apt install -y debootstrap rsync gpg squashfs-tools git + + # install golang + wget https://go.dev/dl/go1.18.2.linux-amd64.tar.gz + rm -rf /usr/local/go &&\ + tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz + export PATH=$PATH:/usr/local/go/bin + rm go1.18.2.linux-amd64.tar.gz + + # install distobuilder + git clone https://github.com/lxc/distrobuilder + cd ./distrobuilder + make + cd .. + rm -rf ./distrobuilder +} + +function build_aca_lxc { + BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + echo "build path is $BUILD" + DEP_PATH="/var/local/git" + + $HOME/go/bin/distrobuilder build-lxd lxd.yaml && \ + lxc image import lxd.tar.xz rootfs.squashfs --alias aca && \ + rm -rf lxd.tar.xz \ + rootfs.squashfs \ + *.service \ + ignite && \ + lxc launch aca aca + lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh" + lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh" + chown -R lxd /etc/run/openvswitch + lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \ + lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \ + lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \ + lxc config device add aca run disk source=/var/run/openvswitch path=/var/run/openvswitch && \ + lxc config device add aca etc disk source=/etc/openvswitch path=/etc/openvswitch +} + + +while getopts "ib" opt; do +case $opt in + i) + echo "Install distrobuilder" + install_distrobuilder + ;; + b) + echo "Build aca lxc container" + build_aca_lxc + ;; + \?) + echo "Invalid arguements" +esac +done \ No newline at end of file diff --git a/build/lxd.yaml b/build/lxd-container/lxd.yaml similarity index 100% rename from build/lxd.yaml rename to build/lxd-container/lxd.yaml From 597debf15d5eee051d14c98590bdf8205a344a9e Mon Sep 17 00:00:00 2001 From: VanderChen Date: Sat, 14 May 2022 17:32:45 +0800 Subject: [PATCH 8/9] Update build shell --- build/lxd-container/build-lxd.sh | 73 ----------- build/lxd-container/lxd.yaml | 200 ------------------------------- 2 files changed, 273 deletions(-) delete mode 100644 build/lxd-container/build-lxd.sh delete mode 100644 build/lxd-container/lxd.yaml diff --git a/build/lxd-container/build-lxd.sh b/build/lxd-container/build-lxd.sh deleted file mode 100644 index e642c508..00000000 --- a/build/lxd-container/build-lxd.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -# MIT License -# Copyright(c) 2020 Futurewei Cloud -# -# Permission is hereby granted, -# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons -# to whom the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -function install_distrobuilder { - apt update &&\ - apt install -y debootstrap rsync gpg squashfs-tools git - - # install golang - wget https://go.dev/dl/go1.18.2.linux-amd64.tar.gz - rm -rf /usr/local/go &&\ - tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz - export PATH=$PATH:/usr/local/go/bin - rm go1.18.2.linux-amd64.tar.gz - - # install distobuilder - git clone https://github.com/lxc/distrobuilder - cd ./distrobuilder - make - cd .. - rm -rf ./distrobuilder -} - -function build_aca_lxc { - BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - echo "build path is $BUILD" - DEP_PATH="/var/local/git" - - $HOME/go/bin/distrobuilder build-lxd lxd.yaml && \ - lxc image import lxd.tar.xz rootfs.squashfs --alias aca && \ - rm -rf lxd.tar.xz \ - rootfs.squashfs \ - *.service \ - ignite && \ - lxc launch aca aca - lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh" - lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh" - chown -R lxd /etc/run/openvswitch - lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \ - lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \ - lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \ - lxc config device add aca run disk source=/var/run/openvswitch path=/var/run/openvswitch && \ - lxc config device add aca etc disk source=/etc/openvswitch path=/etc/openvswitch -} - - -while getopts "ib" opt; do -case $opt in - i) - echo "Install distrobuilder" - install_distrobuilder - ;; - b) - echo "Build aca lxc container" - build_aca_lxc - ;; - \?) - echo "Invalid arguements" -esac -done \ No newline at end of file diff --git a/build/lxd-container/lxd.yaml b/build/lxd-container/lxd.yaml deleted file mode 100644 index e40e5ca3..00000000 --- a/build/lxd-container/lxd.yaml +++ /dev/null @@ -1,200 +0,0 @@ -image: - name: ubuntu-bionic-x86_64 - distribution: ubuntu - release: bionic - description: |- - Alcor Control Agent - architecture: x86_64 - -source: - downloader: debootstrap - same_as: gutsy - url: http://archive.ubuntu.com/ubuntu - keyserver: keyserver.ubuntu.com - keys: - - 0x790BC7277767219C42C86F933B4FE6ACC0B21F32 - - 0xf6ecb3762474eda9d21b7022871920d1991bc93c - -targets: - lxc: - create-message: |- - You just created an {{ image.description }} container. - - To enable SSH, run: apt install openssh-server - No default root or user password are set by LXC. - config: - - type: all - before: 5 - content: |- - lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.common.conf - - - type: user - before: 5 - content: |- - lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.userns.conf - - - type: all - after: 4 - content: |- - lxc.include = LXC_TEMPLATE_CONFIG/common.conf - - - type: user - after: 4 - content: |- - lxc.include = LXC_TEMPLATE_CONFIG/userns.conf - - - type: all - content: |- - lxc.arch = {{ image.architecture_personality }} - -files: -- path: /etc/hostname - generator: hostname - -- path: /etc/hosts - generator: hosts - -- path: /etc/resolvconf/resolv.conf.d/original - generator: remove - -- path: /etc/resolvconf/resolv.conf.d/tail - generator: remove - -- path: /etc/machine-id - generator: dump - -- path: /etc/user/profile - generator: copy - source: /etc/profile - -- path: /var/lib/dbus/machine-id - generator: remove - -- path: /etc/netplan/10-lxc.yaml - generator: dump - content: |- - network: - version: 2 - ethernets: - eth0: - dhcp4: true - dhcp-identifier: mac - releases: - - bionic - types: - - container - variants: - - default - -- path: /etc/netplan/10-lxc.yaml - generator: dump - content: |- - network: - version: 2 - ethernets: - enp5s0: - dhcp4: true - dhcp-identifier: mac - releases: - - bionic - types: - - vm - variants: - - default - -- name: meta-data - generator: cloud-init - variants: - - cloud - -- name: network-config - generator: cloud-init - variants: - - cloud - -- name: user-data - generator: cloud-init - variants: - - cloud - -- name: vendor-data - generator: cloud-init - variants: - - cloud - -- name: ext4 - generator: fstab - types: - - vm - -- name: lxd-agent - generator: lxd-agent - types: - - vm - -- path: /etc/default/grub.d/50-lxd.cfg - generator: dump - content: |- - GRUB_RECORDFAIL_TIMEOUT=0 - GRUB_TIMEOUT=0 - GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} console=tty1 console=ttyS0" - GRUB_TERMINAL=console - types: - - vm - -- path: /etc/sudoers.d/90-lxd - generator: dump - mode: 0440 - content: |- - # User rules for ubuntu - ubuntu ALL=(ALL) NOPASSWD:ALL - variants: - - default - -- path: /root/aca - generator: copy - source: ./aca - -- path: /root/dependencis - generator: copy - source: ./dependencis - -packages: - manager: apt - update: true - cleanup: true - sets: - - packages: - - openssh-client - - vim - - build-essential - - iputils-ping - - iperf - - net-tools - - inetutils-telnet - - iperf - - openssh-server - action: install - - repositories: - - name: sources.list - url: |- - deb http://archive.ubuntu.com/ubuntu {{ image.release }} main restricted universe multiverse - deb http://archive.ubuntu.com/ubuntu {{ image.release }}-updates main restricted universe multiverse - deb http://security.ubuntu.com/ubuntu {{ image.release }}-security main restricted universe multiverse - architectures: - - amd64 - -# TODO: actions part is provided by official but not working -# actions: -# - trigger: post-files -# action: |- -# #!/bin/bash -# chmod +x /root/ignite/bin/ignite.sh -# systemctl daemon-reload -# systemctl enable ignite -# systemctl enable dpm - - -mappings: - architecture_map: debian \ No newline at end of file From a3de2d40be2937eb66c5fb5c88de42ebe071ce64 Mon Sep 17 00:00:00 2001 From: VanderChen Date: Sat, 14 May 2022 17:34:42 +0800 Subject: [PATCH 9/9] Update build shell --- build/aca-machine-init-local.sh | 296 ------------------------------- build/lxd-container/build-lxd.sh | 73 ++++++++ build/lxd-container/lxd.yaml | 200 +++++++++++++++++++++ 3 files changed, 273 insertions(+), 296 deletions(-) delete mode 100755 build/aca-machine-init-local.sh create mode 100644 build/lxd-container/build-lxd.sh create mode 100644 build/lxd-container/lxd.yaml diff --git a/build/aca-machine-init-local.sh b/build/aca-machine-init-local.sh deleted file mode 100755 index 8b652c9c..00000000 --- a/build/aca-machine-init-local.sh +++ /dev/null @@ -1,296 +0,0 @@ -#!/bin/bash - -# MIT License -# Copyright(c) 2020 Futurewei Cloud -# -# Permission is hereby granted, -# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons -# to whom the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -function download_dependencis { - rm -rf ${DEP_PATH} - mkdir -p ${DEP_PATH} - - echo "d.3--- re-downloading cppkafka ---" && \ - rm -rf ${DEP_PATH}/cppkafka - git clone https://github.com/mfontanini/cppkafka.git ${DEP_PATH}/cppkafka - - GRPC_RELEASE_TAG="v1.24.x" - echo "d.5--- re-downloading grpc repo ---" && \ - rm -rf ${DEP_PATH}/grpc && \ - git clone -b $GRPC_RELEASE_TAG https://github.com/grpc/grpc ${DEP_PATH}/grpc - cd ${DEP_PATH}/grpc && \ - git submodule update --init && \ - cd ${DEP_PATH}/grpc/third_party/cares/cares && \ - git fetch origin && \ - git checkout cares-1_15_0 - - - echo "d.6--- re-downloading openvswitch ---" && \ - rm -rf ${DEP_PATH}/openvswitch && \ - git clone -b "branch-2.12" https://github.com/openvswitch/ovs.git ${DEP_PATH}/openvswitch && \ - cd ${DEP_PATH}/openvswitch && \ - wget https://www.openvswitch.org/releases/openvswitch-2.9.8.tar.gz && \ - tar -xvzf openvswitch-2.9.8.tar.gz - - echo "d.7--- re-dowloading marl---" && \ - rm -rf ${DEP_PATH}/marl && \ - mkdir -p ${DEP_PATH}/marl && \ - cd ${DEP_PATH}/marl && \ - git clone https://github.com/google/marl.git && \ - cd ${DEP_PATH}/marl/marl && \ - git submodule update --init - - PULSAR_RELEASE_TAG='pulsar-2.8.1' - echo "d.8--- re-downloading pulsar dependacies ---" && \ - mkdir -p ${DEP_PATH}/pulsar && \ - wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client.deb -O ${DEP_PATH}/pulsar/apache-pulsar-client.deb && \ - wget https://archive.apache.org/dist/pulsar/${PULSAR_RELEASE_TAG}/DEB/apache-pulsar-client-dev.deb -O ${DEP_PATH}/pulsar/apache-pulsar-client-dev.deb -} - -function install_dependencis { - - # TODO: remove the unneeded dependencies - echo "1--- installing common dependencies ---" && \ - apt-get update -y && apt-get install -y \ - rpcbind \ - rsyslog \ - build-essential \ - make \ - g++ \ - unzip \ - cmake \ - clang-9 \ - llvm-9 \ - libelf-dev \ - doxygen \ - zlib1g-dev \ - libssl-dev \ - libboost-program-options-dev \ - libboost-all-dev \ - iproute2 \ - net-tools \ - iputils-ping \ - ethtool \ - curl \ - python3 \ - python3-pip \ - netcat \ - libcmocka-dev \ - lcov \ - git \ - autoconf \ - automake \ - dh-autoreconf \ - pkg-config \ - libtool \ - wget \ - uuid-dev - pip3 install httpserver netaddr - - echo "2--- installing librdkafka ---" && \ - apt-get update -y && apt-get install -y --no-install-recommends\ - librdkafka-dev \ - doxygen \ - libssl-dev \ - zlib1g-dev \ - libboost-program-options-dev \ - libboost-all-dev \ - && apt-get clean - - echo "3--- installing cppkafka ---" && \ - apt-get update -y && apt-get install -y cmake - cd ${DEP_PATH}/cppkafka && \ - mkdir build && \ - cd build && \ - cmake .. && \ - make && \ - make install && \ - ldconfig && \ - cd ~ - - echo "4--- installing grpc dependencies ---" && \ - apt-get update -y && apt-get install -y \ - cmake libssl-dev \ - autoconf git pkg-config \ - automake libtool make g++ unzip - - # installing grpc and its dependencies - echo "5--- cloning grpc repo ---" && \ - echo "--- installing c-ares ---" && \ - cd ${DEP_PATH}/grpc/third_party/cares/cares && \ - mkdir -p cmake/build && \ - cd cmake/build && \ - cmake -DCMAKE_BUILD_TYPE=Release ../.. && \ - make -j4 install && \ - cd ../../../../.. && \ - echo "--- installing protobuf ---" && \ - cd ${DEP_PATH}/grpc/third_party/protobuf && \ - mkdir -p cmake/build && \ - cd cmake/build && \ - cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .. && \ - make -j4 install && \ - cd ../../../.. && \ - echo "--- installing grpc ---" && \ - cd ${DEP_PATH}/grpc && \ - mkdir -p cmake/build && \ - cd cmake/build && \ - cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../.. && \ - make -j4 install && \ - echo "--- installing google test ---" && \ - cd ${DEP_PATH}/grpc/third_party/googletest && \ - cmake -Dgtest_build_samples=ON -DBUILD_SHARED_LIBS=ON . && \ - make && \ - make install && \ - cd ~ - - OVS_INCLUDE_HEADERS="include/openvswitch/compiler.h \ - include/openvswitch/dynamic-string.h \ - include/openvswitch/hmap.h \ - include/openvswitch/flow.h \ - include/openvswitch/geneve.h \ - include/openvswitch/json.h \ - include/openvswitch/list.h \ - include/openvswitch/netdev.h \ - include/openvswitch/match.h \ - include/openvswitch/meta-flow.h \ - include/openvswitch/ofpbuf.h \ - include/openvswitch/ofp-actions.h \ - include/openvswitch/ofp-ed-props.h \ - include/openvswitch/ofp-errors.h \ - include/openvswitch/ofp-msgs.h \ - include/openvswitch/ofp-parse.h \ - include/openvswitch/ofp-print.h \ - include/openvswitch/ofp-prop.h \ - include/openvswitch/ofp-util.h \ - include/openvswitch/packets.h \ - include/openvswitch/poll-loop.h \ - include/openvswitch/rconn.h \ - include/openvswitch/shash.h \ - include/openvswitch/thread.h \ - include/openvswitch/token-bucket.h \ - include/openvswitch/tun-metadata.h \ - include/openvswitch/type-props.h \ - include/openvswitch/types.h \ - include/openvswitch/util.h \ - include/openvswitch/uuid.h \ - include/openvswitch/version.h \ - include/openvswitch/vconn.h \ - include/openvswitch/vlog.h \ - include/openvswitch/nsh.h " - OPENFLOW_HEADERS="include/openflow/intel-ext.h \ - include/openflow/netronome-ext.h \ - include/openflow/nicira-ext.h \ - include/openflow/openflow-1.0.h \ - include/openflow/openflow-1.1.h \ - include/openflow/openflow-1.2.h \ - include/openflow/openflow-1.3.h \ - include/openflow/openflow-1.4.h \ - include/openflow/openflow-1.5.h \ - include/openflow/openflow-1.6.h \ - include/openflow/openflow-common.h \ - include/openflow/openflow.h " - echo "6--- installing openvswitch dependancies ---" && \ - sudo rm -f /tmp/get-pip.py > /dev/null 2>&1 && \ - sudo apt-get install -y python2.7 && \ - sudo wget https://bootstrap.pypa.io/pip/2.7/get-pip.py -O /tmp/get-pip.py && \ - sudo python2.7 /tmp/get-pip.py && \ - sudo pip2 install six && \ - apt-get install -y libevent-dev && \ - mkdir -p ${DEP_PATH}/openvswitch && \ - cd ${DEP_PATH}/openvswitch && \ - ./boot.sh && \ - ./configure --prefix=/usr/local --localstatedir=/var --sysconfdir=/etc --enable-shared --enable-ndebug && \ - make && \ - make install && \ - cp ./lib/vconn-provider.h /usr/local/include/openvswitch && \ - cp ./include/openvswitch/namemap.h /usr/local/include/openvswitch && \ - cd ${DEP_PATH}/openvswitch && \ - cd openvswitch-2.9.8 && \ - ./configure && make && \ - cp $OVS_INCLUDE_HEADERS /usr/local/include/openvswitch && \ - cp $OPENFLOW_HEADERS /usr/local/include/openflow && \ - cp ./lib/.libs/libopenvswitch.a /usr/local/lib/ && \ - test -f /usr/bin/ovs-vsctl && rm -rf /usr/local/sbin/ov* /usr/local/bin/ov* /usr/local/bin/vtep* && \ - cd ~ - - echo "7--- installing marl ---" && \ - cd ${DEP_PATH}/marl/marl && \ - mkdir ${DEP_PATH}/marl/marl/build && \ - cd ${DEP_PATH}/marl/marl/build && \ - cmake .. -DMARL_BUILD_EXAMPLES=1 -DMARL_BUILD_TESTS=1 && \ - make && \ - cd ~ - - PULSAR_RELEASE_TAG='pulsar-2.8.1' - echo "8--- installing pulsar dependacies ---" && \ - cd ${DEP_PATH}/pulsar && \ - apt install -y ./apache-pulsar-client*.deb - cd ~ - - echo "9--- building alcor-control-agent" - cd $BUILD/.. && cmake . && \ - # after cmake ., modify the generated link.txt s so that the "-lssl" and "-lcrypto" appears after the openvswitch, so that it can compile - sed -i 's/\(-ldl -lrt -lm -lpthread\)/-lssl -lcrypto \1/' src/CMakeFiles/AlcorControlAgent.dir/link.txt && \ - sed -i 's/\(-ldl -lrt -lm -lpthread\)/-lssl -lcrypto \1/' test/CMakeFiles/aca_tests.dir/link.txt && \ - sed -i 's/\(-ldl -lrt -lm -lpthread\)/-lssl -lcrypto \1/' test/CMakeFiles/gs_tests.dir/link.txt && \ - make - if [ -n "$1" -a "$1" = "delete-bridges" ]; then - echo "10--- deleting br-tun and br-int if requested" - PATH=$PATH:/usr/local/share/openvswitch/scripts \ - LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib - ovs-ctl --system-id=random --delete-bridges restart - fi - - echo "11--- running alcor-control-agent" - # kill current AlcorControlAgent process if any - pkill -f AlcorControlAgent - # launch newly built AlcorControlAgent with default debug mode as 'false' - # sends output to null device, but stderr to console - nohup $BUILD/bin/AlcorControlAgent > /dev/null 2>&1 & -} - - -BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -echo "build path is $BUILD" -DEP_PATH="/var/local/git" - -# while getopts "dD:iI:" opt; do -while getopts "dD:i" opt; do -case $opt in - d) - echo "Download dependencis" - download_dependencis - ;; - D) - echo "Download dependencis to $OPTARG" - DEP_PATH=$OPTARG - download_dependencis - ;; - i) - echo "Install dependencis" - install_dependencis - ;; -# I) -# echo "Install dependencis from $OPTARG" -# DEP_PATH=$OPTARG -# install_dependencis -# ;; - \?) - echo "Invalid arguements" -esac -done - -if [ $OPTIND -eq 1 ]; then - echo "Download and install dependencis" - download_dependencis - install_dependencis -fi -shift $((OPTIND-1)) \ No newline at end of file diff --git a/build/lxd-container/build-lxd.sh b/build/lxd-container/build-lxd.sh new file mode 100644 index 00000000..e642c508 --- /dev/null +++ b/build/lxd-container/build-lxd.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# MIT License +# Copyright(c) 2020 Futurewei Cloud +# +# Permission is hereby granted, +# free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons +# to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +function install_distrobuilder { + apt update &&\ + apt install -y debootstrap rsync gpg squashfs-tools git + + # install golang + wget https://go.dev/dl/go1.18.2.linux-amd64.tar.gz + rm -rf /usr/local/go &&\ + tar -C /usr/local -xzf go1.18.2.linux-amd64.tar.gz + export PATH=$PATH:/usr/local/go/bin + rm go1.18.2.linux-amd64.tar.gz + + # install distobuilder + git clone https://github.com/lxc/distrobuilder + cd ./distrobuilder + make + cd .. + rm -rf ./distrobuilder +} + +function build_aca_lxc { + BUILD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + echo "build path is $BUILD" + DEP_PATH="/var/local/git" + + $HOME/go/bin/distrobuilder build-lxd lxd.yaml && \ + lxc image import lxd.tar.xz rootfs.squashfs --alias aca && \ + rm -rf lxd.tar.xz \ + rootfs.squashfs \ + *.service \ + ignite && \ + lxc launch aca aca + lxc exec aca -- bash -c "chmod +x /root/aca/build/aca-machine-init.sh" + lxc exec aca -- bash -c "/root/aca/build/aca-machine-init.sh" + chown -R lxd /etc/run/openvswitch + lxc config device add aca modules disk source=/lib/modules path=/lib/modules && \ + lxc config device add aca log disk source=/var/log/openvswitch path=/var/log/openvswitch && \ + lxc config device add aca lib disk source=/var/lib/openvswitch path=/var/lib/openvswitch && \ + lxc config device add aca run disk source=/var/run/openvswitch path=/var/run/openvswitch && \ + lxc config device add aca etc disk source=/etc/openvswitch path=/etc/openvswitch +} + + +while getopts "ib" opt; do +case $opt in + i) + echo "Install distrobuilder" + install_distrobuilder + ;; + b) + echo "Build aca lxc container" + build_aca_lxc + ;; + \?) + echo "Invalid arguements" +esac +done \ No newline at end of file diff --git a/build/lxd-container/lxd.yaml b/build/lxd-container/lxd.yaml new file mode 100644 index 00000000..e40e5ca3 --- /dev/null +++ b/build/lxd-container/lxd.yaml @@ -0,0 +1,200 @@ +image: + name: ubuntu-bionic-x86_64 + distribution: ubuntu + release: bionic + description: |- + Alcor Control Agent + architecture: x86_64 + +source: + downloader: debootstrap + same_as: gutsy + url: http://archive.ubuntu.com/ubuntu + keyserver: keyserver.ubuntu.com + keys: + - 0x790BC7277767219C42C86F933B4FE6ACC0B21F32 + - 0xf6ecb3762474eda9d21b7022871920d1991bc93c + +targets: + lxc: + create-message: |- + You just created an {{ image.description }} container. + + To enable SSH, run: apt install openssh-server + No default root or user password are set by LXC. + config: + - type: all + before: 5 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.common.conf + + - type: user + before: 5 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.userns.conf + + - type: all + after: 4 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/common.conf + + - type: user + after: 4 + content: |- + lxc.include = LXC_TEMPLATE_CONFIG/userns.conf + + - type: all + content: |- + lxc.arch = {{ image.architecture_personality }} + +files: +- path: /etc/hostname + generator: hostname + +- path: /etc/hosts + generator: hosts + +- path: /etc/resolvconf/resolv.conf.d/original + generator: remove + +- path: /etc/resolvconf/resolv.conf.d/tail + generator: remove + +- path: /etc/machine-id + generator: dump + +- path: /etc/user/profile + generator: copy + source: /etc/profile + +- path: /var/lib/dbus/machine-id + generator: remove + +- path: /etc/netplan/10-lxc.yaml + generator: dump + content: |- + network: + version: 2 + ethernets: + eth0: + dhcp4: true + dhcp-identifier: mac + releases: + - bionic + types: + - container + variants: + - default + +- path: /etc/netplan/10-lxc.yaml + generator: dump + content: |- + network: + version: 2 + ethernets: + enp5s0: + dhcp4: true + dhcp-identifier: mac + releases: + - bionic + types: + - vm + variants: + - default + +- name: meta-data + generator: cloud-init + variants: + - cloud + +- name: network-config + generator: cloud-init + variants: + - cloud + +- name: user-data + generator: cloud-init + variants: + - cloud + +- name: vendor-data + generator: cloud-init + variants: + - cloud + +- name: ext4 + generator: fstab + types: + - vm + +- name: lxd-agent + generator: lxd-agent + types: + - vm + +- path: /etc/default/grub.d/50-lxd.cfg + generator: dump + content: |- + GRUB_RECORDFAIL_TIMEOUT=0 + GRUB_TIMEOUT=0 + GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} console=tty1 console=ttyS0" + GRUB_TERMINAL=console + types: + - vm + +- path: /etc/sudoers.d/90-lxd + generator: dump + mode: 0440 + content: |- + # User rules for ubuntu + ubuntu ALL=(ALL) NOPASSWD:ALL + variants: + - default + +- path: /root/aca + generator: copy + source: ./aca + +- path: /root/dependencis + generator: copy + source: ./dependencis + +packages: + manager: apt + update: true + cleanup: true + sets: + - packages: + - openssh-client + - vim + - build-essential + - iputils-ping + - iperf + - net-tools + - inetutils-telnet + - iperf + - openssh-server + action: install + + repositories: + - name: sources.list + url: |- + deb http://archive.ubuntu.com/ubuntu {{ image.release }} main restricted universe multiverse + deb http://archive.ubuntu.com/ubuntu {{ image.release }}-updates main restricted universe multiverse + deb http://security.ubuntu.com/ubuntu {{ image.release }}-security main restricted universe multiverse + architectures: + - amd64 + +# TODO: actions part is provided by official but not working +# actions: +# - trigger: post-files +# action: |- +# #!/bin/bash +# chmod +x /root/ignite/bin/ignite.sh +# systemctl daemon-reload +# systemctl enable ignite +# systemctl enable dpm + + +mappings: + architecture_map: debian \ No newline at end of file