-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathMakefile
133 lines (106 loc) · 4.86 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
include version.mk
# Load environment variables from the .env file
include .env
# Export variables so they are available in the Makefile
export
# Check for required dependencies
CHECK_MOCKERY := $(shell command -v mockery 2> /dev/null)
CHECK_GO := $(shell command -v go 2> /dev/null)
CHECK_DOCKER := $(shell command -v docker 2> /dev/null)
CHECK_CURL := $(shell command -v curl 2> /dev/null)
CHECK_PROTOC := $(shell command -v protoc 2> /dev/null)
CHECK_PROTOC_GEN_MICRO := $(shell command -v protoc-gen-micro 2> /dev/null)
CHECK_PROTOC_GEN_GO := $(shell command -v protoc-gen-go 2> /dev/null)
CHECK_SWAGGER := $(shell command -v swagger 2> /dev/null)
check-mockery:
ifndef CHECK_MOCKERY
$(error "Mockery is not installed. Please install Mockery and retry.")
endif
check-go:
ifndef CHECK_GO
$(error "Go is not installed. Please install Go and retry.")
endif
check-docker:
ifndef CHECK_DOCKER
$(error "Docker is not installed. Please install Docker and retry.")
endif
check-curl:
ifndef CHECK_CURL
$(error "curl is not installed. Please install curl and retry.")
endif
check-protoc:
ifndef CHECK_PROTOC
$(error "protoc is not installed. Please install protoc and retry.")
endif
check-protoc-gen-micro:
ifndef CHECK_PROTOC_GEN_MICRO
$(error "protoc-gen-micro is not installed. Please install protoc-gen-micro and retry.")
endif
check-protoc-gen-go:
ifndef CHECK_PROTOC_GEN_GO
$(error "protoc-gen-go is not installed. Please install protoc-gen-go and retry.")
endif
check-swagger:
ifndef CHECK_SWAGGER
$(error "swagger is not installed. Please install swagger and retry.")
endif
# Targets that require the checks
generate: check-protoc check-protoc-gen-go check-protoc-gen-micro check-swagger
build: check-go
build-docker: check-docker
build-docker-nc: check-docker
install-linter: check-go check-curl
lint: check-go
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
ARCH = amd64
else
ifeq ($(ARCH),aarch64)
ARCH = arm64
endif
endif
GOOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
GOENVVARS := CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH)
LDFLAGS += -X 'github.com/begmaroman/go-micro-boilerplate.Version=$(VERSION)'
LDFLAGS += -X 'github.com/begmaroman/go-micro-boilerplate.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/begmaroman/go-micro-boilerplate.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/begmaroman/go-micro-boilerplate.BuildDate=$(DATE)'
.PHONY: generate
generate: ## Generates mocks and other autogenerated types
go generate -x ./proto
go generate -x ./services/rest-api-svc/swaggergen
.PHONY: build-rest-api-svc
build-rest-api-svc: ## Builds the rest-api-svc binary locally into ./dist
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o ./services/rest-api-svc/dist/rest-api-svc ./services/rest-api-svc/cmd/main.go
.PHONY: build-account-svc
build-account-svc: ## Builds the account-svc binary locally into ./dist
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o ./services/account-svc/dist/account-svc ./services/account-svc/cmd/main.go
.PHONY: build-base-image
build-base-image: ## Builds a docker image
docker build --platform linux/amd64 -f services/Dockerfile -t go-micro-boilerplate-base:latest .
.PHONY: build-and-push-images
build-and-push-images: ## Builds docker images and pushes them to the remote registry
docker build --platform linux/amd64 -f services/rest-api-svc/Dockerfile -t $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/go-micro-boilerplate/rest-api-svc:latest .
aws ecr get-login-password --region $(AWS_REGION) --profile personal | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/go-micro-boilerplate/rest-api-svc
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/go-micro-boilerplate/rest-api-svc:latest
docker build --platform linux/amd64 -f services/account-svc/Dockerfile -t $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/go-micro-boilerplate/account-svc:latest .
aws ecr get-login-password --region $(AWS_REGION) --profile personal | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/go-micro-boilerplate/account-svc
docker push $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/go-micro-boilerplate/account-svc:latest
.PHONY: install-linter
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.59.1
.PHONY: lint
lint: ## Runs the linter
golangci-lint run
.PHONY: test-unit
test-unit: ## Runs the unit tests
go test -v ./... -short -race -timeout=10m -coverprofile=coverage.out
## Help display.
## Pulls comments from beside commands and prints a nicely formatted
## display with the commands and their usage information.
.DEFAULT_GOAL := help
.PHONY: help
help: ## Prints this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'