[ovs-dev] [PATCH] docker: add testing on local docker localhost:5000

hunchback aidan.shribman at gmail.com
Sat Apr 3 11:48:05 UTC 2021


add a set of docker targets which ease the building and testing of
docker images both on local registry (localhost:5000) as well as on the
public default registry (docker.io).

Signed-off-by: hunchback <aidan.shribman at gmail.com>
---
 .gitignore                              |  1 +
 Documentation/intro/install/general.rst | 38 +++++++++---------
 Makefile.am                             |  1 +
 utilities/automake.mk                   |  2 +-
 utilities/docker/.gitignore             |  2 +
 utilities/docker/Makefile               | 22 ----------
 utilities/docker/automake.mk            | 53 +++++++++++++++++++++++++
 utilities/docker/debian/Dockerfile      |  5 ++-
 8 files changed, 79 insertions(+), 45 deletions(-)
 create mode 100644 utilities/docker/.gitignore
 delete mode 100644 utilities/docker/Makefile
 create mode 100644 utilities/docker/automake.mk

diff --git a/.gitignore b/.gitignore
index f1cdcf124..b46a0528a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -79,3 +79,4 @@ testsuite.tmp.orig
 /Documentation/_build
 /.venv
 /cxx-check
+*.mod
diff --git a/Documentation/intro/install/general.rst b/Documentation/intro/install/general.rst
index c4300cd53..dd026c40c 100644
--- a/Documentation/intro/install/general.rst
+++ b/Documentation/intro/install/general.rst
@@ -510,40 +510,38 @@ For ovs vswitchd, we need to load ovs kernel modules on host.
 
 Hence, OVS containers kernel version needs to be same as that of host kernel.
 
-Export following variables in .env  and place it under
-project root::
+If you want to change the default values for building an image then set these
+variables::
 
-    $ OVS_BRANCH=<BRANCH>
-    $ OVS_VERSION=<VERSION>
-    $ DISTRO=<LINUX_DISTRO>
-    $ KERNEL_VERSION=<LINUX_KERNEL_VERSION>
-    $ GITHUB_SRC=<GITHUB_URL>
-    $ DOCKER_REPO=<REPO_TO_PUSH_IMAGE>
+    $ export OVS_BRANCH=<BRANCH>
+    $ export OVS_VERSION=<VERSION>
+    $ export DISTRO=<LINUX_DISTRO>
+    $ export KERNEL_VERSION=<LINUX_KERNEL_VERSION>
+    $ export GITHUB_SRC=<GITHUB_URL>
+    $ export DOCKER_REPO=<REPO_TO_PUSH_IMAGE>
+    $ export DOCKER_TAG=<DOCKER_IMAGE_TAG>
 
-To build ovs modules::
+To setup for using a local registry (localhost:5000)::
 
-    $ cd utilities/docker
-    $ make build
+    $ make docker-registry
+    $ export DOCKER_REPO=localhost:5000/ovsvswitch/ovs
 
-Compiled Modules will be tagged with docker image
+To build ovs modules (tagged with docker image)::
 
-To Push ovs modules::
+    $ make docker-build
 
-    $ make push
+To push ovs modules to docker repo::
 
-OVS docker image will be pushed to specified docker repo.
+     $ make docker-push
 
 Start ovsdb-server using below command::
 
-    $ docker run -itd --net=host --name=ovsdb-server \
-      <docker_repo>:<tag> ovsdb-server
+     $ make docker-ovsdb-server
 
 Start ovs-vswitchd with priviledged mode as it needs to load kernel module in
 host using below command::
 
-    $ docker run -itd --net=host --name=ovs-vswitchd \
-      --volumes-from=ovsdb-server -v /lib:/lib --privileged \
-      <docker_repo>:<tag> ovs-vswitchd
+    $ make docker-ovs-vswitchd
 
 .. note::
     The debian docker file uses ubuntu 16.04 as a base image for reference.
diff --git a/Makefile.am b/Makefile.am
index 691a005ad..e75df1be6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -499,3 +499,4 @@ include datapath-windows/include/automake.mk
 include windows/automake.mk
 include selinux/automake.mk
 include build-aux/automake.mk
+include utilities/docker/automake.mk
diff --git a/utilities/automake.mk b/utilities/automake.mk
index e2e22c39a..4d2f20570 100644
--- a/utilities/automake.mk
+++ b/utilities/automake.mk
@@ -56,7 +56,7 @@ EXTRA_DIST += \
 	utilities/ovs-vlan-test.in \
 	utilities/ovs-vsctl-bashcomp.bash \
 	utilities/checkpatch.py \
-        utilities/docker/Makefile \
+        utilities/docker/automake.mk \
         utilities/docker/ovs-override.conf \
         utilities/docker/start-ovs \
         utilities/docker/create_ovs_db.sh \
