docker: add ovsdb-server and ovs-vswitch

This commit is contained in:
zhihui.ding
2023-04-04 11:11:32 +08:00
parent eec45c75fa
commit cda472b82c
10 changed files with 94 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
SHELL := /bin/bash
.ONESHELL:
.PHONY: linux linux-rpm darwin darwin-zip windows windows-zip test vendor
.PHONY: docker linux linux-rpm darwin darwin-zip windows windows-zip test vendor
## version
LSB = $(shell lsb_release -i -s)$(shell lsb_release -r -s)
@@ -38,15 +38,10 @@ bin: linux windows darwin ## build all platform binary
## docker run --network host --privileged \
## -v /var/run:/var/run -v /etc/openlan/switch:/etc/openlan/switch \
## openlan-switch:5.8.13
docker: docker-switch docker-confd
docker: pkg
cp $(SD)/docker/openlan.docker $(BD)
cd $(BD) && docker build -t openlan:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan.docker .
docker-switch: pkg
cp $(SD)/docker/openlan-switch.docker $(BD)
cd $(BD) && docker build -t openlan-switch:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan-switch.docker .
docker-confd: pkg
cp $(SD)/docker/openlan-confd.docker $(BD)
cd $(BD) && docker build -t openlan-confd:$(VER) --build-arg BIN=$(LINUX_DIR).bin -f openlan-confd.docker .
clean: ## clean cache
rm -rvf ./build

View File

@@ -9,8 +9,8 @@ PIDFile=/var/openlan/confd/confd.pid
Restart=on-failure
EnvironmentFile=-/etc/sysconfig/openlan/confd
ExecStart=/var/openlan/script/confd start --detach
ExecStop=/var/openlan/script/confd stop
ExecStart=/var/openlan/script/confd.sh start --detach
ExecStop=/var/openlan/script/confd.sh stop
[Install]
WantedBy=multi-user.target

View File

@@ -1,6 +1,6 @@
#!/bin/bash
set -e
set -ex
command=$1; shift
options=$@;
@@ -8,6 +8,8 @@ options=$@;
dir=$(dirname $0)
OVSDB_SERVER_BIN="/usr/bin/env ovsdb-server"
OVSDB_TOOL_BIN="/usr/bin/env ovsdb-tool"
[ "$OVSDB_DATABASE_SCH" == "" ] && OVSDB_DATABASE_SCH="/etc/openlan/switch/confd.schema.json"
[ "$OVSDB_DATABASE" == "" ] && OVSDB_DATABASE="/etc/openlan/switch/confd.db"
[ "$OVSDB_LOG_FILE" == "" ] && OVSDB_LOG_FILE="/var/openlan/confd/confd.log"
[ "$OVSDB_SOCK" == "" ] && OVSDB_SOCK="/var/openlan/confd/confd.sock"
@@ -18,14 +20,17 @@ function stop() {
}
function start() {
[ -e "$OVSDB_DATABASE" ] || {
$OVSDB_TOOL_BIN create $OVSDB_DATABASE $OVSDB_DATABASE_SCH
}
set $OVSDB_SERVER_BIN $OVSDB_DATABASE
set "$@" -vconsole:emer -vsyslog:err -vfile:info
set "$@" -vconsole:info -vsyslog:off -vfile:off
set "$@" --remote=punix:"$OVSDB_SOCK"
set "$@" --log-file="$OVSDB_LOG_FILE"
set "$@" --pidfile="$OVSDB_PID_FILE"
[ "$OVSDB_OPTIONS" != "" ] && set "$@" $OVSDB_OPTIONS
for opt in $options; do
set "$@" $opt
set "$@" $opt
done
OVS_RUNDIR="/var/openlan/confd" "$@"
}

7
dist/script/ovs-vswitchd.sh vendored Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
/usr/sbin/ovs-vswitchd unix:/run/openvswitch/db.sock \
-vconsole:info -vsyslog:off -vfile:off --mlockall \
--pidfile

