-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
146 lines (130 loc) · 5.52 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
146
.DEFAULT_GOAL:=help
#============================================================================
# Load environment variables for local development
include .env
export
GOTEST_FLAGS := CFG_DATABASE_HOST=${TEST_DBHOST} CFG_DATABASE_NAME=${TEST_DBNAME}
#============================================================================
.PHONY: dev
dev: ## Run dev container
@docker compose ls -q | grep -q "instill-core" && true || \
(echo "Error: Run \"make latest PROFILE=exclude-pipeline\" in vdp repository (https://github.com/instill-ai/instill-core) in your local machine first." && exit 1)
@docker inspect --type container ${SERVICE_NAME} >/dev/null 2>&1 && echo "A container named ${SERVICE_NAME} is already running." || \
echo "Run dev container ${SERVICE_NAME}. To stop it, run \"make stop\"."
@docker run -d --rm \
-v $(PWD):/${SERVICE_NAME} \
-p ${PUBLIC_SERVICE_PORT}:${PUBLIC_SERVICE_PORT} \
-p ${PRIVATE_SERVICE_PORT}:${PRIVATE_SERVICE_PORT} \
--env-file .env.component \
--network instill-network \
--name ${SERVICE_NAME} \
instill/${SERVICE_NAME}:dev >/dev/null 2>&1
.PHONY: latest
latest: ## Run latest container
@docker compose ls -q | grep -q "instill-core" && true || \
(echo "Error: Run \"make latest PROFILE=exclude-pipeline\" in vdp repository (https://github.com/instill-ai/instill-core) in your local machine first." && exit 1)
@docker inspect --type container ${SERVICE_NAME} >/dev/null 2>&1 && echo "A container named ${SERVICE_NAME} is already running." || \
echo "Run latest container ${SERVICE_NAME} and ${SERVICE_NAME}-worker. To stop it, run \"make stop\"."
@docker run --network=instill-network \
--name ${SERVICE_NAME} \
-d instill/${SERVICE_NAME}:latest ./${SERVICE_NAME}
@docker run --network=instill-network \
--name ${SERVICE_NAME}-worker \
-d instill/${SERVICE_NAME}:latest ./${SERVICE_NAME}-worker
.PHONY: rm
rm: ## Remove all running containers
@docker rm -f ${SERVICE_NAME} ${SERVICE_NAME}-worker >/dev/null 2>&1
.PHONY: build-dev
build-dev: ## Build dev docker image
@docker build \
--build-arg SERVICE_NAME=${SERVICE_NAME} \
--build-arg GOLANG_VERSION=${GOLANG_VERSION} \
--build-arg K6_VERSION=${K6_VERSION} \
--build-arg XK6_VERSION=${XK6_VERSION} \
--build-arg XK6_SQL_VERSION=${XK6_SQL_VERSION} \
--build-arg XK6_SQL_POSTGRES_VERSION=${XK6_SQL_POSTGRES_VERSION} \
-f Dockerfile.dev -t instill/${SERVICE_NAME}:dev .
.PHONY: build-latest
build-latest: ## Build latest docker image
@docker build \
--build-arg GOLANG_VERSION=${GOLANG_VERSION} \
--build-arg SERVICE_NAME=${SERVICE_NAME} \
-t instill/pipeline-backend:latest .
.PHONY: go-gen
go-gen: ## Generate codes
go generate ./...
.PHONY: dbtest-pre
dbtest-pre:
@${GOTEST_FLAGS} go run ./cmd/migration
.PHONY: coverage
coverage: ## Generate coverage report
@if [ "${DBTEST}" = "true" ]; then make dbtest-pre; fi
@docker run --rm \
-v $(PWD):/${SERVICE_NAME} \
-e GOTEST_FLAGS="${GOTEST_FLAGS}" \
--user $(id -u):$(id -g) \
--entrypoint= \
instill/${SERVICE_NAME}:dev \
go test -v -race ${GOTEST_TAGS} -coverpkg=./... -coverprofile=coverage.out -covermode=atomic -timeout 30m ./...
@if [ "${HTML}" = "true" ]; then \
docker run --rm \
-v $(PWD):/${SERVICE_NAME} \
--user $(id -u):$(id -g) \
--entrypoint= \
instill/${SERVICE_NAME}:dev \
go tool cover -func=coverage.out && \
go tool cover -html=coverage.out && \
rm coverage.out; \
fi
# Tests should run in container without local tparse installation.
# If you encounter container test issues, install tparse locally:
# go install github.com/mfridman/tparse/cmd/tparse@latest
.PHONY: test
test: ## Run unit test
@TAGS=""; \
if [ "$${OCR}" = "true" ]; then \
TAGS="$$TAGS,ocr"; \
[ "$$(uname)" = "Darwin" ] && export TESSDATA_PREFIX=$$(dirname $$(brew list tesseract | grep share/tessdata/eng.traineddata)); \
fi; \
if [ "$${ONNX}" = "true" ]; then \
if [ "$$(uname)" = "Darwin" ]; then \
echo "ONNX Runtime test is not supported on Darwin (macOS)."; \
else \
TAGS="$$TAGS,onnx"; \
fi; \
fi; \
TAGS=$${TAGS#,}; \
if [ -n "$$TAGS" ]; then \
echo "Running tests with tags: $$TAGS"; \
go test -v -tags="$$TAGS" ./... -json | tparse --notests --all; \
else \
echo "Running standard tests"; \
go test -v ./... -json | tparse --notests --all; \
fi
.PHONY: integration-test
integration-test: ## Run integration test
@ # DB_HOST points to localhost by default. Override this variable if
@ # pipeline-backend's database isn't accessible at that host.
@TEST_FOLDER_ABS_PATH=${PWD} k6 run \
-e API_GATEWAY_PROTOCOL=${API_GATEWAY_PROTOCOL} \
-e API_GATEWAY_URL=${API_GATEWAY_URL} \
-e DB_HOST=${DB_HOST} \
integration-test/pipeline/grpc.js --no-usage-report --quiet
@TEST_FOLDER_ABS_PATH=${PWD} k6 run \
-e API_GATEWAY_PROTOCOL=${API_GATEWAY_PROTOCOL} \
-e API_GATEWAY_URL=${API_GATEWAY_URL} \
-e DB_HOST=${DB_HOST} \
integration-test/pipeline/rest.js --no-usage-report --quiet
.PHONY: gen-mock
gen-mock: ## Generate mock files
@go install github.com/gojuno/minimock/v3/cmd/[email protected]
@go generate -run minimock ./...
.PHONY: gen-component-doc
gen-component-doc: ## Generate component docs
@rm -f $$(find ./pkg/component -name README.mdx | paste -d ' ' -s -)
@cd ./pkg/component/tools/compogen && go install .
@go generate -run compogen ./pkg/component/...
.PHONY: help
help: ## Show this help
@echo "\nMakefile for local development"
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m (default: help)\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)