-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
187 lines (151 loc) · 6.17 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Include common definitions
include Makefile.def
# Default target
.PHONY: all
all: images
# Build targets
.PHONY: build-binaries
build-binaries: build-controller build-agent
.PHONY: build-controller
build-controller:
$(GO_BUILD) -o $(BIN_DIR)/controller cmd/controller/main.go
.PHONY: build-agent
build-agent:
$(GO_BUILD) -o $(BIN_DIR)/agent cmd/agent/main.go
# Image targets
.PHONY: images
images: controller-image agent-image tools-image
.PHONY: controller-image
controller-image:
docker build $(DOCKER_BUILD_FLAGS) -t $(CONTROLLER_IMAGE_REF) -f image/controller/Dockerfile .
.PHONY: agent-image
agent-image:
docker build $(DOCKER_BUILD_FLAGS) -t $(AGENT_IMAGE_REF) -f image/agent/Dockerfile .
.PHONY: tools-image
tools-image: build-tools-image
.PHONY: build-tools-image
build-tools-image:
docker build -t $(TOOLS_IMAGE_REF) -f image/tools/Dockerfile image/tools
# Helm chart
#================== chart
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CHART_DIR := $(ROOT_DIR)/chart
DESTDIR_CHART ?= $(ROOT_DIR)/output/chart
.PHONY: chart_package
chart_package: lint_chart_format lint_chart_version
-@rm -rf $(DESTDIR_CHART)
-@mkdir -p $(DESTDIR_CHART)
cd $(DESTDIR_CHART) ; \
echo "package chart " ; \
helm package $(CHART_DIR) ; \
.PHONY: update_chart_version
update_chart_version:
VERSION=`cat VERSION | tr -d '\n' ` ; [ -n "$${VERSION}" ] || { echo "error, wrong version" ; exit 1 ; } ; \
echo "update chart version to $${VERSION}" ; \
CHART_VERSION=`echo $${VERSION} | tr -d 'v' ` ; \
sed -E -i 's?^version: .*?version: '$${CHART_VERSION}'?g' $(CHART_DIR)/Chart.yaml &>/dev/null ; \
sed -E -i 's?^appVersion: .*?appVersion: "'$${CHART_VERSION}'"?g' $(CHART_DIR)/Chart.yaml &>/dev/null ; \
echo "version of all chart is right"
.PHONY: lint_chart_format
lint_chart_format:
mkdir -p $(DESTDIR_CHART) ; \
echo "check chart" ; \
helm lint --with-subcharts $(CHART_DIR)
.PHONY: lint_chart_version
lint_chart_version:
VERSION=`cat VERSION | tr -d '\n' ` ; [ -n "$${VERSION}" ] || { echo "error, wrong version" ; exit 1 ; } ; \
echo "check chart version $${VERSION}" ; \
CHART_VERSION=`echo $${VERSION} | tr -d 'v' ` ; \
grep -E "^version: $${CHART_VERSION}" $(CHART_DIR)/Chart.yaml &>/dev/null || { echo "error, wrong version in Chart.yaml" ; exit 1 ; } ; \
grep -E "^appVersion: \"$${CHART_VERSION}\"" $(CHART_DIR)/Chart.yaml &>/dev/null || { echo "error, wrong appVersion in Chart.yaml" ; exit 1 ; } ; \
echo "version of all chart is right"
#================= update golang
GO_VERSION := $(shell cat GO_VERSION | tr -d '\n' )
GO_IMAGE_VERSION = $(shell echo ${GO_VERSION} | awk -F. '{ z=$$3; if (z == "") z=0; print $$1 "." $$2 "." z}' )
#GO_MAJOR_AND_MINOR_VERSION = $(shell echo "${GO_VERSION}" | grep -o -E '^[0-9]+\.[0-9]+' )
## Update Go version for all the components
.PHONY: update_go_version
update_go_version: update_images_dockerfile_golang update_mod_golang update_workflow_golang
.PHONY: update_images_dockerfile_golang
update_images_dockerfile_golang:
echo "update images dockerfile golang to $(GO_VERSION)"
GO_VERSION=$(GO_VERSION) $(ROOT_DIR)/tools/scripts/update-golang-image.sh
# Update Go version for GitHub workflow
.PHONY: update_workflow_golang
update_workflow_golang:
echo "update workflow golang to ${GO_IMAGE_VERSION}" ; \
for fl in $(shell find .github/workflows -name "*.yaml" -print) ; do \
sed -i 's/go-version: .*/go-version: '${GO_IMAGE_VERSION}'/g' $$fl ; \
done
# Update Go version in go.mod
.PHONY: update_mod_golang
update_mod_golang:
echo "update go.mod to ${GO_VERSION}" ; \
sed -i -E 's/^go .*/go '"${GO_VERSION}"'/g' go.mod
#-------------------------------------------
# E2E tests
.PHONY: e2e e2e-clean uninstall_e2e
# Run E2E tests
e2e:
@echo "Setting up E2E test environment..."
$(MAKE) -C test clean
$(MAKE) -C test init
$(MAKE) -C test installDeps
$(MAKE) -C test deploy
$(MAKE) -C test installDepsRedfish
@echo "E2E environment setup completed"
# Clean up E2E environment
e2e-clean:
@echo "Cleaning up E2E environment..."
$(MAKE) -C test clean
@echo "E2E environment cleanup completed"
# Uninstall E2E environment
uninstall_e2e:
@echo "Uninstalling E2E environment..."
$(MAKE) -C test kind-delete
@echo "E2E environment uninstalled successfully"
# Cleanup
.PHONY: clean
clean:
rm -rf $(BIN_DIR)
rm -f *.tgz
.PHONY: update_crd_sdk
update_crd_sdk:
@ echo "update crd manifest" && ./tools/golang/crdControllerGen.sh
@ echo "update crd sdk" && ./tools/golang/crdSdkGen.sh
.PHONY: validate_crd_sdk
validate_crd_sdk:
@ echo "validate crd manifest"
make update_crd_sdk ; \
if ! test -z "$$(git status --porcelain)"; then \
echo "please run 'make update_crd_sdk' to update crd code" ; \
exit 1 ; \
fi ; echo "succeed to check crd sdk"
# Help
.PHONY: usage
usage:
@echo "Available targets:"
@echo " all - Build binaries, container images, and Helm chart"
@echo " build-binaries - Build controller and agent binaries"
@echo " build-controller - Build controller binary"
@echo " build-agent - Build agent binary"
@echo " images - Build container images"
@echo " controller-image - Build controller container image"
@echo " agent-image - Build agent container image"
@echo " tools-image - Build tools container image"
@echo " chart - Package Helm chart"
@echo " e2e - Run E2E tests"
@echo " e2e-clean - Clean up E2E environment"
@echo " uninstall_e2e - Uninstall E2E environment"
@echo " clean - Remove build artifacts"
@echo " usage - Show this help message"
@echo ""
@echo "Environment variables:"
@echo " VERSION - Version tag for images (default: from git commit hash)"
@echo " REGISTRY - Container image registry (default: ghcr.io/spidernet-io)"
@echo " IMAGE_NAMESPACE - Container image namespace for tools (default: bmc)"
@echo " TOOLS_IMAGE_NAME - Name of the tools image (default: tools)"
@echo " TOOLS_IMAGE_TAG - Tag of the tools image (default: latest)"
@echo " GOOS - Target OS for build (default: linux)"
@echo " GOARCH - Target architecture for build (default: amd64)"
@echo " CGO_ENABLED - Enable CGO for build (default: 0)"