-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
99 lines (81 loc) · 3.26 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
# =========================================================================== #
# HELPERS
# =========================================================================== #
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
# =========================================================================== #
# DEVELOPMENT
# =========================================================================== #
## run/api: run the cmd/api application
.PHONY: run/api
run/api:
go run ./cmd/api
# =========================================================================== #
# QUALITY CONTROL
# =========================================================================== #
## test: test the code
.PHONY: test
test:
go test ./...
## audit: tidy dependencies, format, vet, and test the code
.PHONY: audit
audit:
@echo 'Tidying and verifying module dependencies...'
go mod tidy
go mod verify
@echo 'Formatting the code...'
go fmt ./...
@echo 'Vetting the code...'
go vet ./...
staticcheck ./...
@echo 'Running tests...'
go test -race -vet=off ./...
# =========================================================================== #
# BUILD
# =========================================================================== #
arch = 386
build_dir = linux_${arch}
service_name = homebugh-api
current_time = $(shell date +%Y-%m-%dT%H:%M:%S%z)
git_description = $(shell git describe --always --dirty --tags --long)
linker_flags = "-s -X 'main.buildTime=${current_time}' -X 'main.build=${git_description}'"
## build/api: build the cmd/api application
.PHONY: build/api
build/api:
@echo 'Building cmd/api...'
go build -ldflags=${linker_flags} -o=./bin/${service_name} ./cmd/api
GOOS=linux GOARCH=${arch} go build -ldflags=${linker_flags} -o=./bin/${build_dir}/${service_name} ./cmd/api
# =========================================================================== #
# PRODUCTION
# =========================================================================== #
production_host = homebugh.info
deploy_user = deploy
deploy_dir = ~/apps/homebugh-api/
## production/deploy/api: deploy the api to production
.PHONY: production/deploy/api
production/deploy/api:
rsync -P ./bin/${build_dir}/${service_name} ${deploy_user}@${production_host}:${deploy_dir}
ssh -t deploy@${production_host} 'sudo systemctl restart ${service_name}'
## production/deploy/systemdconfig: deploy the systemd config to production
.PHONY: production/deploy/systemdconfig
production/deploy/systemdconfig:
rsync -P ./remote/production/${service_name}.service ${deploy_user}@${production_host}:~
ssh -t ${deploy_user}@${production_host} '\
sudo mv ~/${service_name}.service /etc/systemd/system/ \
&& sudo systemctl enable ${service_name} \
&& sudo systemctl restart ${service_name} \
'
## production/status/api: prints api service status
.PHONY: production/status/api
production/status/api:
ssh -t ${deploy_user}@${production_host} 'sudo systemctl status ${service_name}'
@echo "\n------------------------------------------"
curl https://api.${production_host}:8080/health
@echo ""
## production/restart/api: restarts api service status
.PHONY: production/restart/api
production/restart/api:
ssh -t ${deploy_user}@${production_host} 'sudo systemctl restart ${service_name}'