-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
179 lines (143 loc) · 5.4 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
push-base-repo:
docker pull golang:1.22.4
docker tag golang:1.22.4 vcr.vngcloud.vn/81-vks-public/golang:1.22.4
docker push vcr.vngcloud.vn/81-vks-public/golang:1.22.4
docker image rm golang:1.22.4 vcr.vngcloud.vn/81-vks-public/golang:1.22.4
docker pull registry.k8s.io/build-image/go-runner:v2.3.1-go1.22.4-bookworm.0
docker tag registry.k8s.io/build-image/go-runner:v2.3.1-go1.22.4-bookworm.0 vcr.vngcloud.vn/81-vks-public/go-runner:v2.3.1-go1.22.4-bookworm.0
docker push vcr.vngcloud.vn/81-vks-public/go-runner:v2.3.1-go1.22.4-bookworm.0
docker image rm registry.k8s.io/build-image/go-runner:v2.3.1-go1.22.4-bookworm.0 vcr.vngcloud.vn/81-vks-public/go-runner:v2.3.1-go1.22.4-bookworm.0
# golang-client Makefile
# Follows the interface defined in the Golang CTI proposed
# in https://review.openstack.org/410355
#REPO_VERSION?=$(shell git describe --tags)
GIT_HOST = github.com/vngcloud
CONTAINER_ENGINE ?= docker
PWD := $(shell pwd)
BASE_DIR := $(shell basename $(PWD))
# Keep an existing GOPATH, make a private one if it is undefined
GOPATH_DEFAULT := $(PWD)/.go
export GOPATH ?= $(GOPATH_DEFAULT)
GOBIN_DEFAULT := $(GOPATH)/bin
export GOBIN ?= $(GOBIN_DEFAULT)
export GO111MODULE := on
TESTARGS_DEFAULT := "-v"
export TESTARGS ?= $(TESTARGS_DEFAULT)
PKG := $(shell awk '/^module/ { print $$2 }' go.mod)
DEST := $(GOPATH)/src/$(GIT_HOST)/$(BASE_DIR)
SOURCES := Makefile go.mod go.sum $(shell find $(DEST) -name '*.go' 2>/dev/null)
HAS_GOX := $(shell command -v gox;)
GOX_PARALLEL ?= 3
TARGETS ?= linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64le linux/s390x
DIST_DIRS = find * -type d -exec
TEMP_DIR :=$(shell mktemp -d)
TAR_FILE ?= rootfs.tar
GOOS ?= $(shell go env GOOS)
GOPROXY ?= $(shell go env GOPROXY)
VERSION ?= v0.2.4
GOARCH :=
GOFLAGS :=
TAGS :=
LDFLAGS := "-w -s -X 'k8s.io/component-base/version.gitVersion=$(VERSION)' -X 'github.com/vngcloud/vngcloud-controller-manager/pkg/version.Version=$(VERSION)'"
GOX_LDFLAGS := $(shell echo "$(LDFLAGS) -extldflags \"-static\"")
REGISTRY ?= vcr.vngcloud.vn/81-vks-public
IMAGE_OS ?= linux
IMAGE_NAMES ?= vngcloud-controller-manager \
vngcloud-ingress-controller
ARCH ?= amd64
ARCHS ?= amd64
BUILD_CMDS ?= vngcloud-controller-manager \
vngcloud-ingress-controller
# CTI targets
$(GOBIN):
echo "create gobin"
mkdir -p $(GOBIN)
work: $(GOBIN)
build-all-archs:
@for arch in $(ARCHS); do $(MAKE) ARCH=$${arch} build ; done
build: $(BUILD_CMDS)
$(BUILD_CMDS): $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GOPROXY=${GOPROXY} go build \
-trimpath \
-ldflags $(LDFLAGS) \
-o $@ \
cmd/$@/main.go
test: unit functional
check: work
go run github.com/golangci/golangci-lint/cmd/[email protected] run ./...
unit: work
go test -tags=unit $(shell go list ./... | sed -e '/sanity/ { N; d; }' | sed -e '/tests/ {N; d;}') $(TESTARGS)
# Do the work here
# Set up the development environment
env:
@echo "PWD: $(PWD)"
@echo "BASE_DIR: $(BASE_DIR)"
@echo "GOPATH: $(GOPATH)"
@echo "GOROOT: $(GOROOT)"
@echo "DEST: $(DEST)"
@echo "PKG: $(PKG)"
go version
go env
# Get our dev/test dependencies in place
bootstrap:
tools/test-setup.sh
.bindep:
virtualenv .bindep
.bindep/bin/pip install -i https://pypi.python.org/simple bindep
bindep: .bindep
@.bindep/bin/bindep -b -f bindep.txt || true
install-distro-packages:
tools/install-distro-packages.sh
clean:
rm -rf _dist .bindep
@echo "clean builds binary"
@for binary in $(BUILD_CMDS); do rm -rf $${binary}*; done
realclean: clean
rm -rf vendor
if [ "$(GOPATH)" = "$(GOPATH_DEFAULT)" ]; then \
rm -rf $(GOPATH); \
fi
shell:
$(SHELL) -i
# Build a single image for the local default platform and push to the local
# container engine
build-local-image-%:
$(CONTAINER_ENGINE) buildx build --output type=docker \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$*:$(VERSION) \
--target $* \
.
# Build all images locally
build-local-images: $(addprefix build-local-image-,$(IMAGE_NAMES))
# Build a single image for all architectures in ARCHS and push it to REGISTRY
push-multiarch-image-%:
$(CONTAINER_ENGINE) buildx build --output type=registry \
--build-arg VERSION=$(VERSION) \
--tag $(REGISTRY)/$*:$(VERSION) \
--platform $(shell echo $(addprefix linux/,$(ARCHS)) | sed 's/ /,/g') \
--target $* \
.
$(CONTAINER_ENGINE) image push $(REGISTRY)/$*:$(VERSION)
# Push all multiarch images
push-multiarch-images: clean build $(addprefix push-multiarch-image-,$(IMAGE_NAMES))
version:
@echo ${VERSION}
.PHONY: build-cross
build-cross: work
ifndef HAS_GOX
echo "installing gox"
go install github.com/mitchellh/gox
endif
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/vngcloud-controller-manager/
CGO_ENABLED=0 gox -parallel=$(GOX_PARALLEL) -output="_dist/{{.OS}}-{{.Arch}}/{{.Dir}}" -osarch='$(TARGETS)' $(GOFLAGS) $(if $(TAGS),-tags '$(TAGS)',) -ldflags '$(GOX_LDFLAGS)' $(GIT_HOST)/$(BASE_DIR)/cmd/vngcloud-ingress-controller/
.PHONY: dist
dist: build-cross
( \
cd _dist && \
$(DIST_DIRS) cp ../LICENSE {} \; && \
$(DIST_DIRS) cp ../README.md {} \; && \
$(DIST_DIRS) tar -zcf cloud-provider-vngcloud-$(VERSION)-{}.tar.gz {} \; && \
$(DIST_DIRS) zip -r cloud-provider-vngcloud-$(VERSION)-{}.zip {} \; \
)
.PHONY: bindep build clean cover work docs fmt functional lint realclean \
relnotes test translation version build-cross dist codeclimate