15
dist/script/ovsdb-server.sh vendored Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -ex
if [ ! -f "/etc/openvswitch/conf.db" ]; then
ovsdb-tool create /etc/openvswitch/conf.db
elif ovsdb-tool needs-conversion /etc/openvswitch/conf.db | grep -s -w yes; then
ovsdb-tool convert /etc/openvswitch/conf.db
fi
/usr/sbin/ovsdb-server /etc/openvswitch/conf.db \
-vconsole:info -vsyslog:off -vfile:off \
--remote=punix:/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
--pidfile

32
dist/script/switch.sh vendored Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
set -ex
if [ ! -e "/etc/openlan/switch/switch.json" ]; then
cat >> /etc/openlan/switch/switch.json << EOF
{
"cert": {
"directory": "/var/openlan/cert"
},
"http": {
"public": "/var/openlan/public"
},
"crypt": {
"secret": "cb2ff088a34d"
}
}
EOF
fi
if [ ! -e "/etc/openlan/switch/network/example.json" ]; then
cat >> /etc/openlan/switch/network/example.json << EOF
{
"name": "example",
"bridge": {
"address": "172.32.100.40/24"
}
}
EOF
fi
/usr/bin/openlan-switch -conf:dir /etc/openlan/switch -log:level 20

View File

@@ -1,16 +1,38 @@
version: "2.3"
services:
ovsdb-server:
image: "openlan:latest"
entrypoint: ["/var/openlan/script/ovsdb-server.sh", "start"]
volumes:
- /opt/openlan/run/openvswitch:/run/openvswitch
- /opt/openlan/etc/openvswitch:/etc/openvswitch
ovs-vswitchd:
image: "openlan:latest"
privileged: true
entrypoint: ["/var/openlan/script/ovs-vswitchd.sh", "start"]
volumes:
- /opt/openlan/run/openvswitch:/run/openvswitch
depends_on:
- ovsdb-server
confd:
image: "openlan-confd:latest"
image: "openlan:latest"
entrypoint: ["/var/openlan/script/confd.sh", "start"]
volumes:
- /opt/openlan/confd:/var/openlan/confd
- /opt/openlan/etc/openlan:/etc/openlan
switch:
image: "openlan-switch:latest"
image: "openlan:latest"
privileged: true
entrypoint: ["/var/openlan/script/switch.sh", "start"]
ports:
- 10000:10000
- 10002:10002
volumes:
- /opt/openlan/confd:/var/openlan/confd
- /opt/openlan/run/openvswitch:/run/openvswitch
- /opt/openlan/etc/openvswitch:/etc/openvswitch
- /opt/openlan/etc/openlan:/etc/openlan
depends_on:
- confd
- ovsdb-server
- ovs-vswitchd

View File

@@ -1,23 +0,0 @@
FROM centos:7
ARG BIN
WORKDIR /root
ADD ${BIN} /tmp
RUN yum install -y epel-release centos-release-openstack-train \
&& yum install -y rdma-core libibverbs
RUN DOCKER=yes /tmp/${BIN}
RUN rm -rf /tmp/* && rm -rf /var/cache/yum/*
LABEL application="OpenLAN Switch Application"
LABEL maintainer="danieldin95@163.com"
EXPOSE 10000/tcp
EXPOSE 10002/tcp
EXPOSE 10002/udp
EXPOSE 4500/udp
CMD ["/usr/bin/openlan-switch", "-conf:dir", "/etc/openlan/switch", "-log:level", "20"]

View File

@@ -15,4 +15,4 @@ RUN rm -rf /tmp/* && rm -rf /var/cache/yum/*
LABEL application="OpenLAN Switch Application"
LABEL maintainer="danieldin95@163.com"
CMD ["/var/openlan/script/confd", "start"]
CMD ["/var/openlan/script/switch.sh", "start"]

View File

@@ -246,6 +246,6 @@ func IptInit() {
}
__iptablesInit__ = true
if err := iptables.FirewalldInit(); err != nil {
libol.Info("IptInit %s", err)
libol.Debug("IptInit %s", err)
}
}