diff --git a/utilities/docker/.gitignore b/utilities/docker/.gitignore
new file mode 100644
index 000000000..5d05c158b
--- /dev/null
+++ b/utilities/docker/.gitignore
@@ -0,0 +1,2 @@
+vswitch.ovsschema
+ovsdb-tool
diff --git a/utilities/docker/Makefile b/utilities/docker/Makefile
deleted file mode 100644
index d8b08a3c9..000000000
--- a/utilities/docker/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-#export OVS_BRANCH=branch-2.11
-#export OVS_VERSION=2.11
-#export KERNEL_VERSION=4.15.0-54-generic
-#export DISTRO=debian
-#export GITHUB_SRC=https://github.com/openvswitch/ovs.git
-#export DOCKER_REPO=openvswitch/ovs
-
-# Example:
-#   make build
-#   make push
-
-REPO = ${DOCKER_REPO}
-tag = ${OVS_VERSION}_${DISTRO}_${KERNEL_VERSION}
-
-build: ;docker build -t ${REPO}:${tag} --build-arg DISTRO=${DISTRO} \
---build-arg OVS_BRANCH=${OVS_BRANCH} \
---build-arg KERNEL_VERSION=${KERNEL_VERSION} \
---build-arg GITHUB_SRC=${GITHUB_SRC} -f ${DISTRO}/Dockerfile .
-
-.PHONY: build
-
-push: ;docker push ${REPO}:${tag}
diff --git a/utilities/docker/automake.mk b/utilities/docker/automake.mk
new file mode 100644
index 000000000..1ca3702be
--- /dev/null
+++ b/utilities/docker/automake.mk
@@ -0,0 +1,53 @@
+DIR := utilities/docker
+
+OVS_BRANCH ?= branch-2.11
+OVS_VERSION ?= 2.11
+KERNEL_VERSION ?= 4.15.0-54-generic
+DISTRO ?= debian
+GITHUB_SRC ?= https://github.com/openvswitch/ovs.git
+DOCKER_REPO ?= openvswitch/ovs
+DOCKER_TAG ?= ${OVS_VERSION}_${DISTRO}_${KERNEL_VERSION}
+DOCKER_SERVER ?= localhost:5000
+
+.PHONY: docker-registry
+docker-registry:
+	docker rm --force registry 2>/dev/null || true
+	docker run -d -p 5000:5000 --restart=always --name registry registry:2
+	@echo
+	@echo "# For using local repo set:"
+	@echo "export DOCKER_REPO=localhost:5000/openvswitch/ovs"
+	@echo
+	@echo "# For returning to public repo set:"
+	@echo "export DOCKER_REPO=openvswitch/ovs"
+
+$(DIR)/vswitch.ovsschema: vswitchd/vswitch.ovsschema
+	cp $< $@
+
+$(DIR)/ovsdb-tool: ovsdb/ovsdb-tool
+	cp $< $@
+
+.PHONY: docker-build
+docker-build: $(DIR)/vswitch.ovsschema $(DIR)/ovsdb-tool
+	cd $(DIR) && docker build -t ${DOCKER_REPO}:${DOCKER_TAG} \
+		--build-arg DISTRO=${DISTRO} \
+		--build-arg OVS_BRANCH=${OVS_BRANCH} \
+		--build-arg KERNEL_VERSION=${KERNEL_VERSION} \
+		--build-arg GITHUB_SRC=${GITHUB_SRC} \
+		-f ${DISTRO}/Dockerfile .
+
+.PHONY: docker-push
+docker-push:
+	cd $(DIR) && docker push ${DOCKER_REPO}:${DOCKER_TAG}
+
+.PHONY: docker-ovsdb-server
+docker-ovsdb-server:
+	docker rm --force ovsdb-server 2>/dev/null || true
+	docker run -itd --net=host --name=ovsdb-server \
+		${DOCKER_REPO}:${DOCKER_TAG} ovsdb-server
+
+.PHONY: docker-ovs-vswitchd
+docker-ovs-vswitchd:
+	docker rm --force ovs-vswitchd 2>/dev/null || true
+	docker run -itd --net=host --name=ovs-vswitchd \
+		--volumes-from=ovsdb-server -v /lib:/lib --privileged \
+		${DOCKER_REPO}:${DOCKER_TAG} ovs-vswitchd
diff --git a/utilities/docker/debian/Dockerfile b/utilities/docker/debian/Dockerfile
index ed4baa8f9..be8e79277 100644
--- a/utilities/docker/debian/Dockerfile
+++ b/utilities/docker/debian/Dockerfile
@@ -6,14 +6,15 @@ ARG KERNEL_VERSION
 ARG GITHUB_SRC
 ARG DISTRO
 
-copy $DISTRO/build-kernel-modules.sh /build-kernel-modules.sh
+COPY $DISTRO/build-kernel-modules.sh /build-kernel-modules.sh
 RUN /build-kernel-modules.sh $KERNEL_VERSION $OVS_BRANCH $GITHUB_SRC
 
+COPY vswitch.ovsschema /usr/share/openvswitch/vswitch.ovsschema
+COPY ovsdb-tool /bin/ovsdb-tool
 COPY create_ovs_db.sh /etc/openvswitch/create_ovs_db.sh
 RUN /etc/openvswitch/create_ovs_db.sh
 
 COPY ovs-override.conf /etc/depmod.d/openvswitch.conf
-
 COPY start-ovs /bin/start-ovs
 VOLUME ["/var/log/openvswitch", "/var/lib/openvswitch",\
  "/var/run/openvswitch", "/etc/openvswitch"]
-- 
2.25.1



More information about the dev mailing list