-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
145 lines (119 loc) · 3.78 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
# Base Go commands.
GO_CMD := go
GO_FMT := $(GO_CMD) fmt
GO_INSTALL := $(GO_CMD) install
GO_CLEAN := $(GO_CMD) clean
GO_BUILD := $(GO_CMD) build
# Coverage output.
COVER_OUT := cover.out
# Base swagger commands.
SWAG := swag
SWAG_GEN := $(SWAG) init
# Base golangci-lint commands.
GCL_CMD := golangci-lint
GCL_RUN := $(GCL_CMD) run
# Base protoc commands.
PROTOC := protoc
# Project executable file, and its binary.
CMD_PATH := ./cmd/shimakaze
BINARY_NAME := shimakaze
# Default makefile target.
.DEFAULT_GOAL := run
# Standarize go coding style for the whole project.
.PHONY: fmt
fmt:
@$(GO_FMT) ./...
# Lint go source code.
.PHONY: lint
lint: fmt
@$(GCL_RUN) -D errcheck --timeout 5m
# Clean project binary, test, and coverage file.
.PHONY: clean
clean:
@$(GO_CLEAN) ./...
# Generate swagger docs.
.PHONY: swagger
swagger:
@$(SWAG_GEN) -g cmd/shimakaze/main.go -o ./docs
# Install library.
.PHONY: install
install:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.46.2
@$(GCL_CMD) version
@$(GO_INSTALL) github.com/swaggo/swag/cmd/swag@v1.8.3
@$(SWAG) -v
# Build the project executable binary.
.PHONY: build
build: clean fmt
@cd $(CMD_PATH); \
$(GO_BUILD) -o $(BINARY_NAME) -v .
# Build and run the binary.
.PHONY: run
run: build
@cd $(CMD_PATH); \
./$(BINARY_NAME) server
# Build and run message consumer.
.PHONY: consumer
consumer: build
@cd $(CMD_PATH); \
./$(BINARY_NAME) consumer
# Build and run cron update anime.
.PHONY: cron-update
cron-update: build
@cd $(CMD_PATH); \
./$(BINARY_NAME) cron update
# Build and run cron fill missing anime.
.PHONY: cron-fill
cron-fill: build
@cd $(CMD_PATH); \
./$(BINARY_NAME) cron fill
# Docker base command.
DOCKER_CMD := docker
DOCKER_IMAGE := $(DOCKER_CMD) image
# Docker-compose base command and docker-compose.yml path.
COMPOSE_CMD := docker-compose
COMPOSE_BUILD := deployment/build.yml
COMPOSE_API := deployment/api.yml
COMPOSE_CONSUMER := deployment/consumer.yml
COMPOSE_CRON_UPDATE := deployment/cron-update.yml
COMPOSE_CRON_FILL := deployment/cron-fill.yml
COMPOSE_LINT := deployment/lint.yml
# Build docker images and container for the project
# then delete builder image.
.PHONY: docker-build
docker-build:
@$(COMPOSE_CMD) -f $(COMPOSE_BUILD) build
@$(DOCKER_IMAGE) prune -f --filter label=stage=shimakaze_builder
# Start built docker containers for api.
.PHONY: docker-api
docker-api:
@$(COMPOSE_CMD) -f $(COMPOSE_API) -p shimakaze-api up -d
@$(COMPOSE_CMD) -f $(COMPOSE_API) -p shimakaze-api logs --follow --tail 20
# Start built docker containers for consumer.
.PHONY: docker-consumer
docker-consumer:
@$(COMPOSE_CMD) -f $(COMPOSE_CONSUMER) -p shimakaze-consumer up -d
@$(COMPOSE_CMD) -f $(COMPOSE_CONSUMER) -p shimakaze-consumer logs --follow --tail 20
# Start built docker containers for cron update anime.
.PHONY: docker-cron-update
docker-cron-update:
@$(COMPOSE_CMD) -f $(COMPOSE_CRON_UPDATE) -p shimakaze-cron-update up
# Start built docker containers for cron fill missing anime.
.PHONY: docker-cron-fill
docker-cron-fill:
@$(COMPOSE_CMD) -f $(COMPOSE_CRON_FILL) -p shimakaze-cron-fill up
# Start docker to run lint check.
.PHONY: docker-lint
docker-lint:
@$(COMPOSE_CMD) -f $(COMPOSE_LINT) -p shimakaze-lint run --rm shimakaze-lint $(GCL_RUN) -D errcheck --timeout 5m
# Update docker containers.
.PHONY: docker-update
docker-update:
@$(COMPOSE_CMD) -f $(COMPOSE_API) -p shimakaze-api up -d
@$(COMPOSE_CMD) -f $(COMPOSE_CONSUMER) -p shimakaze-consumer up -d
@$(DOCKER_IMAGE) prune -f --filter label=stage=shimakaze_binary
# Stop running docker containers.
.PHONY: docker-stop
docker-stop:
@$(COMPOSE_CMD) -f $(COMPOSE_API) -p shimakaze-api stop
@$(COMPOSE_CMD) -f $(COMPOSE_CONSUMER) -p shimakaze-consumer stop