-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
241 lines (197 loc) · 8.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
241
# check for build/shipkit and clone if not there, this should come first
SHIPKIT_DIR = build/shipkit
$(shell [ ! -e $(SHIPKIT_DIR) ] && git clone -b v2.0.11 https://github.com/yakworks/shipkit.git $(SHIPKIT_DIR) >/dev/null 2>&1)
# Shipkit.make first, which does all the lifting to create makefile.env for the BUILD_VARS
include $(SHIPKIT_DIR)/Shipkit.make
include $(SHIPKIT_DIR)/makefiles/circle.make
include $(SHIPKIT_DIR)/makefiles/vault.make
include $(SHIPKIT_DIR)/makefiles/spring-common.make
include $(SHIPKIT_DIR)/makefiles/ship-gh-pages.make
# DB = true # set this to true to turn on the DB environment options
gw ?= ./gradlew
# open api targets
include ./api-docs/Makefile
## Run spotlessApply and normal check
check: lint
# $(gradlew) spotlessApply
# $(gradlew) check --max-workers=3
$(gradlew) check
## clean and remove the .build-cache/
clean.all:
rm -rf .build-cache/
$(MAKE) clean
# should run vault.decrypt before this,
# sets up github, kubernetes and docker login
# sets up github, kubernetes and docker login, commented out # kubectl.config dockerhub.login
ship.authorize: git.config-bot-user
$(logr.done)
## publish the java jar lib to repo.9ci for snapshot and to both for prod Sonatype Maven Central
publish:
if [ "$(dry_run)" ]; then
echo "🌮 dry_run -> $(gradlew) publish"
else
if [ "$(IS_SNAPSHOT)" ]; then
$(gradlew) publishJavaLibraryPublicationToMavenRepository
$(logr.done) "- published SNAPSHOT to repo.9ci.com - libraries with version $(VERSION)$(VERSION_SUFFIX)"
else
${gradlew} rally-domain:verifyNoSnapshots
$(gradlew) publishJavaLibraryPublicationToMavenRepository
$(logr.done) "- published to repo.9ci.com - libraries with version $(VERSION)"
$(logr) "Starting publishing to Sonatype Maven Central"
$(gradlew) publishToSonatype closeAndReleaseSonatypeStagingRepository
$(logr.done) "- published to Maven Central - libraries with version $(VERSION)"
fi
fi
## publish snapsot to repo.9ci
publish.snapshot:
if [ "$(IS_SNAPSHOT)" ]; then
$(gradlew) publishJavaLibraryPublicationToMavenRepository
$(logr.done) "- libs with version $(VERSION)$(VERSION_SUFFIX) published to snapshot repo"
fi
## alias to publish.snapshot
snapshot.publish: publish.snapshot
## Build snapshot and publishes to your local maven.
snapshot:
# snapshot task comes from the yakworks shipkit plugin.
$(gradlew) snapshot
$(logr.done) "- libs with version $(VERSION)$(VERSION_SUFFIX) published to local ~/.m2 maven"
ifdef PUBLISHABLE_BRANCH_OR_DRY_RUN
# removed ship.docker kube.deploy for now
ship.release: build publish
$(logr.done)
ship.docker: docker.app-build docker.app-push
$(logr.done) "docker built and pushed"
kube.deploy: kube.create-ns kube.clean
$(kube_tools) apply_tpl $(APP_KUBE_SRC)/app-configmap.tpl.yml
$(kube_tools) apply_tpl $(APP_KUBE_SRC)/app-deploy.tpl.yml
$(logr.done)
else
ship.release:
$(logr.done) "not on a PUBLISHABLE_BRANCH, nothing to do"
endif # end PUBLISHABLE_BRANCH_OR_DRY_RUN
# ---- Docmark -------
# the "dockmark-build" target depends on this. depend on the docmark-copy-readme to move readme to index
docmark.build-prep: docmark.copy-readme
# --- Testing and misc, here below is for testing and debugging ----
PORT ?= 8080
# sanity checks api with curl -i -G http://localhost:8081/api/rally/org,
# pass PORT=8081 for other than default 8080, only works when security is turned off
api-sanity-check:
curl -i -G http://localhost:$(PORT)/api/rally/org/1
api-check-login:
curl -H "Content-Type: application/json" -X POST -d '{"username":"admin","password":"!@#Foo"}' \
http://localhost:8080/api/login
# gets token from curl and used that for sanity check
test.api-check-with-token:
curl_call="curl --silent -H 'Content-Type: application/json' -X POST \
-d '{\"username\":\"admin\",\"password\":\"!@#Foo\"}' \
http://localhost:$(PORT)/api/login"
resp=`eval "$$curl_call"`
echo -e "login response: $$resp \n"
token=`echo $$resp | awk -F'"' '/access_token/{ print $$(NF-1) }'`
curl_call="curl -G -H 'Authorization: Bearer $$token' http://localhost:$(PORT)/api/rally/org/1"
echo -e "$$curl_call \n"
eval $$curl_call
echo -e "\n$@ success"
# -- helpers --
ifdef IS_SNAPSHOT
# publish snapsot to repo.9ci
publish.snapshot.repo:
./gradlew publishJavaLibraryPublicationToMavenRepository
endif
## shows gorm-tools:dependencies --configuration runtime
gradle.dependencies:
$(gw) gorm-tools:dependencies # --configuration compileClasspath
# ./gradlew rally-api:dependencies --configuration compileClasspath
#./gradlew rally-security:dependencies --configuration compileClasspath
rally-api.dependencies:
./gradlew rally-api:dependencies --configuration compileClasspath
#./gradlew rally-security:dependencies --configuration compileClasspath
## shows spring dependencyManagement, modify to show other projects https://bit.ly/3CpcIls
spring.dependencyManagement:
$(gw) gorm-tools:dependencyManagement
## shows spring dependencyManagement, modify to show other projects https://bit.ly/3CpcIls
gradle.buildEnvironment:
$(gw) buildEnvironment
$(gw) gorm-tools:buildEnvironment
## runs the benchmark tests
test.benchmarks:
$(gw) benchmarks:assemble
cd examples/benchmarks
java -server -Xmx3g -XX:MaxMetaspaceSize=256m \
-DmultiplyData=3 -Dgorm.tools.async.poolSize=4 -Djava.awt.headless=true \
-Dgrails.env=prod -jar build/libs/benchmarks.jar
# -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap \
# -XX:+UseConcMarkSweepGC -XX:+UseCMSInitiatingOccupancyOnly \
# -XX:+CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=70 \
# -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark \
# -XX:SurvivorRatio=8 \
# start the rally-api example jar
start.rally-api: # start.db
${gradlew} rally-api:assemble
cd examples/rally-api
java -server -Xmx2g -jar build/libs/rally-api.jar
# clones the api-docs branch or this project where we will publish/push
# oapi.docs-clone:
# mkdir -p $(BUILD_DIR) && rm -rf "$(API_DOCS_BUILD_DIR)"
# git clone $(GITHUB_URL) $(API_DOCS_BUILD_DIR) -b $(API_DOCS_BRANCH) --single-branch --depth 1
# $(logr.done)
## run to get into builder shell
# make oapi.generate-apy-yaml
# make oapi.shell
# cd api-docs
# npm install # ONLY ONCE PER DOCKER! If you have a docker from last time, don't reinstall npm
# npm run start
BIN_BASH=/bin/bash
DOCKER_SHELL=yakworks/bullseye:dev
# for testing set up .env or export both GITHUB_TOKEN and the base64 enocded GPG_KEY from lastpass.
docker.circle.shell:
docker volume create gradle_cache
docker run -it --rm \
-e GITHUB_TOKEN \
-e GPG_KEY \
-v gradle_cache:/root/.gradle \
-v "$$PWD":/root/project \
$(DOCKER_SHELL) $(BIN_BASH)
# -v ~/.gradle_docker:/root/.gradle \
test.token.txt:
TOKEN=`http POST admin:123@localhost:8080/api/oauth/token.txt -b`
echo "$$TOKEN"
http localhost:8080/api -A bearer -a "$$TOKEN"
test.token:
RESP=`http -a admin:123 -b POST http://localhost:8080/api/oauth/token`
# use awk to parse out the access_token
TOKEN=`echo $$RESP | awk -F'"' -v RS="," '/access_token/{ print $$4 }'`
echo "$$TOKEN"
http localhost:8080/api -A bearer -a "$$TOKEN"
test.token-exchange:
RESP=`http -a admin:123 -b POST http://localhost:8080/api/oauth/token`
# use awk to parse out the access_token
TOKEN=`echo $$RESP | awk -F'"' -v RS="," '/access_token/{ print $$4 }'`
echo "$$TOKEN"
echo "curl -X POST -H 'Authorization: Bearer $$TOKEN' \
-d [email protected] \
-d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
http://localhost:8080/api/oauth/token"
sleep 1
curl -X POST -H 'Authorization: Bearer $$TOKEN' \
-d [email protected] \
-d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
http://localhost:8080/api/oauth/token
# http localhost:8080/api -A bearer -a "$$TOKEN"
test.token.cookie:
RESP=`https -b POST admin:123@localhost:8080/api/oauth/token`
# use awk to parse out the access_token
TOKEN=`echo $$RESP | awk -F'"' -v RS="," '/access_token/{ print $$4 }'`
echo "$$TOKEN"
http localhost:8080/api Cookie:jwt="$$TOKEN"
# curl -X POST -H 'Authorization: Bearer 4g2134lkjlkj1324.....' \
# -d [email protected] \
# -d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
# https://rcm-api.9ci.io/api/token
test.hello-post:
RESP=`http -b POST localhost:8080/api/login username=admin password=123`
echo $$RESP
TOKEN=`echo $$RESP | awk -F'"' -v RS="," '/access_token/{ print $$4 }'`
echo $$TOKEN
http localhost:8080 -A bearer -a "$$TOKEN"