-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (116 loc) · 5.84 KB
/
Makefile
File metadata and controls
152 lines (116 loc) · 5.84 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
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
SERVICE_DIR := cmd
FRONTEND_DIR := web/frontend
TEST_OUT_DIR := ./test-reports
VERSION ?= 0.8.6
BUILD_INFO ?= "Local makefile build"
DAPR_RUN_LOGLEVEL := warn
# Only change these if testing with different components
#DAPR_STORE_NAME := statestore-table
#DAPR_PUBSUB_NAME := pubsub
# Most likely want to override these when calling `make image-all`
IMAGE_REG ?= ghcr.io
IMAGE_REPO ?= azure-samples/dapr-store
IMAGE_TAG ?= latest
IMAGE_PREFIX := $(IMAGE_REG)/$(IMAGE_REPO)
API_ENDPOINT := http://localhost:9000/v1.0/invoke
.EXPORT_ALL_VARIABLES:
.PHONY: help lint lint-fix test test-reports docker-build docker-run docker-stop docker-push bundle clean run stop
.DEFAULT_GOAL := help
help: ## 💬 This help message :)
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
lint: $(FRONTEND_DIR)/node_modules ## 🔎 Lint & format, check to be run in CI, sets exit code on error
golangci-lint run --modules-download-mode=mod --timeout=4m ./...
cd $(FRONTEND_DIR); npm run lint
lint-fix: $(FRONTEND_DIR)/node_modules ## 📝 Lint & format, fixes errors and modifies code
golangci-lint run --modules-download-mode=mod --timeout=4m --fix ./...
cd $(FRONTEND_DIR); npm run lint-fix
test: $(FRONTEND_DIR)/node_modules ## 🎯 Run unit tests for services and snapshot tests for SPA frontend
go test -v -count=1 ./$(SERVICE_DIR)/...
@cd $(FRONTEND_DIR); npm run test:unit
test-report: $(FRONTEND_DIR)/node_modules ## 🎯 Run unit tests and generate report
mkdir -p $(TEST_OUT_DIR)
go test -v -count=1 ./$(SERVICE_DIR)/... | go-junit-report -set-exit-code > $(TEST_OUT_DIR)/unit.xml
@cd $(FRONTEND_DIR); npm run test:unit:report
test-api: ## 🧪 Run API integration tests with httpYac
npx httpyac send api/api-tests.http --all --output short --var endpoint=$(API_ENDPOINT)
test-api-report: ## 🧪 Run API integration tests with httpYac & generate report
mkdir -p $(TEST_OUT_DIR)
npx httpyac send api/api-tests.http --all --output short --var endpoint=$(API_ENDPOINT) --junit > $(TEST_OUT_DIR)/api.xml
frontend: $(FRONTEND_DIR)/node_modules ## 💻 Build and bundle the frontend Vue SPA
cd $(FRONTEND_DIR); npm run build
cd $(SERVICE_DIR)/frontend-host; go build
clean: ## 🧹 Clean the project, remove modules, binaries and outputs
rm -rf $(TEST_OUT_DIR)
rm -rf $(FRONTEND_DIR)/node_modules
rm -rf $(FRONTEND_DIR)/dist
rm -rf $(FRONTEND_DIR)/coverage
rm -rf $(SERVICE_DIR)/cart/cart
rm -rf $(SERVICE_DIR)/orders/orders
rm -rf $(SERVICE_DIR)/users/users
rm -rf $(SERVICE_DIR)/products/products
rm -rf $(SERVICE_DIR)/frontend-host/frontend-host
clear-state: ## 💥 Clear all state from Redis (wipe the database)
docker run --rm --network host redis redis-cli flushall
run: $(FRONTEND_DIR)/node_modules ## 🚀 Start & run everything locally as processes
cd $(FRONTEND_DIR); npm run dev &
dapr run --app-id cart --app-port 9001 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/cart &
dapr run --app-id products --app-port 9002 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/products ./cmd/products/sqlite.db &
dapr run --app-id users --app-port 9003 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/users &
dapr run --app-id orders --app-port 9004 --log-level $(DAPR_RUN_LOGLEVEL) go run github.com/azure-samples/dapr-store/cmd/orders &
@sleep 6
@./scripts/local-gateway/run.sh &
@touch -m /tmp/dapr-store-running
@sleep infinity
@echo "!!! Processes may still be running, please run `make stop` in order to shutdown everything"
docker-run: ## 🐋 Run locally using containers and Docker compose
@./scripts/local-gateway/run.sh &
@docker compose -f ./build/compose.yaml up --remove-orphans
docker-build: ## 🔨 Build all containers using Docker compose
docker compose -f ./build/compose.yaml build
docker-push: ## 📤 Push all containers using Docker compose
docker compose -f ./build/compose.yaml push
docker-stop: ## 🚫 Stop and remove local containers
docker rm -f api-gateway || true
docker compose -f ./build/compose.yaml rm -f
stop: ## ⛔ Stop & kill everything started locally from `make run`
docker rm -f api-gateway || true
rm -f /tmp/dapr-store-running
dapr stop --app-id api-gateway
dapr stop --app-id cart
dapr stop --app-id products
dapr stop --app-id users
dapr stop --app-id orders
pkill cart; pkill users; pkill orders; pkill products; pkill main
api-spec: ## 📜 Generate OpenAPI spec & JSON schemas from TypeSpec
cd api/typespec; npm install --silent
rm -rf ./api/typespec/out
npx --package=@typespec/compiler tsp compile ./api/typespec/ --output-dir ./api/typespec/
mv ./api/typespec/out/* ./api/
# ===============================================================================
$(FRONTEND_DIR)/node_modules: $(FRONTEND_DIR)/package.json
cd $(FRONTEND_DIR); npm install --silent
touch -m $(FRONTEND_DIR)/node_modules
$(FRONTEND_DIR)/package.json:
@echo "package.json was modified"
# ===============================================================================
docker-build-cart:
docker compose -f ./build/compose.yaml build cart
docker-build-products:
docker compose -f ./build/compose.yaml build products
docker-build-users:
docker compose -f ./build/compose.yaml build users
docker-build-orders:
docker compose -f ./build/compose.yaml build orders
docker-build-frontend:
docker compose -f ./build/compose.yaml build frontend
# ===============================================================================
docker-push-cart:
docker compose -f ./build/compose.yaml push cart
docker-push-products:
docker compose -f ./build/compose.yaml push products
docker-push-users:
docker compose -f ./build/compose.yaml push users
docker-push-orders:
docker compose -f ./build/compose.yaml push orders
docker-push-frontend:
docker compose -f ./build/compose.yaml push frontend