forked from JamesClonk/backman
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
306 lines (256 loc) · 7.61 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
.DEFAULT_GOAL := run
SHELL := /bin/bash
APP = backman
COMMIT_SHA = $(shell git rev-parse --short HEAD)
DOCKER_TAG = latest
.PHONY: help
## help: prints this help message
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: run
## run: runs main.go with the race detector
run:
source _fixtures/env; source _fixtures/env_private; go run -race main.go
.PHONY: gin
## gin: runs main.go via gin (hot reloading)
gin:
source _fixtures/env; source _fixtures/env_private; gin --all --immediate run main.go
.PHONY: build
## build: builds the application
build: clean
@echo "Building binary ..."
go build -o ${APP}
.PHONY: clean
## clean: cleans up binary files
clean:
@echo "Cleaning up ..."
@go clean
.PHONY: install
## install: installs the application
install:
@echo "Installing binary ..."
go install
.PHONY: test
## test: runs go test with the race detector
test: build
@source _fixtures/env; GOARCH=amd64 GOOS=linux go test -v -race ./...
.PHONY: init
## init: sets up go modules
init:
@echo "Setting up modules ..."
@go mod init 2>/dev/null; go mod tidy && go mod vendor
.PHONY: docker-build
## docker-build: builds docker image
docker-build: clean
docker pull ubuntu:22.04
docker build -t jamesclonk/${APP}:${COMMIT_SHA} $$PWD
.PHONY: docker-push
## docker-push: pushes docker image to dockerhub
docker-push: docker-build
docker tag jamesclonk/${APP}:${COMMIT_SHA} jamesclonk/${APP}:${DOCKER_TAG}
docker push jamesclonk/${APP}:${DOCKER_TAG}
.PHONY: docker-run
## docker-run: runs docker image locally
docker-run: docker-clean
docker run -p 9990:8080 \
--env-file _fixtures/dockerenv \
--name ${APP} \
jamesclonk/${APP}
.PHONY: docker-clean
## docker-clean: cleans up local docker image
docker-clean:
docker rm -f ${APP} || true
.PHONY: docker-exec
## docker-exec: hijacks running docker container
docker-exec:
@docker exec -it ${APP} /bin/bash
docker-check-version:
ifndef IMAGE_VERSION
$(error IMAGE_VERSION not set)
endif
docker-set-tag:
DOCKER_TAG = $${IMAGE_VERSION}
.PHONY: docker-release
## docker-release: builds and releases docker image to dockerhub with given IMAGE_VERSION
docker-release: docker-check-version docker-set-tag docker-push
.PHONY: cleanup
cleanup: docker-cleanup
.PHONY: docker-cleanup
## docker-cleanup: cleans up local docker images and volumes
docker-cleanup:
docker system prune --volumes -a
.PHONY: swagger
## swagger: generates swagger documentation
swagger:
swagger generate spec -m -o ./swagger.yml
swagger serve -F=swagger swagger.yml
.PHONY: elasticsearch
## elasticsearch: runs elasticsearch backend on docker
elasticsearch: elasticsearch-network elasticsearch-stop elasticsearch-start elasticsearch-data
docker logs elasticsearch -f
.PHONY: elasticsearch-network
elasticsearch-network:
docker network create elasticsearch-network --driver bridge || true
.PHONY: elasticsearch-cleanup
## elasticsearch-cleanup: cleans up elasticsearch backend
elasticsearch-cleanup: elasticsearch-stop
.PHONY: elasticsearch-stop
elasticsearch-stop:
docker rm -f elasticsearch || true
.PHONY: elasticsearch-start
elasticsearch-start:
docker run -d -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
--network elasticsearch-network \
--name elasticsearch elasticsearch:6.8.2
.PHONY: elasticsearch-data
elasticsearch-data:
curl -O https://download.elastic.co/demos/kibana/gettingstarted/7.x/accounts.zip
unzip accounts.zip
sleep 20
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
.PHONY: minio
## minio: runs minio backend on docker
minio: minio-stop minio-start
docker logs minio -f
.PHONY: minio-cleanup
## minio-cleanup: cleans up minio backend
minio-cleanup: minio-stop
.PHONY: minio-stop
minio-stop:
docker rm -f minio || true
.PHONY: minio-start
minio-start:
docker run -d -p 9000:9000 --name minio \
-e "MINIO_ACCESS_KEY=6d611e2d-330b-4e52-a27c-59064d6e8a62" \
-e "MINIO_SECRET_KEY=eW9sbywgeW91IGhhdmUganVzdCBiZWVuIHRyb2xsZWQh" \
minio/minio server /data
.PHONY: mysql
## mysql: runs mysql backend on docker
mysql: mysql-network mysql-stop mysql-start
docker logs mysql -f
.PHONY: mysql-network
mysql-network:
docker network create mysql-network --driver bridge || true
.PHONY: mysql-cleanup
## mysql-cleanup: cleans up mysql backend
mysql-cleanup: mysql-stop
.PHONY: mysql-stop
mysql-stop:
docker rm -f mysql || true
.PHONY: mysql-start
mysql-start:
docker run -d -p 3306:3306 \
-e MYSQL_ROOT_PASSWORD='my-secret-pw' \
--network mysql-network \
--name mysql mysql:5.7
.PHONY: mysql-client
## mysql-client: connects to mysql backend with CLI
mysql-client:
docker run -it --rm \
-e MYSQL_PWD='my-secret-pw' \
--network mysql-network \
--name mysql-client mysql mysql -hmysql -uroot
.PHONY: mysql-test
## mysql-test: runs mysql integration tests
mysql-test: build
scripts/mysql.sh
.PHONY: postgres
## postgres: runs postgres backend on docker
postgres: postgres-network postgres-stop postgres-start
docker logs postgres -f
.PHONY: postgres-network
postgres-network:
docker network create postgres-network --driver bridge || true
.PHONY: postgres-cleanup
## postgres-cleanup: cleans up postgres backend
postgres-cleanup: postgres-stop
.PHONY: postgres-stop
postgres-stop:
docker rm -f postgres || true
.PHONY: postgres-start
postgres-start:
docker run --name postgres \
--network postgres-network \
-e POSTGRES_USER='dev-user' \
-e POSTGRES_PASSWORD='dev-secret' \
-e POSTGRES_DB='my_postgres_db' \
-p 5432:5432 \
-d postgres:9-alpine
.PHONY: postgres-client
## postgres-client: connects to postgres backend with CLI
postgres-client:
docker exec -it \
-e PGPASSWORD='dev-secret' \
postgres psql -U 'dev-user' -d 'my_postgres_db'
.PHONY: postgres-test
## postgres-test: runs postgres integration tests
postgres-test: build
scripts/postgres.sh
.PHONY: mongodb
## mongodb: runs mongodb backend on docker
mongodb: mongodb-network mongodb-stop mongodb-start
docker logs mongodb -f
.PHONY: mongodb-network
mongodb-network:
docker network create mongodb-network --driver bridge || true
.PHONY: mongodb-cleanup
## mongodb-cleanup: cleans up mongodb backend
mongodb-cleanup: mongodb-stop
.PHONY: mongodb-stop
mongodb-stop:
docker rm -f mongodb || true
.PHONY: mongodb-start
mongodb-start:
docker run --name mongodb \
--network mongodb-network \
-e MONGO_INITDB_ROOT_USERNAME='mongoadmin' \
-e MONGO_INITDB_ROOT_PASSWORD='super-secret' \
-p 27017:27017 \
-d mongo:3.6
.PHONY: mongodb-client
## mongodb-client: connects to mongodb backend with CLI
mongodb-client:
docker run -it --rm \
--network mongodb-network \
--name mongodb-client mongo:3.6 mongo \
--host mongodb \
-u 'mongoadmin' \
-p 'super-secret' \
--authenticationDatabase admin
.PHONY: mongodb-test
## mongodb-test: runs mongodb integration tests
mongodb-test: build
scripts/mongodb.sh
.PHONY: redis
## redis: runs redis backend on docker
redis: redis-network redis-stop redis-start
docker logs redis -f
.PHONY: redis-network
redis-network:
docker network create redis-network --driver bridge || true
.PHONY: redis-cleanup
## redis-cleanup: cleans up redis backend
redis-cleanup: redis-stop
.PHONY: redis-stop
redis-stop:
docker rm -f redis || true
.PHONY: redis-start
redis-start:
docker run --name redis \
--network redis-network \
-p 6379:6379 \
-d redis \
redis-server --requirepass 'very-secret'
.PHONY: redis-client
## redis-client: connects to redis backend with CLI
redis-client:
docker run -it --rm \
--network redis-network \
--name redis-cli redis redis-cli \
-h redis -a 'very-secret'
.PHONY: redis-test
## redis-test: runs redis integration tests
redis-test: build
scripts/redis.sh