Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 2e7cd1c

Browse files
committed
update Makefile
Makefile now only runs docker build Signed-off-by: John O'Loughlin <[email protected]>
1 parent a909934 commit 2e7cd1c

File tree

2 files changed

+17
-291
lines changed

2 files changed

+17
-291
lines changed

Diff for: Makefile

+16-290
Original file line numberDiff line numberDiff line change
@@ -1,304 +1,30 @@
1-
SUDO?=sudo
2-
OS_ID = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
3-
OS_VERSION_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
1+
IMAGE_REGISTRY?=localhost:5000/
2+
IMAGE_VERSION?=latest
3+
IMAGE_BUILDER?=docker
44

5-
ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
6-
PKG=deb
7-
else ifeq ($(filter rhel centos fedora opensuse opensuse-leap opensuse-tumbleweed,$(OS_ID)),$(OS_ID))
8-
PKG=rpm
9-
endif
5+
IMAGE_NAME?=$(IMAGE_REGISTRY)userspacecni:$(IMAGE_VERSION)
106

11-
#
12-
# Unit test specific variables
13-
#
14-
UT_IMAGE=userspace_cni_plugin
15-
UT_GO_VERSION=1.14.3
16-
UT_OS_CENTOS=centos7 centos8
17-
UT_OS_FEDORA=fedora31 fedora32
18-
UT_OS_UBUNTU=ubuntu16.04 ubuntu18.04 ubuntu20.04
19-
UT_OS_DEFAULT=ubuntu20.04
20-
UT_OS_ALL=$(UT_OS_CENTOS) $(UT_OS_FEDORA) $(UT_OS_UBUNTU)
21-
TEST_TARGETS=$(addprefix test-,$(UT_OS_ALL))
22-
TEST_BUILD_TARGETS=$(addprefix test-build-,$(UT_OS_ALL))
23-
COVERAGE_TARGETS=$(addprefix coverage-,$(UT_OS_ALL))
24-
25-
# Get hash of recent commit for IMAGE tagging
26-
GIT_HASH=$(shell git rev-parse --short HEAD)
27-
28-
# Fail in case that unsupported UT_OS is set
29-
ifeq ($(filter $(UT_OS), $(UT_OS_ALL)),)
30-
ifneq ($(UT_OS),)
31-
$(warning Unsupported unit test OS was selected: UT_OS=$(UT_OS))
32-
$(error Supported values are: $(UT_OS_ALL))
33-
endif
34-
UT_OS=$(UT_OS_DEFAULT)
35-
endif
36-
37-
#
38-
# VPP Variables
39-
#
40-
VPPGPG=ge4a0f9f~b72
41-
VPPMAJOR=19
42-
VPPMINOR=04
43-
VPPDOTRL=1
44-
45-
VPPVERSION=$(VPPMAJOR)$(VPPMINOR)
46-
VPPDOTVERSION=$(VPPMAJOR).$(VPPMINOR).$(VPPDOTRL)
47-
ifeq ($(VPPDOTRL),0)
48-
VPPDOTVERSION=$(VPPMAJOR).$(VPPMINOR)
49-
else
50-
VVPPDOTVERSION=$(VPPMAJOR).$(VPPMINOR).$(VPPDOTRL)
51-
endif
52-
53-
ifeq ($(PKG),rpm)
54-
VPPLIBDIR=/usr/lib64
55-
else ifeq ($(PKG),deb)
56-
VPPLIBDIR=/usr/lib/x86_64-linux-gnu
57-
endif
58-
59-
# Building the cnivpp subfolder requires VPP to be installed, or at least a
60-
# handful of files in the proper installed location. VPPINSTALLED indicates
61-
# if required VPP files are installed.
62-
# For 'make clean', VPPLCLINSTALLED indicates if 'make install' installed
63-
# the minimum set of files or if VPP is actually installed.
64-
ifeq ($(shell test -e $(VPPLIBDIR)/libvppapiclient.so && echo -n yes),yes)
65-
VPPINSTALLED=1
66-
ifeq ($(shell test -e /usr/bin/vpp && echo -n yes),yes)
67-
VPPLCLINSTALLED=0
68-
else
69-
VPPLCLINSTALLED=1
70-
endif
71-
else
72-
VPPINSTALLED=0
73-
VPPLCLINSTALLED=0
74-
endif
75-
76-
77-
# Default to build
787
default: build
79-
all: build
8+
all: build deploy
809

