-
Notifications
You must be signed in to change notification settings - Fork 118
/
Makefile
240 lines (196 loc) · 9.35 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# Copyright IBM Corporation 2020
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO_VERSION ?= $(shell go run ./scripts/detectgoversion/detect.go 2>/dev/null || printf '1.19')
BINNAME ?= move2kube
IN_CICD ?= false
CGO_ENABLED ?= 0
BINDIR := $(CURDIR)/bin
DISTDIR := $(CURDIR)/_dist
TARGETS := darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/s390x linux/ppc64le windows/amd64
MULTI_ARCH_TARGET_PLATFORMS := linux/amd64,linux/arm64
REGISTRYNS ?= quay.io/konveyor
GOPATH = $(shell go env GOPATH)
GOX = $(GOPATH)/bin/gox
GOTEST = ${GOPATH}/bin/gotest
GOLANGCILINT = golangci-lint
GOLANGCOVER = $(GOPATH)/bin/goveralls
PKG := ./...
LDFLAGS := -w -s
SRC = $(shell find . -type f -name '*.go' -print)
ASSETS = $(shell find assets -type f -name '*' -print)
WEB_ASSETS = $(shell find graph/web/build -type f -name '*' -print)
ARCH = $(shell uname -p)
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git tag --points-at | tail -n 1)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
HAS_NODE = $(shell command -v node >/dev/null && echo true || echo false)
HAS_LINT = $(shell command -v ${GOLANGCILINT} >/dev/null && echo true || echo false)
GOGET := cd / && GO111MODULE=on go install
ifdef VERSION
BINARY_VERSION = $(VERSION)
endif
BINARY_VERSION ?= ${GIT_TAG}
ifneq ($(BINARY_VERSION),)
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.version=${BINARY_VERSION}
VERSION ?= $(BINARY_VERSION)
endif
VERSION ?= latest
VERSION_METADATA = unreleased
ifneq ($(filter v%[0-9].%[0-9].%[0-9],$(GIT_TAG)),)
VERSION_METADATA = stable
else ifneq ($(filter v%[0-9].%[0-9].%[0-9]-%,$(GIT_TAG)),)
VERSION_METADATA = prerelease
else ifneq ($(filter v%[0-9].%[0-9].%[0-9]-released,$(GIT_TAG)),)
VERSION_METADATA = released
endif
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.buildmetadata=${VERSION_METADATA}
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.gitCommit=${GIT_COMMIT}
LDFLAGS += -X github.com/konveyor/${BINNAME}/types/info.gitTreeState=${GIT_DIRTY}
# LDFLAGS += -extldflags "-static"
# Setting container tool
DOCKER_CMD := $(shell command -v docker 2> /dev/null)
PODMAN_CMD := $(shell command -v podman 2> /dev/null)
ifdef DOCKER_CMD
CONTAINER_TOOL = 'docker'
else ifdef PODMAN_CMD
CONTAINER_TOOL = 'podman'
endif
# HELP
# This will output the help for each task
.PHONY: help
help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# -- Build --
.PHONY: buildgraph
buildgraph: ## Build the code for the graph web server
ifeq ($(HAS_NODE),true)
cd graph/web && yarn && yarn run build
@printf "\033[32m-------------------------------------\n GRAPH BUILD SUCCESS\n-------------------------------------\033[0m\n"
else
@echo 'Please install node to build the graph server files.'
@echo
@echo 'Install Node 16 or higher using Node Version Manager https://github.com/nvm-sh/nvm'
@echo 'Once nvm is installed, you can install NodeJS 16 by running "nvm install 16 && nvm use 16"'
@echo 'Run "node --version" to make sure it is v16.9.0 or higher and then enable CorePack by running "corepack enable"'
@echo 'CorePack will take care of installing the correct yarn version.'
@echo
@echo 'See https://nodejs.org/api/corepack.html for more information on CorePack.'
endif
.PHONY: build
build: get $(BINDIR)/$(BINNAME) ## Build go code
@printf "\033[32m-------------------------------------\n BUILD SUCCESS\n-------------------------------------\033[0m\n"
$(BINDIR)/$(BINNAME): $(SRC) $(ASSETS) $(WEB_ASSETS)
CGO_ENABLED=$(CGO_ENABLED) go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) .
mkdir -p $(GOPATH)/bin/
cp $(BINDIR)/$(BINNAME) $(GOPATH)/bin/
.PHONY: get
get: go.mod
go mod download
.PHONY: generate
generate: ## Generate assets
go generate ${PKG}
# -- Test --
.PHONY: test
test: ## Run tests
go test -run . $(PKG) -race
@printf "\033[32m-------------------------------------\n TESTS PASSED\n-------------------------------------\033[0m\n"
${GOTEST}:
${GOGET} github.com/rakyll/gotest@v0.0.6
.PHONY: test-verbose
test-verbose: ${GOTEST}
gotest -run . $(PKG) -race -v
${GOLANGCOVER}:
${GOGET} github.com/mattn/goveralls@v0.0.11
.PHONY: test-coverage
test-coverage: ${GOLANGCOVER} ## Run tests with coverage
go test -run . $(PKG) -coverprofile=coverage.txt -covermode=atomic
${GOLANGCILINT}:
ifeq ($(HAS_LINT),false)
ifeq ($(IN_CICD),true)
@echo "installing ${GOLANGCILINT}"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.50.0
else
@echo "Please install the '${GOLANGCILINT}' tool to run the linters."
@echo "https://golangci-lint.run/usage/install/#local-installation"
@exit 1
endif
endif
.PHONY: test-style
test-style: ${GOLANGCILINT}
${GOLANGCILINT} run --timeout 3m
scripts/licensecheck.sh
@printf "\033[32m-------------------------------------\n STYLE CHECK PASSED\n-------------------------------------\033[0m\n"
# -- CI --
.PHONY: ci
ci: clean build test test-style ## Run CI routine
# -- Release --
$(GOX):
${GOGET} github.com/mitchellh/gox@v1.0.1
.PHONY: build-cross
build-cross: $(GOX) clean $(SRC) $(ASSETS) $(WEB_ASSETS)
CGO_ENABLED=0 $(GOX) -parallel=3 -output="$(DISTDIR)/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' -ldflags '$(LDFLAGS)' .
.PHONY: dist
dist: clean build-cross ## Build distribution
mkdir -p $(DISTDIR)/files
cp -r ./LICENSE ./USAGE.md ./samples $(DISTDIR)/files/
cd $(DISTDIR) && go run ../scripts/dist/builddist.go -b $(BINNAME) -v $(VERSION)
.PHONY: clean
clean:
rm -rf $(BINDIR) $(DISTDIR)
go clean -cache
.PHONY: info
info: ## Get version info
@echo "inside CI/CD pipelines: ${IN_CICD}"
@echo "Version: ${VERSION}"
@echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_COMMIT}"
@echo "Git Tree State: ${GIT_DIRTY}"
# -- Container Image --
.PHONY: cbuild
cbuild: ## Build container image
ifndef CONTAINER_TOOL
$(error No container tool (docker, podman) found in your environment. Please, install one)
endif
@echo "Building image with $(CONTAINER_TOOL)"
DOCKER_BUILDKIT=1 ${CONTAINER_TOOL} build -t ${REGISTRYNS}/${BINNAME}-builder:${VERSION} --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --target builder --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} .
DOCKER_BUILDKIT=1 ${CONTAINER_TOOL} build -t ${REGISTRYNS}/${BINNAME}:${VERSION} --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --cache-from ${REGISTRYNS}/${BINNAME}:latest --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} .
${CONTAINER_TOOL} tag ${REGISTRYNS}/${BINNAME}-builder:${VERSION} ${REGISTRYNS}/${BINNAME}-builder:latest
${CONTAINER_TOOL} tag ${REGISTRYNS}/${BINNAME}:${VERSION} ${REGISTRYNS}/${BINNAME}:latest
.PHONY: cpush
cpush: ## Push container image
ifndef CONTAINER_TOOL
$(error No container tool (docker, podman) found in your environment. Please, install one)
endif
@echo "Pushing image with $(CONTAINER_TOOL)"
# To help with reusing layers and hence speeding up build
${CONTAINER_TOOL} push ${REGISTRYNS}/${BINNAME}-builder:${VERSION}
${CONTAINER_TOOL} push ${REGISTRYNS}/${BINNAME}:${VERSION}
.PHONY: cmultibuildpush
cmultibuildpush: ## Build and push multi arch container image
ifndef DOCKER_CMD
$(error Docker wasn't detected. Please install docker and try again.)
endif
@echo "Building image for multiple architectures with $(CONTAINER_TOOL)"
## TODO: When docker exporter supports exporting manifest lists we can separate out this into two steps: build and push
${CONTAINER_TOOL} buildx create --name m2k-builder --driver-opt network=host --use --platform ${MULTI_ARCH_TARGET_PLATFORMS}
${CONTAINER_TOOL} buildx build --platform ${MULTI_ARCH_TARGET_PLATFORMS} --tag ${REGISTRYNS}/${BINNAME}-builder:${VERSION} --tag ${REGISTRYNS}/${BINNAME}-builder:latest --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --target builder --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} --push .;
${CONTAINER_TOOL} buildx build --platform ${MULTI_ARCH_TARGET_PLATFORMS} --tag ${REGISTRYNS}/${BINNAME}:${VERSION} --tag ${REGISTRYNS}/${BINNAME}:latest --cache-from ${REGISTRYNS}/${BINNAME}-builder:latest --cache-from ${REGISTRYNS}/${BINNAME}:latest --build-arg VERSION=${VERSION} --build-arg GO_VERSION=${GO_VERSION} --push .;
${CONTAINER_TOOL} buildx rm m2k-builder
.PHONY: cbuildbuiltin
cbuildbuiltin: ## Build all the images for the built-in containerized transformers
DOCKER_BUILDKIT=1 ${CONTAINER_TOOL} build -t quay.io/konveyor-move2kube-transformers/run-tca:${VERSION} assets/built-in/transformers/kubernetes/operatorsfromtca/
.PHONY: cpushbuiltin
cpushbuiltin: ## Push all the images for the built-in containerized transformers
${CONTAINER_TOOL} push quay.io/konveyor-move2kube-transformers/run-tca:${VERSION}