forked from vrnetlab/vrnetlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile.include
88 lines (69 loc) · 3.03 KB
/
makefile.include
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
VR_NAME=$(shell basename $$(pwd))
IMAGES=$(shell ls $(IMAGE_GLOB) 2>/dev/null)
NUM_IMAGES=$(shell ls $(IMAGES) | wc -l)
ifeq ($(NUM_IMAGES), 0)
docker-image: no-image usage
else
docker-image:
for IMAGE in $(IMAGES); do \
echo "Making $$IMAGE"; \
$(MAKE) IMAGE=$$IMAGE docker-build; \
done
endif
docker-clean-build:
-rm -f docker/*.qcow2* docker/*.tgz* docker/*.vmdk* docker/*.iso
docker-pre-build:: ;
docker-build-image-copy:
cp $(IMAGE)* docker/
TAG_NAME = $(REGISTRY)vr-$(VR_NAME):$(VERSION)
ifeq ($(PNS),)
PNS:=$(shell whoami | sed 's/[^[:alnum:]._-]\+/_/g')
endif
docker-build-common: docker-clean-build docker-pre-build
@if [ -z "$$IMAGE" ]; then echo "ERROR: No IMAGE specified"; exit 1; fi
@if [ "$(IMAGE)" = "$(VERSION)" ]; then echo "ERROR: Incorrect version string ($(IMAGE)). The regexp for extracting version information is likely incorrect, check the regexp in the Makefile or open an issue at https://github.com/plajjan/vrnetlab/issues/new including the image file name you are using."; exit 1; fi
@echo "Building docker image using $(IMAGE) as $(TAG_NAME)"
cp ../common/* docker/
$(MAKE) IMAGE=$$IMAGE docker-build-image-copy
(cd docker; docker build --build-arg http_proxy=$(http_proxy) --build-arg https_proxy=$(https_proxy) --build-arg IMAGE=$(IMAGE) --build-arg VERSION=$(VERSION) -t $(TAG_NAME) .)
docker-build: docker-build-common
docker-push:
for IMAGE in $(IMAGES); do \
$(MAKE) IMAGE=$$IMAGE docker-push-image; \
done
docker-push-image:
@if [ -z "$$IMAGE" ]; then echo "ERROR: No IMAGE specified"; exit 1; fi
@if [ "$(IMAGE)" = "$(VERSION)" ]; then echo "ERROR: Incorrect version string"; exit 1; fi
docker push $(TAG_NAME)
usage:
@echo "Usage: put the $(VENDOR) $(NAME) $(IMAGE_FORMAT) image in this directory and run:"
@echo " make"
no-image:
@echo "ERROR: you have no $(IMAGE_FORMAT) ($(IMAGE_GLOB)) image"
version-test:
@echo Extracting version from filename $(IMAGE)
@echo Version: $(VERSION)
docker-test:
set -xe; for IMAGE in $(IMAGES); do \
$(MAKE) IMAGE=$$IMAGE docker-test-image; \
done
CNT_PREFIX ?= $(PNS)-test-image-$(VR_NAME)-$(VERSION)
TEST_TIMEOUT ?= 2400
docker-test-image: CONTAINER_NAME?=$(CNT_PREFIX)-dut
docker-test-image:
# Run the test script in a container to ensure:
# 1. we have all the tooling available,
# 2. the test container and the device under test container end up in the same network.
# We attach the hosts docker socket to allow creating new containers, but cannot
# bind mount the working directory from a sibling container ..
-docker rm -f $(CNT_PREFIX)
docker create -t --name $(CNT_PREFIX) -v /var/run/docker.sock:/var/run/docker.sock vrnetlab/ci-builder /test-image -t $(TEST_TIMEOUT) $(TAG_NAME) $(CONTAINER_NAME) $(TEST_PARAMS)
docker cp $(CURDIR)/../test/test-image $(CNT_PREFIX):/
docker start --attach $(CNT_PREFIX)
docker-test-clean:
docker ps -aqf name=$(CNT_PREFIX) | xargs --no-run-if-empty docker rm -f
docker-test-save-logs:
for cnt in `docker ps -af name=$(CNT_PREFIX) --format '{{.Names}}'`; do \
docker logs $${cnt} > $${cnt}.log 2>&1; \
done
all: docker-image