forked from vrnetlab/vrnetlab
-
Notifications
You must be signed in to change notification settings - Fork 95
/
makefile.include
64 lines (52 loc) · 2.5 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
IMG_NAME=$(shell echo $(NAME) | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
IMG_VENDOR=$(shell echo $(VENDOR) | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
IMAGES=$(shell ls $(IMAGE_GLOB) 2>/dev/null)
NUM_IMAGES=$(shell ls $(IMAGES) | wc -l)
VRNETLAB_VERION=$$(git log -1 --format=format:"Commit: %H from %aD")
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; \
$(MAKE) IMAGE=$$IMAGE docker-clean-build; \
done
endif
docker-clean-build:
@echo "--> Cleaning docker build context"
-rm -f docker/*.qcow2* docker/*.tgz* docker/*.vmdk* docker/*.iso docker/*.xml docker/*.bin
-rm -f docker/healthcheck.py docker/vrnetlab.py
docker-pre-build: ;
docker-build-image-copy:
cp $(IMAGE)* docker/
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/hellt/vrnetlab/issues/new including the image file name you are using."; exit 1; fi
@echo "Building docker image using $(IMAGE) as $(REGISTRY)$(IMG_VENDOR)_$(IMG_NAME):$(VERSION)"
ifeq ($(NOT_VM_IMAGE), 1)
echo "ok"
else
cp ../common/* docker/
endif
@[ -f ./vswitch.xml ] && cp vswitch.xml docker/ || true
$(MAKE) IMAGE=$$IMAGE docker-build-image-copy
(cd docker; docker build --build-arg http_proxy=$(http_proxy) --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg https_proxy=$(https_proxy) --build-arg HTTPS_PROXY=$(HTTPS_PROXY) --build-arg IMAGE=$(IMAGE) --build-arg VERSION=$(VERSION) --label "vrnetlab-version=$(VRNETLAB_VERION)" -t $(REGISTRY)$(IMG_VENDOR)_$(IMG_NAME):$(VERSION) .)
docker-build: docker-build-common docker-clean-build
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 $(REGISTRY)$(VENDOR)_$(NAME):$(VERSION)
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)
all: docker-image