-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
48 lines (41 loc) · 1.68 KB
/
Makefile
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
## Define constants
VERSION=latest
TAG_PRE_BUILD_IMAGE=k8s-diag-pre
K8S_DIAG_IMAGE=k8s-diagnose
FULL_URL_IMAGE=registry.cn-hangzhou.aliyuncs.com/wise2c-dev/$(K8S_DIAG_IMAGE):$(VERSION)
#FULL_URL_IMAGE=registry.cn-hangzhou.aliyuncs.com/solomonxu/$(K8S_DIAG_IMAGE):$(VERSION)
## Check docker image pre-build-image if existed
pre-image-count := $(shell docker images | grep $(TAG_PRE_BUILD_IMAGE) | wc -l)
pre-image-id := $(shell docker images | grep $(TAG_PRE_BUILD_IMAGE) | grep centos | awk '{print $$3}')
diag-image-id := $(shell docker images | grep $(K8S_DIAG_IMAGE) | grep $(VERSION) | awk '{print $$3}')
## .PHONY
.PHONY: all image-pre
## Build all
all: pre-build-image
# echo "This will make Docker image $(K8S_DIAG_IMAGE) ..."
docker build -f Dockerfile -t $(K8S_DIAG_IMAGE):$(VERSION) .
## Build pre-build-image
pre-build-image:
@if [ "$(pre-image-count)" = "0" ]; then \
# echo "This will make Docker image centos:$(TAG_PRE_BUILD_IMAGE) ..."; \
docker build -f Dockerfile.pre -t centos:$(TAG_PRE_BUILD_IMAGE) . ; \
else \
# echo "Docker image centos:$(TAG_PRE_BUILD_IMAGE) has existed. Omit step of pre-build-image."; \
echo ""; \
fi
## Cleanup images
cleanup: cleanup-diag
@if [ -n "$(pre-image-id)" ]; then \
echo "This will remove Docker image centos:$(TAG_PRE_BUILD_IMAGE) now, IMAGE ID: $(pre-image-id)."; \
docker rmi $(pre-image-id) ; \
fi
## Cleanup image k8s-diagnose
cleanup-diag:
@if [ -n "$(diag-image-id)" ]; then \
echo "This will remove Docker image $(K8S_DIAG_IMAGE) now, IMAGE ID: $(diag-image-id)."; \
docker rmi $(diag-image-id) ; \
fi
## Push to repository
push:
docker tag $(K8S_DIAG_IMAGE):$(VERSION) $(FULL_URL_IMAGE)
docker push $(FULL_URL_IMAGE)