-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (89 loc) · 3.14 KB
/
Copy pathMakefile
File metadata and controls
110 lines (89 loc) · 3.14 KB
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
include app.env
export $(shell sed 's/=.*//' app.env)
export GO111MODULE=on
prod_docker_compose_file=./docker/hs_auth/docker-compose.yml
dev_docker_compose_file=./docker/hs_auth_dev/docker-compose.yml
test_docker_compose_file=./docker/hs_auth_test/docker-compose.yml
default: build test
# checks the code for problems
.PHONY: vet
vet:
go vet
# starts the app
run: vet
@echo "=============vetting the code============="
go run main.go wire_gen.go server.go
.PHONY: mocks
mocks: clean-mocks
@echo "=============generating mocks============="
grep -rl --exclude-dir 'vendor' --exclude-dir 'data' --include "*.go" "interface {" . | while read -r file ; do mockgen --source=$$file --destination mocks/$$file ; done
# runs test
test: vet mocks
go test -cover ./...
test-integration: vet mocks
docker-compose -f $(test_docker_compose_file) up -d
go test -cover ./... -tags integration
# build target for CI
ci: vet mocks
docker-compose -f $(test_docker_compose_file) up -d
go test ./... -coverprofile=coverage.txt -covermode=atomic -tags integration
bench: vet mocks
docker-compose -f $(test_docker_compose_file) up -d
go test ./... -run=xxx -bench=. benchtime 30s
# builds the executable
build:
go build -o bin/hs_auth main.go
# builds the docker image
build-docker:
@echo "=============building hs_auth============="
docker build -f docker/hs_auth/Dockerfile -t hs_auth . ;
# sets up the hacker suite docker network
setup-network:
@echo "=============setting up the hacker suite network============="
docker network create --driver bridge hacker_suite || echo "This is most likely fine, it just means that the network has already been created"
# starts the app and MongoDB in docker containers
up: vet build-docker setup-network
@echo "=============starting hs_auth============="
docker-compose -f $(prod_docker_compose_file) up -d
# starts the app and MongoDB in docker containers for dev environment
up-dev: export ENVIRONMENT=dev
up-dev: export PORT=8000
up-dev: export MONGO_HOST=127.0.0.1:8002
up-dev: vet setup-network
@echo "=============starting hs_auth (dev)============="
docker-compose -f $(dev_docker_compose_file) up -d
refresh run
# prints the logs from all containers
logs:
ifeq ($(ENV), dev)
docker-compose -f $(dev_docker_compose_file) logs -f
else
docker-compose -f $(prod_docker_compose_file) logs -f
endif
# prints the logs only from the go app
logs-app:
docker-compose -f $(prod_docker_compose_file) logs -f hs_auth
# prints the logs only from the database
logs-db:
ifeq ($(ENV), dev)
docker-compose -f $(dev_docker_compose_file) logs -f mongo
else
docker-compose -f $(prod_docker_compose_file) logs -f mongo
endif
# shuts down the containers
down:
docker-compose -f $(prod_docker_compose_file) down
docker-compose -f $(dev_docker_compose_file) down
docker-compose -f $(test_docker_compose_file) down
# cleans up unused images, networks and containers
# WARNING: this will delete ALL docker images on the system
# that are not being used
clean: down
@echo "=============cleaning up============="
rm -f hs_auth
docker container prune -f
docker network prune -f
docker system prune -f
docker volume prune -f
clean-mocks:
rm -rf ./mocks