Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (91 loc) · 6.9 KB
/
Copy pathMakefile
File metadata and controls
117 lines (91 loc) · 6.9 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
.PHONY: test build k3d-build-pull-image k3d-build-dev-image k3d-build-local-images build-docker build-dev-docker watch watch-windows test-integration test-integration-docker test-integration-kubernetes kind-integration-up kind-integration-down
VERSION ?= "dev"
DRUID_K8S_PULL_IMAGE ?= druid:local
DRUID_DEV_IMAGE ?= artifacts.druid.gg/druid-team/druid-dev:stable
K3D_CLUSTER ?= druid-gs
INTEGRATION_TIMEOUT ?= 1200s
KIND_CLUSTER ?= druid-cli-integration
KIND_VERSION ?= v0.27.0
GO_BIN ?= $(shell go env GOPATH)/bin
DRUID_K8S_NAMESPACE ?= druid
DRUID_WORKER_CALLBACK_LISTEN ?= 0.0.0.0:8083
DRUID_WORKER_CALLBACK_URL ?= http://host.docker.internal:8083
WSL_HOST_IP ?= $(word 1,$(shell hostname -I 2>/dev/null))
DRUID_WORKER_CALLBACK_URL_WINDOWS ?= http://$(WSL_HOST_IP):8083
DRUID_WATCH_ARGS ?= daemon --runtime kubernetes --listen 127.0.0.1:8081 --public-listen 127.0.0.1:8082 --worker-callback-listen $(DRUID_WORKER_CALLBACK_LISTEN) --worker-callback-url $(DRUID_WORKER_CALLBACK_URL) --unsafe-allow-unauthenticated-management --unsafe-allow-unauthenticated-public --k8s-namespace $(DRUID_K8S_NAMESPACE) --k8s-pull-image $(DRUID_K8S_PULL_IMAGE)
export DRUID_K8S_UI_S3_BUCKET ?= druid-ui
export DRUID_K8S_UI_S3_PUBLIC_BASE_URL ?= http://127.0.0.1:9000/druid-ui
export DRUID_K8S_UI_S3_REGION ?= us-east-1
export DRUID_K8S_UI_S3_ENDPOINT ?= http://host.docker.internal:9000
export DRUID_K8S_UI_S3_ACCESS_KEY ?= druid
export DRUID_K8S_UI_S3_SECRET_KEY ?= druidpassword
generate-api: ## Generate API types from OpenAPI spec
@echo "Generating API types from OpenAPI spec..."
@which oapi-codegen > /dev/null || (echo "Installing oapi-codegen..." && go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.5.1)
@PATH="$(shell go env GOPATH)/bin:$$PATH" oapi-codegen -config api/oapi-codegen.yaml api/openapi.yaml
@PATH="$(shell go env GOPATH)/bin:$$PATH" oapi-codegen -config api/dev-oapi-codegen.yaml api/dev.openapi.yaml
@PATH="$(shell go env GOPATH)/bin:$$PATH" oapi-codegen -config api/callback-oapi-codegen.yaml api/callback.openapi.yaml
validate-api: ## Validate OpenAPI spec
@echo "Validating OpenAPI spec..."
@which oapi-codegen > /dev/null || (echo "Installing oapi-codegen..." && go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.5.1)
@PATH="$(shell go env GOPATH)/bin:$$PATH" oapi-codegen -config api/oapi-codegen.yaml api/openapi.yaml > /dev/null
@PATH="$(shell go env GOPATH)/bin:$$PATH" oapi-codegen -config api/dev-oapi-codegen.yaml api/dev.openapi.yaml > /dev/null
@PATH="$(shell go env GOPATH)/bin:$$PATH" oapi-codegen -config api/callback-oapi-codegen.yaml api/callback.openapi.yaml > /dev/null
@echo "✓ OpenAPI spec is valid"
build: generate-api ## Build Druid and helper binaries
CGO_ENABLED=0 go build -ldflags "-X github.com/highcard-dev/daemon/internal.Version=$(VERSION)" -o ./bin/druid ./apps/druid
CGO_ENABLED=0 go build -ldflags "-X github.com/highcard-dev/daemon/internal.Version=$(VERSION)" -o ./bin/druid-coldstarter ./apps/druid-coldstarter
CGO_ENABLED=0 go build -ldflags "-X github.com/highcard-dev/daemon/internal.Version=$(VERSION)" -o ./bin/druid-dev ./apps/druid-dev
k3d-build-pull-image: ## Build the unified Druid runtime image and import it into local k3d.
docker build . -f Dockerfile --build-arg "VERSION=$(VERSION)" -t "$(DRUID_K8S_PULL_IMAGE)"
@docker rm -f "k3d-$(K3D_CLUSTER)-tools" >/dev/null 2>&1 || true
k3d image import "$(DRUID_K8S_PULL_IMAGE)" -c "$(K3D_CLUSTER)"
k3d-build-dev-image: ## Build the standalone dev image and import it into local k3d.
docker build . -f Dockerfile.dev --build-arg "VERSION=$(VERSION)" -t "$(DRUID_DEV_IMAGE)"
k3d image import "$(DRUID_DEV_IMAGE)" -c "$(K3D_CLUSTER)"
k3d-build-local-images: k3d-build-pull-image k3d-build-dev-image ## Build and import every Druid runtime image used locally.
build-docker:
docker build . -f Dockerfile --build-arg "VERSION=$(VERSION)" -t "$(DRUID_K8S_PULL_IMAGE)"
build-dev-docker:
docker build . -f Dockerfile.dev --build-arg "VERSION=$(VERSION)" -t "$(DRUID_DEV_IMAGE)"
build-x86-docker:
docker run -e GOOS=linux -e GOARCH=amd64 -it --rm -v ./:/app -w /app --entrypoint=/bin/bash docker.elastic.co/beats-dev/golang-crossbuild:1.22.5-main -c 'CGO_ENABLED=1 go build -ldflags "-X github.com/highcard-dev/daemon/internal.Version=$(VERSION)" -o ./bin/x86/druid'
install: build ## Build and install Druid binaries
install -m 0755 ./bin/druid /usr/local/bin/druid
install -m 0755 ./bin/druid-coldstarter /usr/local/bin/druid-coldstarter
install -m 0755 ./bin/druid-dev /usr/local/bin/druid-dev
generate-md-docs:
go run ./docs_md/main.go
run: ## Run Daemon
go run ./apps/druid
watch: k3d-build-local-images ## Build local runtime images, then run Daemon with auto reload.
@command -v air >/dev/null 2>&1 || go install github.com/air-verse/air@latest
air --build.cmd "CGO_ENABLED=0 go build -ldflags '-X github.com/highcard-dev/daemon/internal.Version=$(VERSION)' -o ./bin/druid ./apps/druid" --build.full_bin "DRUID_REGISTRY_PLAIN_HTTP=true ./bin/druid $(DRUID_WATCH_ARGS)"
watch-windows: ## Build local runtime images, then run the daemon with auto reload inside WSL2.
@grep -qi microsoft /proc/sys/kernel/osrelease 2>/dev/null || (echo "watch-windows must run inside WSL2; use make watch on Linux or macOS." >&2; exit 1)
@$(MAKE) watch DRUID_WORKER_CALLBACK_URL="$(DRUID_WORKER_CALLBACK_URL_WINDOWS)"
mock:
mockgen -source=internal/core/ports/services_ports.go -destination test/mock/services.go
test:
go test -v ./...
test-clean:
go clean -testcache
go test -v ./test
test-docker:
docker build . -f Dockerfile.testing -t druid-cli-test
docker run -v ./:/app --entrypoint=/bin/bash --rm druid-cli-test -c "go test -v ./..."
test-integration: test-integration-docker test-integration-kubernetes
test-integration-docker:
go test -count=1 -timeout $(INTEGRATION_TIMEOUT) -tags='integration docker' -v ./test/integration/docker
test-integration-kubernetes: kind-integration-up
go test -count=1 -timeout $(INTEGRATION_TIMEOUT) -tags='integration kubernetes' -v ./test/integration/kubernetes
kind-integration-up:
@command -v kind >/dev/null 2>&1 || (echo "Installing kind $(KIND_VERSION)..." && go install sigs.k8s.io/kind@$(KIND_VERSION))
@PATH="$(GO_BIN):$$PATH"; if ! kind get clusters | grep -qx "$(KIND_CLUSTER)"; then kind create cluster --name "$(KIND_CLUSTER)" --wait 120s; fi
@PATH="$(GO_BIN):$$PATH"; kind export kubeconfig --name "$(KIND_CLUSTER)" >/dev/null
@kubectl config use-context "kind-$(KIND_CLUSTER)" >/dev/null
kind-integration-down:
@PATH="$(GO_BIN):$$PATH"; kind delete cluster --name "$(KIND_CLUSTER)"
test-integration-docker-debug:
docker build . -f Dockerfile.testing -t druid-cli-test
docker run -v ./:/app -v /var/run/docker.sock:/var/run/docker.sock --entrypoint=/bin/bash --rm -p 2345:2345 -it druid-cli-test -c "dlv --listen=:2345 --headless=true --log=true --log-output=debugger,debuglineerr,gdbwire,lldbout,rpc --accept-multiclient --api-version=2 test --build-flags='-tags=integration docker' ./test/integration/docker"