-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
181 lines (165 loc) · 7.65 KB
/
Copy pathMakefile
File metadata and controls
181 lines (165 loc) · 7.65 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
.DEFAULT_GOAL:=help
#============================================================================
# Load environment variables for local development
include .env
export
# Integration test configuration
# - From host: make integration-test (uses localhost:8080)
# - In container: make integration-test API_GATEWAY_URL=api-gateway:8080 DB_HOST=pg_sql
API_GATEWAY_PROTOCOL ?= http
API_GATEWAY_URL ?= localhost:8080
DB_HOST ?= localhost
#============================================================================
.PHONY: dev
dev: ## Run dev container
@docker compose ls -q | grep -q "instill-core" && true || \
(echo "Error: Run \"make latest\" in instill-core repository (https://github.com/instill-ai/instill-core) in your local machine first and run \"docker rm -f ${SERVICE_NAME} ${SERVICE_NAME}-worker\"." && 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} \
--network instill-network \
--name ${SERVICE_NAME} \
instill/${SERVICE_NAME}:dev
.PHONY: latest
latest: ## Run latest container
@docker compose ls -q | grep -q "instill-core" && true || \
(echo "Error: Run \"make latest\" in instill-core repository (https://github.com/instill-ai/instill-core) in your local machine first and run \"docker rm -f ${SERVICE_NAME} ${SERVICE_NAME}-worker\"." && 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} \
-p ${PUBLIC_SERVICE_PORT}:${PUBLIC_SERVICE_PORT} \
-p ${PRIVATE_SERVICE_PORT}:${PRIVATE_SERVICE_PORT} \
-d instill/${SERVICE_NAME}:latest \
/bin/sh -c "\
./${SERVICE_NAME}-migrate && \
./${SERVICE_NAME}-init && \
./${SERVICE_NAME} \
"
@docker run --network=instill-network \
--name ${SERVICE_NAME}-worker \
-d instill/${SERVICE_NAME}:latest ./${SERVICE_NAME}-worker
.PHONY: logs
logs: ## Tail container logs with -n 10
@docker logs ${SERVICE_NAME} --follow --tail=10
.PHONY: stop
stop: ## Stop all running containers
@docker stop -t 1 ${SERVICE_NAME} ${SERVICE_NAME}-worker 2>/dev/null || true
.PHONY: rm
rm: ## Remove all running containers
@docker rm -f ${SERVICE_NAME} ${SERVICE_NAME}-worker >/dev/null 2>&1
.PHONY: top
top: ## Display all running service processes
@docker top ${SERVICE_NAME}
.PHONY: build-dev
build-dev: ## Build dev docker image
@docker build \
--build-arg SERVICE_NAME=${SERVICE_NAME} \
--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 SERVICE_NAME=${SERVICE_NAME} \
--build-arg SERVICE_VERSION=dev \
-t instill/${SERVICE_NAME}:latest .
.PHONY: go-gen
go-gen: ## Generate codes
go generate ./...
.PHONY: unit-test
unit-test: ## Run unit test
@go test -v -race -coverpkg=./... -coverprofile=coverage.out ./...
@cat coverage.out | grep -v "mock" > coverage.final.out
@go tool cover -func=coverage.final.out
@go tool cover -html=coverage.final.out
@rm coverage.out coverage.final.out
.PHONY: integration-test
integration-test: ## Run integration tests (parallel by default, sequential if CI=true)
@echo "✓ Running tests via API Gateway: ${API_GATEWAY_URL}"
@echo " DB_HOST: ${DB_HOST}"
ifeq ($(CI),true)
@echo "Running integration tests sequentially (CI mode)..."
@rm -f /tmp/artifact-integration-test.log
@bash -c 'set -o pipefail; \
for test in \
integration-test/rest.js \
integration-test/rest-object-storage.js \
integration-test/rest-hash-based-ids.js \
integration-test/rest-invariants.js \
integration-test/rest-file-type.js \
integration-test/rest-db.js \
integration-test/rest-ai-client.js \
integration-test/rest-kb-e2e-file-process.js \
integration-test/rest-file-reprocess.js \
integration-test/rest-kb-delete.js \
integration-test/rest-file-dedup.js \
integration-test/rest-namespace-permission.js \
integration-test/grpc.js \
integration-test/grpc-kb-update.js \
integration-test/grpc-system-config-update.js \
integration-test/grpc-system-admin.js; do \
echo "Running $$test..." | tee -a /tmp/artifact-integration-test.log; \
TEST_FOLDER_ABS_PATH=$(PWD) k6 run --address="" \
-e CI=true \
-e API_GATEWAY_PROTOCOL=$(API_GATEWAY_PROTOCOL) \
-e API_GATEWAY_URL=$(API_GATEWAY_URL) \
-e DB_HOST=$(DB_HOST) \
$$test --no-usage-report 2>&1 | tee -a /tmp/artifact-integration-test.log; \
if [ $${PIPESTATUS[0]} -ne 0 ]; then exit 1; fi; \
done'
@bash integration-test/scripts/report-summary.sh /tmp/artifact-integration-test.log
else
@echo "Running integration tests in parallel..."
@rm -f /tmp/artifact-integration-test.log
# Batch 1: Core REST tests + grpc.js (isolated from other gRPC tests to avoid conflicts)
@parallel --halt now,fail=1 --tag --line-buffer \
"TEST_FOLDER_ABS_PATH=${PWD} k6 run --address=\"\" \
-e API_GATEWAY_PROTOCOL=${API_GATEWAY_PROTOCOL} -e API_GATEWAY_URL=${API_GATEWAY_URL} \
-e DB_HOST=${DB_HOST} \
{} --no-usage-report" ::: \
integration-test/rest.js \
integration-test/rest-object-storage.js \
integration-test/rest-hash-based-ids.js \
integration-test/rest-invariants.js \
integration-test/rest-file-dedup.js 2>&1 | tee -a /tmp/artifact-integration-test.log
# Batch 2: File processing tests (heavy AI workload)
@parallel --halt now,fail=1 --tag --line-buffer \
"TEST_FOLDER_ABS_PATH=${PWD} k6 run --address=\"\" \
-e API_GATEWAY_PROTOCOL=${API_GATEWAY_PROTOCOL} -e API_GATEWAY_URL=${API_GATEWAY_URL} \
-e DB_HOST=${DB_HOST} \
{} --no-usage-report" ::: \
integration-test/rest-namespace-permission.js \
integration-test/rest-file-type.js \
integration-test/rest-db.js \
integration-test/rest-ai-client.js 2>&1 | tee -a /tmp/artifact-integration-test.log
# Batch 3: E2E and KB management tests
@parallel --halt now,fail=1 --tag --line-buffer \
"TEST_FOLDER_ABS_PATH=${PWD} k6 run --address=\"\" \
-e API_GATEWAY_PROTOCOL=${API_GATEWAY_PROTOCOL} -e API_GATEWAY_URL=${API_GATEWAY_URL} \
-e DB_HOST=${DB_HOST} \
{} --no-usage-report" ::: \
integration-test/rest-kb-e2e-file-process.js \
integration-test/rest-file-reprocess.js \
integration-test/rest-kb-delete.js 2>&1 | tee -a /tmp/artifact-integration-test.log
# Batch 4: gRPC system tests (may modify system config, run separately from grpc.js)
@parallel --halt now,fail=1 --tag --line-buffer \
"TEST_FOLDER_ABS_PATH=${PWD} k6 run --address=\"\" \
-e API_GATEWAY_PROTOCOL=${API_GATEWAY_PROTOCOL} -e API_GATEWAY_URL=${API_GATEWAY_URL} \
-e DB_HOST=${DB_HOST} \
{} --no-usage-report" ::: \
integration-test/grpc.js \
integration-test/grpc-kb-update.js \
integration-test/grpc-system-config-update.js \
integration-test/grpc-system-admin.js 2>&1 | tee -a /tmp/artifact-integration-test.log
@bash integration-test/scripts/report-summary.sh /tmp/artifact-integration-test.log
endif
.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)