forked from kubernetes-sigs/kubespray
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
133 lines (108 loc) · 4.84 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# The old school Makefile, following are required targets. The Makefile is written
# to allow building multiple binaries. You are free to add more targets or change
# existing implementations, as long as the semantics are preserved.
#
# make - default to 'build' target
# make lint - code analysis
# make release-image - build cluster-deploy-job image
# make base-image - build kubespray base image
# $ docker login registry -u username -p xxxxx
# make push - push cluster-deploy-job image to registrys
# make save - save cluster-deploy-job image to xxx.tar.gz
# make convert-images - convert images from download.yml into images list
#
# Not included but recommended targets:
# make e2e-test
#
# The makefile is also responsible to populate project version information.
#
#
# Tweak the variables based on your project.
# Module name.
NAME := cluster-deploy-job
# Container image prefix and suffix added to targets.
# The final built images are:
# $[REGISTRY]/$[IMAGE_PREFIX]$[TARGET]$[IMAGE_SUFFIX]:$[VERSION]
# $[REGISTRY] is an item from $[REGISTRIES], $[TARGET] is an item from $[TARGETS].
IMAGE_PREFIX ?= $(strip )
IMAGE_SUFFIX ?= $(strip )
# Container registries.
REGISTRY ?= cargo.dev.caicloud.xyz/release
# Container registry for base images.
BASE_REGISTRY ?= cargo.caicloud.xyz/library
DEVOPS_REGISTRY ?= cargo.caicloud.xyz/devops_release
RELEASE_TIME ?= $(shell date +'%Y-%m-%d')
IMGAES_LIST_DIR ?= ./images-lists
IMAGE_ARCH ?= amd64
DOWNLOAD_YAML_FILE ?= ./inventory/deploy-cluster/group_vars/all/download.yml
SAVE_PATH ?= /tmp
BASE_IMAGE_VERSION ?= 18.04-kubespray-v0.1.1
KUBESPRAY_BASE_IMAGE ?= $(BASE_REGISTRY)/ubuntu:$(BASE_IMAGE_VERSION)
KEEPALIVED_VERSION ?= v0.1.0
#
# These variables should not need tweaking.
#
# It's necessary to set this because some environments don't link sh -> bash.
export SHELL := /bin/bash
# It's necessary to set the errexit flags for the bash shell.
export SHELLOPTS := errexit
IMAGE_NAME := $(IMAGE_PREFIX)$(NAME)$(IMAGE_SUFFIX)
# Current version of the project.
VERSION ?= $(shell git describe --tags --always --dirty)
BRANCH ?= $(shell git branch | grep \* | cut -d ' ' -f2)
GITCOMMIT ?= $(shell git rev-parse HEAD)
GITTREESTATE ?= $(if $(shell git status --porcelain),dirty,clean)
BUILDDATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Track code version with Docker Label.
DOCKER_LABELS ?= git-describe="$(shell date -u +v%Y%m%d)-$(shell git describe --tags --always --dirty)"
#
# Define all targets. At least the following commands are required:
#
# All targets.
.PHONY: lint release-image base-image push save
release-image:
@sed -i- "s|KUBESPRAY_BASE_IMAGE|$(KUBESPRAY_BASE_IMAGE)|" build/cluster-deploy-job/Dockerfile
@docker build --no-cache -t $(REGISTRY)/$(IMAGE_NAME):$(VERSION) \
--label $(DOCKER_LABELS) -f build/cluster-deploy-job/Dockerfile .
@mv -f build/cluster-deploy-job/Dockerfile- build/cluster-deploy-job/Dockerfile
base-image:
@docker build --no-cache -t $(KUBESPRAY_BASE_IMAGE) \
--label $(DOCKER_LABELS) -f build/kubespray-base-image/Dockerfile .
keepalived-image:
@docker build --no-cache -t $(REGISTRY)/keepalived:$(KEEPALIVED_VERSION) \
-f build/keepalived/Dockerfile .
push: release-image
@docker push $(REGISTRY)/$(IMAGE_NAME):$(VERSION);
base-push: base-image
@docker push $(KUBESPRAY_BASE_IMAGE)
keepalived-push: keepalived-image
@docker push $(REGISTRY)/keepalived:$(KEEPALIVED_VERSION)
save: release-image
@echo "[info] start save to file path: $(SAVE_PATH) ..."
@docker tag $(REGISTRY)/$(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):$(VERSION)
@docker save -o $(SAVE_PATH)/$(IMAGE_NAME)-$(VERSION).tar $(IMAGE_NAME):$(VERSION)
@gzip -f $(SAVE_PATH)/$(IMAGE_NAME)-$(VERSION).tar
@echo "[info] save image finish"
lint:
@bash hack/lint/lint.sh
.PHONY: convert-images check-images
# convert images in download.yml file to images list
convert-images:
@mkdir -p $(IMGAES_LIST_DIR)
@grep -Ev "^#|^$$|kubelet|kubeadm|---|\{%|%\}" $(DOWNLOAD_YAML_FILE) \
| sed 's|{{ |$${|g;s| }}|}|g;s|: |=|g;s|"||g;s|image_arch=.*|image_arch=$(IMAGE_ARCH)|' > convert.sh
@grep 'image_name=' convert.sh | awk -F "=" '{print $1}' | sed 's|^|$${|g;s|$$|}|g;s|^|echo |g' >> convert.sh
@bash convert.sh | sed 's|^/||g' | grep -E '^release|^library' | sort -nr | uniq > $(IMGAES_LIST_DIR)/images_kubernetes.list
@cat $(IMGAES_LIST_DIR)/images_kubernetes.list
@rm -f convert.sh
# check if images exists in images-lists directory
check-images: convert-images
@find $(IMGAES_LIST_DIR) -type f -name "images*.list" \
| xargs -L1 sed -n 's|^release|$(DEVOPS_REGISTRY)|p;s|^library|$(BASE_REGISTRY)|p' \
| xargs -L1 -P 16 -I {} skopeo inspect --raw docker://{} > /dev/null
.PHONY: mitogen clean
mitogen:
ansible-playbook -c local mitogen.yml -vv
clean:
rm -rf dist/
rm *.retry