-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
211 lines (186 loc) · 11.5 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
# SPDX-FileCopyrightText: 2020-present Open Networking Foundation <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
export CGO_ENABLED=0
export GO111MODULE=on
.PHONY: build
DOCKER_TAG ?= latest
DOCKER_REPOSITORY ?= onosproject/
DOCKER_REGISTRY ?= ""
DOCKER_IMAGENAME_API := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}aether-roc-api:${DOCKER_TAG}
OAPI_CODEGEN_VERSION := v1.7.0
PLATFORM ?= --platform linux/x86_64
build: # @HELP build the Go binaries and run all validations (default)
build:
CGO_ENABLED=1 go build -o build/_output/aether-roc-api ./cmd/aether-roc-api
build-tools:=$(shell if [ ! -d "./build/build-tools" ]; then cd build && git clone https://github.com/onosproject/build-tools.git; fi)
include ./build/build-tools/make/onf-common.mk
test: # @HELP run the unit tests and source code validation
test: build deps linters license openapi-linters
CGO_ENABLED=1 go test -race github.com/onosproject/aether-roc-api/pkg/...
CGO_ENABLED=1 go test -race github.com/onosproject/aether-roc-api/cmd/...
jenkins-test: # @HELP run the unit tests and source code validation producing a junit style report for Jenkins
jenkins-test: deps license linters jenkins-tools # openapi-linters
CGO_ENABLED=1 TEST_PACKAGES=github.com/onosproject/aether-roc-api/... ./build/build-tools/build/jenkins/make-unit
oapi-codegen:
oapi-codegen || ( cd .. && go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@${OAPI_CODEGEN_VERSION})
openapi-spec-validator: # @HELP install openapi-spec-validator
openapi-spec-validator -h || python -m pip install openapi-spec-validator==0.3.1
openapi-linters: # @HELP lints the Open API specifications
openapi-linters: openapi-spec-validator
openapi-spec-validator api/aether-top-level-openapi3.yaml
openapi-spec-validator api/aether-2.1.0-openapi3.yaml
openapi-spec-validator api/aether-2.0.0-openapi3.yaml
openapi-spec-validator api/aether-app-gtwy-openapi3.yaml
oapi-codegen-aether-2.1.0: # @HELP generate openapi types from aether-2.1.0-openapi3.yaml - see code-generation.md
oapi-codegen-aether-2.1.0: oapi-codegen
mkdir -p pkg/aether_2_1_0/types pkg/aether_2_1_0/server
oapi-codegen -generate types -package types -o pkg/aether_2_1_0/types/aether-2.1.0-types.go api/aether-2.1.0-openapi3.yaml
oapi-codegen -generate spec -package server -o pkg/aether_2_1_0/server/aether-2.1.0-spec.go api/aether-2.1.0-openapi3.yaml
# Note the import-mapping prefix below will be ignored and the the items sorted alphabetically
oapi-codegen \
-generate types,server \
-import-mapping imp1:"github.com/onosproject/aether-roc-api/pkg/aether_2_1_0/types",imp2:"github.com/onosproject/aether-models/models/aether-2.1.x/v2/api" \
-package server \
-templates pkg/codegen/templates \
-o pkg/aether_2_1_0/server/aether-2.1.0-impl.go \
api/aether-2.1.0-openapi3.yaml
sed -e "s/enterpriseId EnterpriseId/enterpriseId externalRef1.EnterpriseId/g" pkg/aether_2_1_0/server/aether-2.1.0-impl.go > aether-2.1.0-impl.new
mv aether-2.1.0-impl.new pkg/aether_2_1_0/server/aether-2.1.0-impl.go
oapi-codegen \
-generate server \
-import-mapping externalRef0:"github.com/onosproject/aether-roc-api/pkg/aether_2_1_0/types" \
-package server \
-templates pkg/codegen/modified \
-o pkg/aether_2_1_0/server/aether-2.1.0-server.go \
api/aether-2.1.0-openapi3.yaml
sed -e "s/enterpriseId EnterpriseId/enterpriseId externalRef0.EnterpriseId/g" pkg/aether_2_1_0/server/aether-2.1.0-server.go > aether-2.1.0-server.new
mv aether-2.1.0-server.new pkg/aether_2_1_0/server/aether-2.1.0-server.go
oapi-codegen \
-generate types \
-import-mapping externalRef0:"github.com/onosproject/aether-models/models/aether-2.1.x/v2/api" \
-package server \
-templates pkg/codegen/convert-oapi-gnmi \
-o pkg/aether_2_1_0/server/aether-2.1.0-convert-oapi-gnmi.go \
api/aether-2.1.0-openapi3.yaml
sed -e "s/ > !//g" pkg/aether_2_1_0/server/aether-2.1.0-convert-oapi-gnmi.go > aether-2.1.0-convert-oapi-gnmi.new
mv aether-2.1.0-convert-oapi-gnmi.new pkg/aether_2_1_0/server/aether-2.1.0-convert-oapi-gnmi.go
oapi-codegen \
-generate types \
-import-mapping externalRef0:"github.com/onosproject/aether-models/models/aether-2.1.x/v2/api" \
-package server \
-templates pkg/codegen/convert-gnmi-oapi \
-o pkg/aether_2_1_0/server/aether-2.1.0-convert-gnmi-oapi.go \
api/aether-2.1.0-openapi3.yaml
sed -e "s/ > !//g" pkg/aether_2_1_0/server/aether-2.1.0-convert-gnmi-oapi.go > aether-2.1.0-convert-gnmi-oapi.new
mv aether-2.1.0-convert-gnmi-oapi.new pkg/aether_2_1_0/server/aether-2.1.0-convert-gnmi-oapi.go
for f in pkg/aether_2_1_0/**/aether-2.1.0*.go; do { echo "// Code generated by oapi-codegen. DO NOT EDIT."; cat $$f; } > $$f.new; mv $$f.new $$f; done
oapi-codegen-aether-2.0.0: # @HELP generate openapi types from aether-2.0.0-openapi3.yaml
oapi-codegen-aether-2.0.0: oapi-codegen
mkdir -p pkg/aether_2_0_0/types pkg/aether_2_0_0/server
oapi-codegen -generate types -package types -o pkg/aether_2_0_0/types/aether-2.0.0-types.go api/aether-2.0.0-openapi3.yaml
oapi-codegen -generate spec -package server -o pkg/aether_2_0_0/server/aether-2.0.0-spec.go api/aether-2.0.0-openapi3.yaml
oapi-codegen \
-generate types,server \
-import-mapping imp1:"github.com/onosproject/aether-roc-api/pkg/aether_2_0_0/types",imp2:"github.com/onosproject/aether-models/models/aether-2.0.x/v2/api" \
-package server \
-templates pkg/codegen/templates \
-o pkg/aether_2_0_0/server/aether-2.0.0-impl.go \
api/aether-2.0.0-openapi3.yaml
sed -e "s/enterpriseId externalRef1\.EnterpriseId/targetId externalRef1.Target/g" pkg/aether_2_0_0/server/aether-2.0.0-impl.go > aether-2.0.0-impl.new2
sed -e "s/target Target/target externalRef1.Target/g" aether-2.0.0-impl.new2 > aether-2.0.0-impl.new3
sed -e "s/enterpriseId/targetId/g" aether-2.0.0-impl.new3 > aether-2.0.0-impl.new4
mv aether-2.0.0-impl.new4 pkg/aether_2_0_0/server/aether-2.0.0-impl.go
rm aether-2.0.0-impl.new*
oapi-codegen \
-generate server \
-import-mapping imp1:"github.com/onosproject/aether-roc-api/pkg/aether_2_0_0/types" \
-package server \
-templates pkg/codegen/modified \
-o pkg/aether_2_0_0/server/aether-2.0.0-server.go \
api/aether-2.0.0-openapi3.yaml
sed -e "s/target Target/target externalRef0.Target/g" pkg/aether_2_0_0/server/aether-2.0.0-server.go > aether-2.0.0-server.new3
sed -e "s/ctx\.Param(\"target\")/externalRef0.Target(ctx.Param(\"target\"))/g" aether-2.0.0-server.new3 > aether-2.0.0-server.new4
sed -e "s/var enterpriseId externalRef0.string/var enterpriseId string/g" aether-2.0.0-server.new4 > aether-2.0.0-server.new5
sed -e "s/externalRef0.EnterpriseId(ctx.Param(\"enterprise-id\"))/ctx.Param(\"enterprise-id\")/g" aether-2.0.0-server.new5 > aether-2.0.0-server.new6
mv aether-2.0.0-server.new6 pkg/aether_2_0_0/server/aether-2.0.0-server.go
rm aether-2.0.0-server.new*
oapi-codegen \
-generate types \
-import-mapping externalRef0:"github.com/onosproject/aether-models/models/aether-2.0.x/v2/api" \
-package server \
-templates pkg/codegen/convert-oapi-gnmi \
-o pkg/aether_2_0_0/server/aether-2.0.0-convert-oapi-gnmi.go \
api/aether-2.0.0-openapi3.yaml
sed -e "s/ > !//g" pkg/aether_2_0_0/server/aether-2.0.0-convert-oapi-gnmi.go > aether-2.0.0-convert-oapi-gnmi.new
sed -e "s/types\.EnterpriseId/types.Target/g" aether-2.0.0-convert-oapi-gnmi.new > aether-2.0.0-convert-oapi-gnmi.new1
sed -e "s/\"reflect\"/\"reflect\"\n\t\"github.com\/onosproject\/aether-roc-api\/pkg\/aether_2_0_0\/types\"/g" aether-2.0.0-convert-oapi-gnmi.new1 > aether-2.0.0-convert-oapi-gnmi.new2
mv aether-2.0.0-convert-oapi-gnmi.new2 pkg/aether_2_0_0/server/aether-2.0.0-convert-oapi-gnmi.go
rm aether-2.0.0-convert-oapi-gnmi.new*
oapi-codegen \
-generate types \
-import-mapping externalRef0:"github.com/onosproject/aether-models/models/aether-2.0.x/v2/api" \
-package server \
-templates pkg/codegen/convert-gnmi-oapi \
-o pkg/aether_2_0_0/server/aether-2.0.0-convert-gnmi-oapi.go \
api/aether-2.0.0-openapi3.yaml
sed -e "s/ > !//g" pkg/aether_2_0_0/server/aether-2.0.0-convert-gnmi-oapi.go > aether-2.0.0-convert-gnmi-oapi.new
mv aether-2.0.0-convert-gnmi-oapi.new pkg/aether_2_0_0/server/aether-2.0.0-convert-gnmi-oapi.go
for f in pkg/aether_2_0_0/**/aether-2.0.0*.go; do { echo "// Code generated by oapi-codegen. DO NOT EDIT."; cat $$f; } > $$f.new; mv $$f.new $$f; done
oapi-codegen-aether-app-gtwy: # @HELP generate openapi types from aether-app-gtwy-openapi3.yaml
oapi-codegen-aether-app-gtwy: oapi-codegen
mkdir -p pkg/app_gtwy/types pkg/app_gtwy/server
oapi-codegen -generate types -package types -o pkg/app_gtwy/types/aether-app-gtwy-types.go api/aether-app-gtwy-openapi3.yaml
oapi-codegen -generate spec -package server -o pkg/app_gtwy/server/aether-app-gtwy-spec.go api/aether-app-gtwy-openapi3.yaml
oapi-codegen \
-generate server \
-import-mapping externalRef0:"github.com/onosproject/aether-roc-api/pkg/aether_2_0_0/types" \
-package server \
-templates pkg/codegen/modified \
-o pkg/app_gtwy/server/aether-app-gtwy-server.go \
api/aether-app-gtwy-openapi3.yaml
sed -i "s/target Target/target externalRef0.Target/g" pkg/app_gtwy/server/aether-app-gtwy-server.go
aether-top-level: # @HELP generate openapi types from aether-top-level-openapi3.yaml
aether-top-level: oapi-codegen
oapi-codegen -generate types -package types \
-import-mapping \
./aether-2.0.0-openapi3.yaml:github.com/onosproject/aether-roc-api/pkg/aether_2_0_0/types,\
./aether-2.1.0-openapi3.yaml:github.com/onosproject/aether-roc-api/pkg/aether_2_1_0/types,\
./aether-app-gtwy-openapi3.yaml:github.com/onosproject/aether-roc-api/pkg/app_gtwy/types \
-o pkg/toplevel/types/toplevel-types.go api/aether-top-level-openapi3.yaml
oapi-codegen -generate spec -package server \
-import-mapping \
./aether-2.0.0-openapi3.yaml:github.com/onosproject/aether-roc-api/pkg/aether_2_0_0/types,\
./aether-2.1.0-openapi3.yaml:github.com/onosproject/aether-roc-api/pkg/aether_2_1_0/types,\
./aether-app-gtwy-openapi3.yaml:github.com/onosproject/aether-roc-api/pkg/app_gtwy/types \
-o pkg/toplevel/server/toplevel-spec.go api/aether-top-level-openapi3.yaml
sed -e "s/\/types/\/server/g" pkg/toplevel/server/toplevel-spec.go > toplevel-spec.new
mv toplevel-spec.new pkg/toplevel/server/toplevel-spec.go
aether-roc-api-docker: # @HELP build aether-roc-api Docker image
@go mod vendor
docker build ${PLATFORM} . -f build/aether-roc-api/Dockerfile \
-t ${DOCKER_IMAGENAME_API}
@rm -rf vendor
images: # @HELP build all Docker images
images: build aether-roc-api-docker
kind: # @HELP build Docker images and add them to the currently configured kind cluster
kind: images
$(eval CLUSTER_NAME := $(shell kind get clusters))
@if [ "$(CLUSTER_NAME)" = '' ]; then echo "no kind cluster found" && exit 1; fi
kind load --name=$(CLUSTER_NAME) docker-image ${DOCKER_IMAGENAME_API}
kind load --name=$(CLUSTER_NAME) docker-image ${DOCKER_IMAGENAME_WS}
all: build images
publish: # @HELP publish version on github and dockerhub
./build/build-tools/publish-version ${VERSION} onosproject/aether-roc-api
jenkins-publish: # @HELP Jenkins calls this to publish artifacts
./build/bin/push-images
./build/build-tools/release-merge-commit
generated: # @HELP create generated artifacts
generated: oapi-codegen-aether-2.1.0 oapi-codegen-aether-2.0.0 oapi-codegen-aether-app-gtwy
clean:: # @HELP remove all the build artifacts
rm -rf ./build/_output ./vendor ./cmd/aether-roc-api/aether-roc-api
go clean -testcache github.com/onosproject/aether-roc-api/...
clean-generated: # @HELP remove generated artifacts
rm -f pkg/aether_2_1_0/**/aether-2.1.0*.go
rm -f pkg/aether_2_0_0/**/aether-2.0.0*.go
rm -f pkg/app_gtwy/**/aether-app-gtwy*.go