-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
187 lines (140 loc) · 5.06 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
SHELL := bash
SRC_DIR=$(shell pwd)
BUILD_DIR=$(SRC_DIR)/build
GO_TOOLCHAIN ?= $(BUILD_DIR)/go
GO_VERSION := 1.21.7
GO_DOWNLOAD_URL=https://dl.google.com/go/go$(GO_VERSION).$(shell uname)-amd64.tar.gz
ifneq ($(GO_TOOLCHAIN),"")
export GOROOT:=$(GO_TOOLCHAIN)
export PATH:=$(GO_TOOLCHAIN)/bin:$(PATH)
endif
HELM_BIN := "$(or $(HELM), helm)"
OPERATOR_STAGE_DIR=$(BUILD_DIR)/operator
OPERATOR_EXE=$(OPERATOR_STAGE_DIR)/decco-operator
OPERATOR_IMAGE_NAME := decco-operator
OPERATOR_IMAGE_MARKER=$(OPERATOR_STAGE_DIR)/image-marker
SPRINGBOARD_STAGE_DIR=$(BUILD_DIR)/springboard-stunnel
SPRINGBOARD_EXE=$(SPRINGBOARD_STAGE_DIR)/springboard
SPRINGBOARD_IMAGE_NAME := springboard-stunnel
SPRINGBOARD_IMAGE_MARKER=$(SPRINGBOARD_STAGE_DIR)/image-marker
# Override with your own Docker registry tag(s)
REPO_TAG ?= platform9/$(OPERATOR_IMAGE_NAME)
VERSION ?= $(shell cat ${SRC_DIR}/VERSION)
BUILD_NUMBER ?= 000
BUILD_ID := $(BUILD_NUMBER)
IMAGE_TAG ?= $(VERSION)-$(BUILD_ID)
FULL_TAG := $(REPO_TAG):$(IMAGE_TAG)
TAG_FILE := $(BUILD_DIR)/container-full-tag
STUNNEL_CONTAINER_TAG ?= platform9/stunnel:5.56-102
SPRINGBOARD_REPO_TAG ?= platform9/$(SPRINGBOARD_IMAGE_NAME)
SPRINGBOARD_FULL_TAG := $(SPRINGBOARD_REPO_TAG):$(IMAGE_TAG)
CHART_DIR := deploy/
GORELEASER ?= ${SRC_DIR}/hack/goreleaser-docker.sh
.PHONY: all
all: operator springboard
.PHONY: release
release: release-clean verify test $(BUILD_DIR) ## Build and release Decco, publishing the artifacts on Github and Dockerhub.
$(GORELEASER) release --rm-dist
# Output a file with the published Docker image tag exactly the same as `make container-full-tag`
echo -n "$(REPO_TAG):$(VERSION)" > $(BUILD_DIR)/container-full-tag
.PHONY: release-dry-run
release-dry-run: release-clean verify test $(BUILD_DIR)
$(GORELEASER) release --rm-dist --skip-publish --snapshot
.PHONY: release-clean
release-clean:
rm -rf ${SRC_DIR}/dist
.PHONY: test
test: ## Run all unit tests.
go test -v ./api/... ./cmd/... ./pkg/... ./test/...
.PHONY: verify
verify: verify-go verify-goreleaser ## Run all static analysis checks.
.PHONY: verify-goreleaser
verify-goreleaser:
$(GORELEASER) check
.PHONY: verify-go
verify-go:
# Check if codebase is formatted.
@bash -c "[ -z \"$$(gofmt -l ./api ./cmd ./pkg ./test)\" ] && echo 'OK' || (echo 'ERROR: files are not formatted:' && gofmt -l . && echo -e \"\nRun 'make format' or manually fix the formatting issues.\n\" && false)"
# Run static checks on codebase.
go vet ./api/... ./cmd/... ./pkg/... ./test/...
.PHONY: format
format: ## Run all formatters on the codebase.
# Format the Go codebase.
gofmt -s -w api cmd pkg test
# Format the go.mod file.
go mod tidy
.PHONY: generate
generate:
# nop
.PHONY: clean
clean: operator-clean clean-tag-file springboard-clean release-clean
rm -rf $(BUILD_DIR)
.PHONY: version
version: ## Print the version used in the Makefile
@echo $(VERSION)
#
# Go toolchain
#
$(BUILD_DIR):
mkdir -p $@
$(GO_TOOLCHAIN):| $(BUILD_DIR)
cd $(BUILD_DIR) && wget -q $(GO_DOWNLOAD_URL) && tar xf go*.tar.gz
go version
gotoolchain: | $(GO_TOOLCHAIN)
$(GOPATH_DIR):| $(BUILD_DIR) $(GO_TOOLCHAIN)
mkdir -p $@
#
# Springboard
#
$(SPRINGBOARD_STAGE_DIR):
mkdir -p $@
$(SPRINGBOARD_EXE): | $(SPRINGBOARD_STAGE_DIR)
go build -o $@ $(SRC_DIR)/cmd/springboard
$(SPRINGBOARD_IMAGE_MARKER): $(SPRINGBOARD_EXE)
cp -f $(SRC_DIR)/support/stunnel-instrumented-with-springboard/* $(SPRINGBOARD_STAGE_DIR)
sed -i 's|__STUNNEL_CONTAINER_TAG__|$(STUNNEL_CONTAINER_TAG)|g' $(SPRINGBOARD_STAGE_DIR)/Dockerfile
docker build --tag $(SPRINGBOARD_FULL_TAG) $(SPRINGBOARD_STAGE_DIR)
touch $@
springboard-image: $(SPRINGBOARD_IMAGE_MARKER)
springboard-push: $(SPRINGBOARD_IMAGE_MARKER)
(docker push $(SPRINGBOARD_FULL_TAG) || \
(echo -n $${DOCKER_PASSWORD} | docker login --password-stdin -u $${DOCKER_USERNAME} && \
docker push $(SPRINGBOARD_FULL_TAG) && docker logout))
docker rmi $(SPRINGBOARD_FULL_TAG)
rm -f $(SPRINGBOARD_IMAGE_MARKER)
springboard-clean:
rm -rf $(SPRINGBOARD_STAGE_DIR)
springboard:
go build -o $(SRC_DIR)/support/stunnel-with-springboard/springboard $(SRC_DIR)/cmd/springboard
#
# Decco-operator
#
$(OPERATOR_STAGE_DIR):
mkdir -p $@
$(OPERATOR_EXE): $(GO_TOOLCHAIN) $(SRC_DIR)/cmd/operator/*.go $(SRC_DIR)/pkg/*/*.go | $(OPERATOR_STAGE_DIR)
CGO_ENABLED=0 go build -o $(OPERATOR_EXE) $(SRC_DIR)/cmd/operator
operator: $(OPERATOR_EXE)
charts:
cd $(CHART_DIR) && \
${HELM_BIN} package decco/ -d "../build/charts/"
clean-gopath:
@echo "GOPATH is $(GOPATH_DIR)"
go clean -modcache
operator-clean:
rm -rf $(OPERATOR_STAGE_DIR)
operator-image: $(OPERATOR_IMAGE_MARKER)
$(OPERATOR_IMAGE_MARKER): $(OPERATOR_EXE)
cp -f support/operator/Dockerfile $(OPERATOR_STAGE_DIR)
docker build --tag $(FULL_TAG) $(OPERATOR_STAGE_DIR)
touch $@
operator-push: $(OPERATOR_IMAGE_MARKER)
(docker push $(FULL_TAG) || \
(echo -n $${DOCKER_PASSWORD} | docker login --password-stdin -u $${DOCKER_USERNAME} && \
docker push $(FULL_TAG) && docker logout))
docker rmi $(FULL_TAG)
rm -f $(OPERATOR_IMAGE_MARKER)
$(TAG_FILE): operator-push
echo -n $(FULL_TAG) > $@
container-full-tag: $(TAG_FILE)
clean-tag-file:
rm -f $(TAG_FILE)