forked from banzaicloud/cloudinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (77 loc) · 3.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
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
OS = $(shell uname | tr A-Z a-z)
# Project variables
BUILD_PACKAGE ?= ./cmd/cloudinfo
BINARY_NAME ?= cloudinfo
DOCKER_IMAGE = banzaicloud/cloudinfo
# Docker Push configuration
GCR_HOST ?= us.gcr.io
GCR_PROJECT_ID ?= platform-205701
GCR_IMAGE_REPOSITORY ?= harness/cloudinfo
# Build variables
BUILD_DIR ?= build
VERSION_FILE := ./version
VERSION := $(shell cat $(VERSION_FILE) | grep 'version=' | sed -e 's: *version=1.0.::g' | tr -d '\r\n')
ifeq (${VERSION},)
VERSION := $(shell git describe --tags --exact-match 2>/dev/null)
endif
ifeq (${VERSION},)
VERSION := $(shell git symbolic-ref -q --short HEAD | sed 's/[^a-zA-Z0-9]/-/g')
endif
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
BRANCH ?= $(shell git symbolic-ref -q --short HEAD)
LDFLAGS := -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE} -X main.branch=${BRANCH}
export CGO_ENABLED ?= 0
ifeq (${VERBOSE}, 1)
ifeq ($(filter -v,${GOARGS}),)
GOARGS += -v
endif
TEST_FORMAT = short-verbose
endif
# Docker variables
DOCKER_TAG ?= ${VERSION}
GCR_IMAGE_LOCATION = ${GCR_HOST}/${GCR_PROJECT_ID}/${GCR_IMAGE_REPOSITORY}:${DOCKER_TAG}
MISSPELL_VERSION = 0.3.4
GQLGEN_VERSION = 0.13.0
GOTESTSUM_VERSION = 0.4.2
GOLANGCI_VERSION = 1.27.0
LICENSEI_VERSION = 0.3.1
OPENAPI_GENERATOR_VERSION = v4.1.3
GOLANG_VERSION = 1.14
SWAGGER_VERSION = 0.27.0
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./client/*")
SWAGGER_PI_TMP_FILE = ./api/openapi-spec/cloudinfo.json
SWAGGER_PI_FILE = ./api/openapi-spec/cloudinfo.yaml
## include "generic" targets
include main-targets.mk
.PHONY: swagger2openapi
swagger2openapi:
ifeq ($(shell which swagger2openapi),)
npm install -g swagger2openapi
endif
bin/swagger: bin/swagger-${SWAGGER_VERSION}
@ln -sf swagger-${SWAGGER_VERSION} bin/swagger
bin/swagger-${SWAGGER_VERSION}:
@mkdir -p bin
GOBIN=$$PWD/bin go install github.com/go-swagger/go-swagger/cmd/swagger@v${SWAGGER_VERSION}
@mv bin/swagger bin/swagger-${SWAGGER_VERSION}
.PHONY: swagger
swagger: bin/swagger
bin/swagger generate spec -m -w ./cmd/cloudinfo -o $(SWAGGER_PI_TMP_FILE)
swagger2openapi -y $(SWAGGER_PI_TMP_FILE) > $(SWAGGER_PI_FILE)
define generate_openapi_client
@ if [[ "$$OSTYPE" == "linux-gnu" ]]; then sudo rm -rf ${3}; else rm -rf ${3}; fi
docker run --rm -v $${PWD}:/local openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION} generate \
--additional-properties packageName=${2} \
--additional-properties withGoCodegenComment=true \
-i /local/${1} \
-g go \
-o /local/${3}
@ if [[ "$$OSTYPE" == "linux-gnu" ]]; then sudo chown -R $(shell id -u):$(shell id -g) ${3}; fi
rm ${3}/{.travis.yml,git_push.sh,go.*}
endef
api/openapi-spec/cloudinfo.yaml:swagger
.PHONY: generate-cloudinfo-client
generate-cloudinfo-client: api/openapi-spec/cloudinfo.yaml ## Generate client from Cloudinfo OpenAPI spec
$(call generate_openapi_client,api/openapi-spec/cloudinfo.yaml,cloudinfo,.gen/cloudinfo-client)