-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
70 lines (55 loc) · 2.57 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
# The version of this client (should be in line with the highest supported engine/enterprise version
CLIENT_VERSION = 0.1.0
# where all generated code will be located
PROJECT_ROOT = pkg
# OpenAPI generator version to use
OPENAPI_GENERATOR_VERSION = v4.3.1
# note: v5 introduces the new command pattern approach, splitting request and execute + generating interfaces per service.
#OPENAPI_GENERATOR_VERSION = v5.0.0-beta3
# --- anchore engine references
# a git tag/branch/commit within anchore/anchore-engine repo
ENGINE_REF = 7568d8810ac2958ae6e9917e4bf2bd2d7c079a03
EXTAPI_CLIENT_ROOT = $(PROJECT_ROOT)/external
EXTAPI_OPENAPI_DOC = $(PROJECT_ROOT)/swagger-external-$(ENGINE_REF).yaml
# --- anchore enterprise references
# ANCHORE_ENTERPRISE_REF = ...
define generate_openapi_client
# remove previous API clients
@ if [[ "$$OSTYPE" == "linux-gnu" ]]; then sudo rm -rf ${3}; else rm -rf ${3}; fi
# generate the API client
docker run \
--rm \
-v $${PWD}:/local \
openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION} \
generate \
-c /local/generator.yaml \
--additional-properties packageName=${2} \
--additional-properties packageVersion=$(CLIENT_VERSION) \
--http-user-agent "anchore-client/$(CLIENT_VERSION)/go" \
-i /local/${1} \
-o /local/${3} \
-g go
# keep permissions the same as the user
@ if [[ "$$OSTYPE" == "linux-gnu" ]]; then sudo chown -R $(shell id -u):$(shell id -g) ${3}; fi
# remove unused files (go.mod is curated manually)
rm ${3}/{.travis.yml,git_push.sh,go.*}
endef
.PHONY :=
.DEFAULT_GOAL :=
update: clean generate-external-client ## pull all swagger definitions and generate client code
.PHONY :=
generate: generate-external-client ## generate all client code from all swagger documents
$(EXTAPI_OPENAPI_DOC): ## pull the engine external API swagger document
mkdir -p $(PROJECT_ROOT)
# note: the existing upstream swagger document needs to be corrected, otherwise invalid code will be generated.
# the tr/sed cmds are a workaround for now.
curl https://raw.githubusercontent.com/anchore/anchore-engine/$(ENGINE_REF)/anchore_engine/services/apiext/swagger/swagger.yaml > $(EXTAPI_OPENAPI_DOC)
.PHONY :=
generate-external-client: $(EXTAPI_OPENAPI_DOC) ## generate client code for engine external API
$(call generate_openapi_client,$(EXTAPI_OPENAPI_DOC),external,$(EXTAPI_CLIENT_ROOT))
.PHONY :=
clean: ## remove all swagger documents and generated client code
rm -rf $(PROJECT_ROOT)
.PHONY :=
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'