forked from clearflask/clearflask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
249 lines (204 loc) · 14.9 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
242
243
244
245
246
247
248
249
.EXPORT_ALL_VARIABLES:
AWS_PROFILE = clearflask
help:
@echo "\tmake run-dev-frontend\n\tmake build-no-test && make run-dev\n\tmake build && make publish-jar && make prod-rolling-restart"
build:
mvn install
build-no-test:
mvn install -DskipTests
build-no-it:
mvn install -DskipITs
build-server-no-test:
cd clearflask-server && mvn install -DskipTests
frontend-start:
cd clearflask-frontend && node/node_modules/pnpm/bin/pnpm.cjs start
connect-start:
cd clearflask-frontend && node/node_modules/pnpm/bin/pnpm.cjs run start:connect
clearflask-release/target/run-docker-compose-local/docker-compose.yml: get-project-version
test -f clearflask-release/target/clearflask-release-$(PROJECT_VERSION)-docker-compose-local.tar.gz
rm -fr clearflask-release/target/run-docker-compose-local
mkdir clearflask-release/target/run-docker-compose-local
tar -xzf clearflask-release/target/clearflask-release-$(PROJECT_VERSION)-docker-compose-local.tar.gz -C clearflask-release/target/run-docker-compose-local
cp -n clearflask-release/target/run-docker-compose-local/server/config-local-template.cfg ./config-local.cfg \
&& echo IMPORTANT: Created config-local.cfg please adjust settings for local deployment || true
cp ./config-local.cfg clearflask-release/target/run-docker-compose-local/server/config-local.cfg
cp -n clearflask-release/target/run-docker-compose-local/connect/connect.config.local-template.json ./connect.config-local.json \
&& echo IMPORTANT: Created connect.config.json please adjust settings for local deployment || true
cp ./connect.config-local.json clearflask-release/target/run-docker-compose-local/connect/connect.config.json
local-up: clearflask-release/target/run-docker-compose-local/docker-compose.yml
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch up -d
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch logs -f
local-down: clearflask-release/target/run-docker-compose-local/docker-compose.yml
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch down -t 0
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch rm
local-full-up: clearflask-release/target/run-docker-compose-local/docker-compose.yml
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch,with-kaui,with-kabana up -d
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch,with-kaui,with-kabana logs -f
local-full-down: clearflask-release/target/run-docker-compose-local/docker-compose.yml
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch,with-kaui,with-kabana down -t 0
docker-compose -f clearflask-release/target/run-docker-compose-local/docker-compose.yml --profile with-elasticsearch,with-kaui,with-kabana rm
clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml: get-project-version
test -f clearflask-release/target/clearflask-release-$(PROJECT_VERSION)-docker-compose-self-host.tar.gz
rm -fr clearflask-release/target/run-docker-compose-selfhost
mkdir clearflask-release/target/run-docker-compose-selfhost
tar -xzf clearflask-release/target/clearflask-release-$(PROJECT_VERSION)-docker-compose-self-host.tar.gz -C clearflask-release/target/run-docker-compose-selfhost
sed -i'.original' 's,ghcr.io/clearflask,clearflask,g' clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml
selfhost-up: clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml
docker-compose -f clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml --profile with-deps up -d
docker-compose -f clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml --profile with-deps logs -f
selfhost-down: clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml
docker-compose -f clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml --profile with-deps down -t 0
docker-compose -f clearflask-release/target/run-docker-compose-selfhost/docker-compose.yml --profile with-deps rm
killbill-sleep-%:
curl -v \
-u admin:password \
-H "X-Killbill-ApiKey: bob" \
-H 'X-Killbill-ApiSecret: lazar' \
-H "Content-Type: application/json" \
-H 'X-Killbill-CreatedBy: admin' \
-X PUT \
"http://127.0.0.1:8082/1.0/kb/test/clock?days=$*"
get-project-version:
$(eval PROJECT_VERSION := $(shell mvn -q -Dexec.executable=echo -Dexec.args='$${project.version}' --non-recursive exec:exec))
echo "Project version is $(PROJECT_VERSION)"
release-patch:
mvn build-helper:parse-version \
-DreleaseVersion=\$${parsedVersion.majorVersion}.\$${parsedVersion.minorVersion}.\$${parsedVersion.nextIncrementalVersion} \
-DdevelopmentVersion=\$${parsedVersion.majorVersion}.\$${parsedVersion.minorVersion}.\$${parsedVersion.nextIncrementalVersion}-SNAPSHOT \
--batch-mode -Dresume=false -DskipITs -Darguments=-DskipITs release:prepare
make release-perform
make release-github-release
release-minor:
mvn build-helper:parse-version \
-DreleaseVersion=\$${parsedVersion.majorVersion}.\$${parsedVersion.nextMinorVersion}.0 \
-DdevelopmentVersion=\$${parsedVersion.majorVersion}.\$${parsedVersion.nextMinorVersion}.0-SNAPSHOT \
--batch-mode -Dresume=false -DskipITs -Darguments=-DskipITs release:prepare
make release-perform
make release-github-release
release-major:
mvn build-helper:parse-version \
-DreleaseVersion=\$${parsedVersion.nextMajorVersion}.0.0 \
-DdevelopmentVersion=\$${parsedVersion.nextMajorVersion}.0.0-SNAPSHOT \
--batch-mode -Dresume=false -DskipITs -Darguments=-DskipITs release:prepare
make release-perform
make release-github-release
release-perform:
mvn -DskipTests -Darguments=-DskipTests --batch-mode release:perform
release-github-release:
mvn build-helper:parse-version \
-DgithubReleaseVersion=\$${parsedVersion.majorVersion}.\$${parsedVersion.minorVersion}.\$${parsedVersion.incrementalVersion} \
-Dgithub.draft=true --non-recursive github-release:release
deploy-singlehost:
$(eval TIMESTAMP := $(shell date +%Y%m%d%H%M%S))
make $(foreach server, \
$(shell aws ec2 describe-instances --no-paginate --output text \
--instance-ids $(shell aws ec2 describe-instances --filters 'Name=tag:Name,Values=cf-kb' --output text --query 'Reservations[*].Instances[*].InstanceId') \
--query "Reservations[].Instances[].{Host:PublicDnsName}"), \
deploy-singlehost-$(server) )
deploy-singlehost-%: get-project-version
echo "Deploying to $*"
scp ./clearflask-server/target/clearflask-server-$(PROJECT_VERSION).war $*:/home/ec2-user/clearflask-server-$(TIMESTAMP)-$(PROJECT_VERSION).war
ssh $* "sudo cp /home/ec2-user/clearflask-server-$(TIMESTAMP)-$(PROJECT_VERSION).war /var/lib/tomcat/webapps/150clearflask/ROOT##$(TIMESTAMP)-$(PROJECT_VERSION).war && \
ls -tp /home/ec2-user | grep '^clearflask-server-' | tail -n +6 | xargs -I {} rm -- {}"
scp ./clearflask-frontend/target/clearflask-frontend-$(PROJECT_VERSION)-connect.tar.gz $*:/home/ec2-user/clearflask-frontend-0.1-connect.tar.gz
ssh $* "sudo service connect stop && sudo rm -fr /srv/clearflask-connect/* && sudo tar -xzf /home/ec2-user/clearflask-frontend-0.1-connect.tar.gz -C /srv/clearflask-connect && sudo chmod go-rwx -R /srv/clearflask-connect && sudo chown connect:connect -R /srv/clearflask-connect && sudo service connect start"
deploy-connect-singlehost:
make $(foreach server, \
$(shell aws ec2 describe-instances --no-paginate --output text \
--instance-ids $(shell aws ec2 describe-instances --filters 'Name=tag:Name,Values=cf-kb' --output text --query 'Reservations[*].Instances[*].InstanceId') \
--query "Reservations[].Instances[].{Host:PublicDnsName}"), \
deploy-singlehost-$(server) )
deploy-connect-singlehost-%: get-project-version
echo "Deploying to $*"
scp ./clearflask-frontend/target/clearflask-frontend-$(PROJECT_VERSION)-connect.tar.gz $*:/home/ec2-user/clearflask-frontend-0.1-connect.tar.gz
ssh $* "sudo service connect stop && sudo rm -fr /srv/clearflask-connect/* && sudo tar -xzf /home/ec2-user/clearflask-frontend-0.1-connect.tar.gz -C /srv/clearflask-connect && sudo chmod go-rwx -R /srv/clearflask-connect && sudo chown connect:connect -R /srv/clearflask-connect && sudo service connect start"
deploy-server-singlehost:
make $(foreach server, \
$(shell aws ec2 describe-instances --no-paginate --output text \
--instance-ids $(shell aws ec2 describe-instances --filters 'Name=tag:Name,Values=cf-kb' --output text --query 'Reservations[*].Instances[*].InstanceId') \
--query "Reservations[].Instances[].{Host:PublicDnsName}"), \
deploy-singlehost-$(server) )
deploy-server-singlehost-%: get-project-version
echo "Deploying to $*"
scp ./clearflask-server/target/clearflask-server-$(PROJECT_VERSION).war $*:/home/ec2-user/clearflask-server-0.1.war
ssh $* "sudo service tomcat stop && sudo rm -fr /var/lib/tomcat/webapps/150clearflask/ROOT.war /var/lib/tomcat/webapps/150clearflask/ROOT && sudo cp /home/ec2-user/clearflask-server-0.1.war /var/lib/tomcat/webapps/150clearflask/ROOT.war && sudo service tomcat start"
deploy-autoscale:
make deploy-server
make deploy-connect
make deploy-rotate-instances
make deploy-cloudfront-invalidate-all
deploy-server: get-project-version
aws s3 cp ./clearflask-server/target/clearflask-server-$(PROJECT_VERSION).war s3://clearflask-secret/clearflask-server-0.1.war
deploy-logging: get-project-version
aws s3 cp ./clearflask-logging/target/clearflask-logging-$(PROJECT_VERSION)-standalone.jar s3://killbill-secret/clearflask-logging-0.1-standalone.jar
deploy-connect: get-project-version
aws s3 cp ./clearflask-frontend/target/clearflask-frontend-$(PROJECT_VERSION)-connect.tar.gz s3://clearflask-secret/clearflask-frontend-0.1-connect.tar.gz
deploy-static: ./clearflask-server/target/war-include/ROOT deploy-manifest deploy-files
deploy-rotate-instances:
tools/instance-refresh-and-wait.sh clearflask-server
aws autoscaling describe-auto-scaling-instances --no-paginate --output table --query "AutoScalingInstances[?AutoScalingGroupName=='clearflask-server']"
deploy-running-configs:
make $(foreach server, \
$(shell aws ec2 describe-instances --no-paginate --output text \
--instance-ids $(shell aws autoscaling describe-auto-scaling-instances --output text --query "AutoScalingInstances[?AutoScalingGroupName=='clearflask-server'].InstanceId") \
--query "Reservations[].Instances[].{Host:PublicDnsName}"), \
deploy-running-config-$(server) )
deploy-running-config-%:
echo "Syncing config to $*"
ssh $* "sudo aws s3 cp s3://clearflask-secret/config-prod.cfg /opt/clearflask/config-prod.cfg && sudo aws s3 cp s3://clearflask-secret/connect.config.json /opt/clearflask/connect.config.json && sudo service connect restart"
deploy-running-servers:
make $(foreach server, \
$(shell aws ec2 describe-instances --no-paginate --output text \
--instance-ids $(shell aws autoscaling describe-auto-scaling-instances --output text --query "AutoScalingInstances[?AutoScalingGroupName=='clearflask-server'].InstanceId") \
--query "Reservations[].Instances[].{Host:PublicDnsName}"), \
deploy-running-server-$(server) )
deploy-running-server-%: get-project-version
echo "Deploying to $*"
scp ./clearflask-server/target/clearflask-server-$(PROJECT_VERSION).war $*:/home/ec2-user/clearflask-server-0.1.war
ssh $* "sudo service tomcat stop && sudo rm -fr /var/lib/tomcat/webapps/ROOT.war /var/lib/tomcat/webapps/ROOT && sudo cp /home/ec2-user/clearflask-server-0.1.war /var/lib/tomcat/webapps/ROOT.war && sudo service tomcat start"
deploy-running-connects:
make $(foreach server, \
$(shell aws ec2 describe-instances --no-paginate --output text \
--instance-ids $(shell aws autoscaling describe-auto-scaling-instances --output text --query "AutoScalingInstances[?AutoScalingGroupName=='clearflask-server'].InstanceId") \
--query "Reservations[].Instances[].{Host:PublicDnsName}"), \
deploy-running-connect-$(server) )
deploy-running-connect-%: get-project-version
echo "Deploying to $*"
scp ./clearflask-frontend/target/clearflask-frontend-$(PROJECT_VERSION)-connect.tar.gz $*:/home/ec2-user/clearflask-frontend-0.1-connect.tar.gz
ssh $* "sudo service connect stop && sudo rm -fr /srv/clearflask-connect/* && sudo tar -xzf /home/ec2-user/clearflask-frontend-0.1-connect.tar.gz -C /srv/clearflask-connect && sudo chmod go-rwx -R /srv/clearflask-connect && sudo chown connect:connect -R /srv/clearflask-connect && sudo service connect start"
deploy-cloudfront-invalidate:
aws cloudfront create-invalidation --distribution-id EQHBQLQZXVKCU --paths /index.html /service-worker.js /sw.js /asset-manifest.json
deploy-cloudfront-invalidate-all:
aws cloudfront create-invalidation --distribution-id EQHBQLQZXVKCU --paths "/*"
deploy-emergency:
make deploy-running-configs
make deploy-running-servers
make deploy-running-connects
make deploy-cloudfront-invalidate-all
make deploy-server
make deploy-connect
autoscale-server-suspend:
aws autoscaling suspend-processes --auto-scaling-group-name clearflask-server --scaling-processes Launch Terminate
autoscale-server-resume:
aws autoscaling resume-processes --auto-scaling-group-name clearflask-server --scaling-processes Launch Terminate
autoscale-killbill-suspend:
aws autoscaling suspend-processes --auto-scaling-group-name killbill-webserver --scaling-processes Launch Terminate
autoscale-killbill-resume:
aws autoscaling resume-processes --auto-scaling-group-name killbill-webserver --scaling-processes Launch Terminate
list-instances-cf-kb:
aws ec2 describe-instances --no-paginate --output table \
--instance-ids $(shell aws ec2 describe-instances --filters 'Name=tag:Name,Values=cf-kb' --output text --query 'Reservations[*].Instances[*].InstanceId') \
--query "Reservations[].Instances[].{Host:PublicDnsName,Id:InstanceId,AZ:Placement.AvailabilityZone,Type:InstanceType,State:State.Name,Name:Tags[?Key=='Name']|[0].Value}"
list-instances-clearflask:
aws ec2 describe-instances --no-paginate --output table \
--instance-ids $(shell aws autoscaling describe-auto-scaling-instances --output text --query "AutoScalingInstances[?AutoScalingGroupName=='clearflask-server'].InstanceId") \
--query "Reservations[].Instances[].{Host:PublicDnsName,Id:InstanceId,AZ:Placement.AvailabilityZone,Type:InstanceType,State:State.Name,Name:Tags[?Key=='Name']|[0].Value}"
list-instances-killbill:
aws ec2 describe-instances --no-paginate --output table \
--instance-ids $(shell aws autoscaling describe-auto-scaling-instances --output text --query "AutoScalingInstances[?AutoScalingGroupName=='killbill-webserver'].InstanceId") \
--query "Reservations[].Instances[].{Host:PublicDnsName,Id:InstanceId,AZ:Placement.AvailabilityZone,Type:InstanceType,State:State.Name,Name:Tags[?Key=='Name']|[0].Value}"
.PHONY: \
build \
build-no-test \
killbill-sleep-% \
get-project-version