8110

8211
help:
8312
@echo "Make Targets:"
84-
@echo " make - Build UserSpace CNI."
85-
@echo " make clean - Cleanup all build artifacts. Will remove VPP files installed from *make install*."
86-
@echo " make install - If VPP is not installed, install the minimum set of files to build."
87-
@echo " CNI-VPP will fail because VPP is still not installed."
88-
@echo " make install-dep - Install software dependencies, currently only needed for *make install*."
89-
@echo " make extras - Build *usrsp-app*, small binary to run in Docker container for testing."
90-
@echo " make test-app - Build test code."
91-
@echo ""
92-
@echo "Make Targets for unit testing inside containers:"
93-
@echo " make test-clean - Remove test container images and generated Dockerfiles."
94-
@echo " make test-build - Build container image for unit tests with OS defined by UT_OS: UT_OS="$(UT_OS)
95-
@echo " make test - Run unit tests inside container with OS defined by UT_OS: UT_OS="$(UT_OS)
96-
@echo " make coverage - Calculate code coverage in container with OS defined by UT_OS: UT_OS="$(UT_OS)
97-
@echo " make test-build-<os> - Build container image for unit tests with <os>, e.g. make test-build-centos8"
98-
@echo " make test-<os> - Run unit tests inside container with <os>, e.g. make test-centos8"
99-
@echo " make coverage-<os> - Calculate code coverage inside container with <os>, e.g. make coverage-centos8"
100-
@echo " make test-build-all - Build container images for unit tests for all supported OS distributions"
101-
@echo " e.g. make -j 5 test-build-all"
102-
@echo " make test-all - Run unit tests inside container for all supported OS distributions"
103-
@echo " e.g. make -j 5 test-all"
104-
@echo " make coverage-all - Calculate code coverage inside container for all supported OS distributions."
105-
@echo " e.g. make -j 5 coverage-all"
106-
@echo ""
107-
@echo " Supported OS distributions for unit testing are: $(UT_OS_ALL)"
108-
@echo ""
109-
# @echo "Makefile variables (debug):"
110-
# @echo " SUDO=$(SUDO) OS_ID=$(OS_ID) OS_VERSION_ID=$(OS_VERSION_ID) PKG=$(PKG) VPPVERSION=$(VPPVERSION) $(VPPDOTVERSION)"
111-
# @echo " VPPLIBDIR=$(VPPLIBDIR)"
112-
# @echo " VPPINSTALLED=$(VPPINSTALLED) VPPLCLINSTALLED=$(VPPLCLINSTALLED)"
113-
# @echo ""
114-
115-
build: generate
116-
@cd userspace && go build -v
117-
118-
test-app:
119-
@cd cnivpp/test/memifAddDel && go build -v
120-
@cd cnivpp/test/vhostUserAddDel && go build -v
121-
@cd cnivpp/test/ipAddDel && go build -v
122-
123-
install-dep:
124-
ifeq ($(VPPINSTALLED),0)
125-
ifeq ($(PKG),rpm)
126-
@$(SUDO) -E yum install -y wget cpio rpm
127-
else ifeq ($(PKG),deb)
128-
@$(SUDO) -E apt-get install -y binutils wget
129-
endif
130-
endif
131-
132-
install:
133-
go get go.fd.io/govpp/cmd/[email protected]
134-
ifeq ($(VPPINSTALLED),0)
135-
@echo VPP not installed, installing required files. Run *sudo make clean* to remove installed files.
136-
@mkdir -p tmpvpp/
137-
ifeq ($(PKG),rpm)
138-
@cd tmpvpp && wget --content-disposition https://packagecloud.io/fdio/$(VPPVERSION)/packages/el/7/vpp-lib-$(VPPDOTVERSION)-1~$(VPPGPG).x86_64.rpm/download.rpm
139-
@cd tmpvpp && wget --content-disposition https://packagecloud.io/fdio/$(VPPVERSION)/packages/el/7/vpp-devel-$(VPPDOTVERSION)-1~$(VPPGPG).x86_64.rpm/download.rpm
140-
@cd tmpvpp && rpm2cpio ./vpp-devel-$(VPPDOTVERSION)-1~$(VPPGPG).x86_64.rpm | cpio -ivd \
141-
./usr/include/vpp-api/client/vppapiclient.h
142-
@cd tmpvpp && rpm2cpio ./vpp-lib-$(VPPDOTVERSION)-1~$(VPPGPG).x86_64.rpm | cpio -ivd \
143-
./usr/lib64/libsvm.so.$(VPPDOTVERSION) \
144-
./usr/lib64/libvlibmemoryclient.so.$(VPPDOTVERSION) \
145-
./usr/lib64/libvppapiclient.so.$(VPPDOTVERSION) \
146-
./usr/lib64/libvppinfra.so.$(VPPDOTVERSION)
147-
@cd tmpvpp && rpm2cpio ./vpp-lib-$(VPPDOTVERSION)-1~$(VPPGPG).x86_64.rpm | cpio -ivd \
148-
./usr/share/vpp/api/interface.api.json \
149-
./usr/share/vpp/api/l2.api.json \
150-
./usr/share/vpp/api/memif.api.json \
151-
./usr/share/vpp/api/vhost_user.api.json \
152-
./usr/share/vpp/api/vpe.api.json
153-
else ifeq ($(PKG),deb)
154-
@cd tmpvpp && wget --content-disposition https://packagecloud.io/fdio/release/packages/ubuntu/xenial/vpp_$(VPPDOTVERSION)-release_amd64.deb/download.deb
155-
@cd tmpvpp && wget --content-disposition https://packagecloud.io/fdio/release/packages/ubuntu/xenial/vpp-dev_$(VPPDOTVERSION)-release_amd64.deb/download.deb
156-
@cd tmpvpp && wget --content-disposition https://packagecloud.io/fdio/release/packages/ubuntu/xenial/libvppinfra_$(VPPDOTVERSION)-release_amd64.deb/download.deb
157-
@cd tmpvpp && wget --content-disposition https://packagecloud.io/fdio/release/packages/ubuntu/xenial/vpp-plugin-core_$(VPPDOTVERSION)-release_amd64.deb/download.deb
158-
@cd tmpvpp && dpkg-deb --fsys-tarfile vpp-dev_$(VPPDOTVERSION)-release_amd64.deb | tar -x \
159-
./usr/include/vpp-api/client/vppapiclient.h
160-
@cd tmpvpp && dpkg-deb --fsys-tarfile libvppinfra_$(VPPDOTVERSION)-release_amd64.deb | tar -x \
161-
./usr/lib/x86_64-linux-gnu/libvppinfra.so.$(VPPDOTVERSION)
162-
@cd tmpvpp && dpkg-deb --fsys-tarfile vpp_$(VPPDOTVERSION)-release_amd64.deb | tar -x \
163-
./usr/share/vpp/api/core/interface.api.json \
164-
./usr/share/vpp/api/core/l2.api.json \
165-
./usr/share/vpp/api/core/vhost_user.api.json \
166-
./usr/share/vpp/api/core/vpe.api.json \
167-
./usr/lib/x86_64-linux-gnu/libsvm.so.$(VPPDOTVERSION) \
168-
./usr/lib/x86_64-linux-gnu/libvlibmemoryclient.so.$(VPPDOTVERSION) \
169-
./usr/lib/x86_64-linux-gnu/libvppapiclient.so.$(VPPDOTVERSION)
170-
@cd tmpvpp && dpkg-deb --fsys-tarfile vpp-plugin-core_$(VPPDOTVERSION)-release_amd64.deb | tar -x \
171-
./usr/share/vpp/api/plugins/memif.api.json
172-
endif
173-
@$(SUDO) -E mkdir -p /usr/include/vpp-api/client/
174-
@$(SUDO) -E cp tmpvpp/usr/include/vpp-api/client/vppapiclient.h /usr/include/vpp-api/client/.
175-
@$(SUDO) -E chown -R bin:bin /usr/include/vpp-api/
176-
@echo Installed /usr/include/vpp-api/client/vppapiclient.h
177-
@$(SUDO) -E cp tmpvpp$(VPPLIBDIR)/libsvm.so.$(VPPDOTVERSION) $(VPPLIBDIR)/.
178-
@$(SUDO) -E cp tmpvpp$(VPPLIBDIR)/libvlibmemoryclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/.
179-
@$(SUDO) -E cp tmpvpp$(VPPLIBDIR)/libvppapiclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/.
180-
@$(SUDO) -E cp tmpvpp$(VPPLIBDIR)/libvppinfra.so.$(VPPDOTVERSION) $(VPPLIBDIR)/.
181-
ifneq ($(VPPDOTRL),0)
182-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libsvm.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libsvm.so.$(VPPMAJOR).$(VPPMINOR)
183-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvlibmemoryclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvlibmemoryclient.so.$(VPPMAJOR).$(VPPMINOR)
184-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvppapiclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvppapiclient.so.$(VPPMAJOR).$(VPPMINOR)
185-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvppinfra.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvppinfra.so.$(VPPMAJOR).$(VPPMINOR)
186-
endif
187-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libsvm.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libsvm.so.$(VPPMAJOR)
188-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvlibmemoryclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvlibmemoryclient.so.$(VPPMAJOR)
189-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvppapiclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvppapiclient.so.$(VPPMAJOR)
190-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvppinfra.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvppinfra.so.$(VPPMAJOR)
191-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libsvm.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libsvm.so
192-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvlibmemoryclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvlibmemoryclient.so
193-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvppapiclient.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvppapiclient.so
194-
@$(SUDO) -E ln -s $(VPPLIBDIR)/libvppinfra.so.$(VPPDOTVERSION) $(VPPLIBDIR)/libvppinfra.so
195-
@$(SUDO) -E chown -R bin:bin $(VPPLIBDIR)/libsvm.so*
196-
@$(SUDO) -E chown -R bin:bin $(VPPLIBDIR)/libvlibmemoryclient.so*
197-
@$(SUDO) -E chown -R bin:bin $(VPPLIBDIR)/libvppapiclient.so*
198-
@$(SUDO) -E chown -R bin:bin $(VPPLIBDIR)/libvppinfra.so*
199-
@echo Installed $(VPPLIBDIR)/libsvm.so $(VPPLIBDIR)/libvlibmemoryclient.so $(VPPLIBDIR)/libvppapiclient.so $(VPPLIBDIR)/libvppinfra.so
200-
@$(SUDO) -E mkdir -p /usr/share/vpp/api/
201-
ifeq ($(PKG),rpm)
202-
@$(SUDO) -E cp tmpvpp/usr/share/vpp/api/*.json /usr/share/vpp/api/.
203-
else ifeq ($(PKG),deb)
204-
@$(SUDO) -E cp tmpvpp/usr/share/vpp/api/core/*.json /usr/share/vpp/api/.
205-
@$(SUDO) -E cp tmpvpp/usr/share/vpp/api/plugins/*.json /usr/share/vpp/api/.
206-
endif
207-
@$(SUDO) -E chown -R bin:bin /usr/share/vpp/
208-
@echo Installed /usr/share/vpp/api/*.json
209-
@rm -rf tmpvpp
210-
endif
211-
13+
@echo "make build - Build UserSpace CNI container."
14+
@echo "make deploy - Copy binary from container to host: /opt/cni/bin."
15+
@echo "make all - build and deploy"
21216

213-
extras:
214-
@cd docker/usrsp-app && go build -v
17+
build:
18+
@$(IMAGE_BUILDER) build . -f ./docker/userspacecni/Dockerfile -t $(IMAGE_NAME)
21519

216-
clean: test-clean
217-
@rm -f docker/usrsp-app/usrsp-app
218-
@rm -f cnivpp/test/memifAddDel/memifAddDel
219-
@rm -f cnivpp/test/vhostUserAddDel/vhostUserAddDel
220-
@rm -f cnivpp/test/ipAddDel/ipAddDel
221-
@rm -rf cnivpp/bin_api
222-
@rm -f userspace/userspace
223-
ifeq ($(VPPLCLINSTALLED),1)
224-
@echo VPP was installed by *make install*, so cleaning up files.
225-
@$(SUDO) -E rm -rf /usr/include/vpp-api/
226-
@$(SUDO) -E rm $(VPPLIBDIR)/libsvm.so*
227-
@$(SUDO) -E rm $(VPPLIBDIR)/libvlibmemoryclient.so*
228-
@$(SUDO) -E rm $(VPPLIBDIR)/libvppapiclient.so*
229-
@$(SUDO) -E rm $(VPPLIBDIR)/libvppinfra.so*
230-
@$(SUDO) -E rm -rf /usr/share/vpp/
20+
deploy:
21+
# Copying the ovs binary to host /opt/cni/bin/
22+
@mkdir -p /opt/cni/bin/
23+
@$(IMAGE_BUILDER) run -it --rm -v /opt/cni/bin/:/opt/cni/bin/ $(IMAGE_NAME)
23124

232-
endif
25+
generate-bin: generate
26+
@cd userspace && go build -v
23327

23428
generate:
235-
ifeq ($(VPPINSTALLED),0)
236-
@echo VPP not installed. Run *make install* to install the minimum set of files to compile, or install VPP.
237-
@echo
238-
endif
23929
for package in cnivpp/api/* ; do cd $$package ; pwd ; go generate ; cd - ; done
24030

241-
lint:
242-
243-
check-test-dep:
244-
@for TEST_DEP in docker cpp git ; do \
245-
if ! which $$TEST_DEP > /dev/null ; then \
246-
echo "$$TEST_DEP is required for unit test execution, please install it."; \
247-
exit 1; \
248-
fi \
249-
done
250-
251-
$(TEST_BUILD_TARGETS): test-build-%: check-test-dep
252-
@# Skip image build in case that image with recent code changes exists
253-
@if [ "`docker images -q $(UT_IMAGE):$*_$(GIT_HASH)`" = "" ] ; then \
254-
echo Build unit test image for $*; \
255-
cpp -o docker/unit-tests/Dockerfile.$* docker/unit-tests/Dockerfile.$*.in; \
256-
docker build . \
257-
-t $(UT_IMAGE):$* \
258-
-t $(UT_IMAGE):$*_$(GIT_HASH) \
259-
--build-arg UT_GO_VERSION=$(UT_GO_VERSION) \
260-
-f docker/unit-tests/Dockerfile.$*; \
261-
fi
262-
263-
test-build: test-build-$(UT_OS)
264-
265-
test-build-all: $(TEST_BUILD_TARGETS)
266-
267-
$(TEST_TARGETS): test-%: test-build-%
268-
@echo Run unit tests at $*
269-
@$(SUDO) docker run --rm --privileged $(UT_IMAGE):$*_$(GIT_HASH) bash -c \
270-
'UT_LIST=`find . -name "*_test.go" -not -path "./vendor/*" -exec dirname \{\} \; | sort -u`; \
271-
for UT_DIR in $$UT_LIST ; do \
272-
cd $${UT_DIR}; \
273-
go test -v || exit 1; \
274-
cd -; \
275-
done'
276-
277-
test: test-$(UT_OS)
278-
279-
test-all: $(TEST_TARGETS)
280-
281-
$(COVERAGE_TARGETS): coverage-%: test-build-%
282-
@echo Calculate code coverage at $*
283-
@$(SUDO) docker run --rm --privileged $(UT_IMAGE):$* bash -c "go-carpet -summary | sort"
284-
285-
coverage: coverage-$(UT_OS)
286-
287-
coverage-all: $(COVERAGE_TARGETS)
288-
289-
test-clean:
290-
@if which docker > /dev/null ; then \
291-
echo Remove unit test container images with name $(UT_IMAGE); \
292-
for IMAGE in `docker images -a -q --filter=reference=$(UT_IMAGE) | sort -u`; do \
293-
docker rmi -f $$IMAGE; \
294-
done; \
295-
echo Remove generated dockerfiles; \
296-
for IMAGEOS in $(UT_OS_ALL) ; do \
297-
rm -f docker/unit-tests/Dockerfile.$$IMAGEOS; \
298-
done; \
299-
else \
300-
echo "Docker is not installed, nothing to delete."; \
301-
fi
302-
303-
.PHONY: build test-app install extras clean generate check-test-dep test-clean test-build test-build-all \
304-
test test-all coverage coverage-all $(TEST_TARGETS) $(TEST_BUILD_TARGETS) $(COVERAGE_TARGETS)

Diff for: docker/userspacecni/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV PATH="${PATH}:/usr/local/go/bin"
99
RUN go mod download
1010
RUN make generate
1111
RUN go mod tidy
12-
RUN make build
12+
RUN make generate-bin
1313
#End of builder container
1414

1515
# Copy build userspace cni bin to a small deployer container

0 commit comments

Comments
 (0)