Files
gateway/Makefile
zooqueen 15bd5d1d0d fix(edge): build the KrakenD HTTP edge (tags=legacy) so /v1/* serves, not 404
The v2.14.x HIP-0110 rearchitecture (#17, ZAP relay #649ff8b) flipped the
default `make build` output to cmd/gateway/main.go — the pure ZAP->ZAP
relay. That binary's BuildApp serves ONLY /healthz+/readyz on :8080 and
expects all client traffic over ZAP to cloud:9090 + base:9091. But those
ZAP peers don't exist (cloud:9090 is cloud's health/metrics listener, the
base service is absent), and the Dockerfile CMD still drives the KrakenD
`run -c gateway.json` path — which the relay-only binary ignores. Net:
api.hanzo.ai 404s every model call (/v1/chat/completions, /v1/models, ...).

2.14.1 worked because it predates the build-tag split: `make build` then
produced the single KrakenD main that `run -c` drives -> NewEngine ->
hostProxyMiddleware -> HTTP passthrough of api.hanzo.ai /v1/* straight to
cloud-api.hanzo.svc.cluster.local:8000 (the HIP-0106 cloud binary). That
HTTP relay target already lives in router_engine.go; it just wasn't being
built/run.

Forward fix (no revert to a stale lineage):
- Makefile: BUILD_TAGS ?= legacy so `make build` (and thus the Dockerfile)
  produces the KrakenD edge binary that the `run -c` CMD drives. This
  mounts the proven HTTP completions path AND corsPreflightMiddleware
  (the *.hanzo.ai CORS allowlist from #29). The ZAP relay (build_app.go)
  stays available behind the default build for HIP-0110 Phase C, but is
  not required for HTTP serving today.
- router_engine.go: make the cloud-api target overridable via
  GATEWAY_CLOUD_API_URL (operator + test), with a safe fallback so a
  malformed override can never silently break routing.
- router_engine_routing_test.go: regression guard — every
  apiHanzoAIEndpoints prefix on api.hanzo.ai proxies to cloud-api (200,
  path unchanged), never 404; non-api hosts are not hijacked; the env
  override resolves/falls back correctly.

Verified locally: `gateway run -c gateway.json` with GATEWAY_CLOUD_API_URL
-> stub returns /healthz 200, POST /v1/chat/completions 200 (proxied to
stub, not 404), OPTIONS preflight from https://cowork.hanzo.ai -> 204 with
Access-Control-Allow-Origin.
2026-06-19 23:39:13 -07:00

146 lines
6.1 KiB
Makefile

.PHONY: all build test help deploy deploy-hanzo deploy-lux apply-hanzo apply-lux validate status clean docker
BIN_NAME := gateway
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
MODULE := github.com/hanzoai/gateway
VERSION := 2.13.0
SCHEMA_VERSION := $(shell echo "${VERSION}" | cut -d '.' -f 1,2)
GIT_COMMIT = $(shell git rev-parse --short=7 HEAD 2>/dev/null)
GOLANG_VERSION := 1.26.3
ALPINE_VERSION := 3.23
GLIBC_VERSION := $(shell sh find_glibc.sh 2>/dev/null || echo "unknown")
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
## Build
all: test
# BUILD_TAGS selects the gateway entrypoint. The production HTTP edge runs
# the KrakenD `run -c gateway.json` path (cmd/gateway/main_legacy.go, tag
# `legacy`) which mounts NewEngine -> hostProxyMiddleware (the proven HTTP
# relay of api.hanzo.ai /v1/* straight to cloud-api:8000) + the CORS
# preflight allowlist. The default (untagged) main.go is the HIP-0110
# pure ZAP->ZAP relay; it serves ONLY /healthz on :8080 and 404s every
# model call when the ZAP backends are absent (they are: cloud:9090 is
# cloud's health listener, the base service does not exist). Until the
# ZAP relay backends are live (HIP-0110 Phase C), the edge MUST be the
# `legacy` build — that is what the Dockerfile CMD (`run -c ...`) drives.
BUILD_TAGS ?= legacy
build: cmd/gateway/schema/schema.json ## Build the gateway binary (KrakenD HTTP edge; BUILD_TAGS=legacy)
@echo "Building the gateway binary (tags: ${BUILD_TAGS})..."
@go build -mod=mod -tags "${BUILD_TAGS}" -ldflags="-X ${MODULE}/pkg.Version=${VERSION} -X github.com/luraproject/lura/v2/core.KrakendVersion=${VERSION} \
-X github.com/luraproject/lura/v2/core.GlibcVersion=${GLIBC_VERSION}" \
-o ${BIN_NAME} ./cmd/gateway
@echo "You can now use ./${BIN_NAME}"
build-ingress: ## Build the ingress binary
@echo "Building the ingress binary..."
@CGO_ENABLED=0 go build -ldflags="-w -s -X main.version=${VERSION}" -o ingress ./cmd/ingress
@echo "You can now use ./ingress"
test: build ## Build and run tests
go test -v ./tests
cmd/gateway/schema/schema.json:
@echo "Fetching v${SCHEMA_VERSION} schema"
@wget -qO $@.orig https://raw.githubusercontent.com/krakend/krakend-schema/refs/heads/main/v${SCHEMA_VERSION}/krakend.json || wget -qO $@.orig https://krakend.io/schema/krakend.json
@echo "Rebranding embedded schema descriptions and URLs"
@sed \
-e 's|https://www.krakend.io|https://gateway.hanzo.ai|g' \
-e 's|https://krakend.io|https://gateway.hanzo.ai|g' \
-e 's|www.krakend.io|gateway.hanzo.ai|g' \
-e 's|krakend.io|gateway.hanzo.ai|g' \
-e 's|KrakenD Enterprise|Hanzo Gateway Enterprise|g' \
-e 's|KrakenD|Gateway|g' \
-e 's|Krakend|Gateway|g' \
-e 's|KRAKEND|GATEWAY|g' \
-e 's|krakend|gateway|g' \
$@.orig > $@
@rm -f $@.orig
REGISTRY := ghcr.io/hanzoai/gateway
docker: ## Build Docker image
docker build --no-cache --pull --build-arg GOLANG_VERSION=${GOLANG_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} \
-t ${REGISTRY}:${VERSION} -t ${REGISTRY}:latest .
docker-hanzo: ## Build hanzo config Docker image
docker build --build-arg CONFIG=hanzo \
-t ${REGISTRY}:latest \
-t ${REGISTRY}:v${VERSION} \
-t ${REGISTRY}:v${VERSION}-${GIT_COMMIT} .
docker-lux: ## Build lux config Docker image
docker build --build-arg CONFIG=lux \
-t ${REGISTRY}:lux-latest \
-t ${REGISTRY}:lux-v${VERSION} .
docker-push: ## Push all tags to registry
docker push ${REGISTRY} --all-tags
docker-push-hanzo: docker-hanzo ## Build and push hanzo gateway
docker push ${REGISTRY}:latest
docker push ${REGISTRY}:v${VERSION}
docker push ${REGISTRY}:v${VERSION}-${GIT_COMMIT}
## Validation
validate: ## Validate all configs
./$(BIN_NAME) check -c configs/hanzo/gateway.json
./$(BIN_NAME) check -c configs/lux/gateway.json
## Hanzo cluster (hanzo-k8s)
apply-hanzo: ## Apply hanzo gateway config to k8s
kubectl --context do-sfo3-hanzo-k8s -n hanzo create configmap gateway-config --from-file=gateway.json=configs/hanzo/gateway.json --dry-run=client -o yaml | kubectl --context do-sfo3-hanzo-k8s apply -f -
kubectl --context do-sfo3-hanzo-k8s apply -f k8s/hanzo/
kubectl --context do-sfo3-hanzo-k8s -n hanzo rollout restart deployment gateway
apply-ingress-hanzo: ## Apply hanzo ingress to k8s
kubectl --context do-sfo3-hanzo-k8s -n hanzo create configmap ingress-config --from-file=ingress.json=configs/hanzo/ingress.json --dry-run=client -o yaml | kubectl --context do-sfo3-hanzo-k8s apply -f -
kubectl --context do-sfo3-hanzo-k8s apply -f k8s/hanzo-ingress/
kubectl --context do-sfo3-hanzo-k8s -n hanzo rollout restart deployment hanzo-ingress
deploy-ingress-hanzo: apply-ingress-hanzo ## Deploy hanzo ingress (alias)
deploy-hanzo: apply-hanzo ## Deploy hanzo gateway (alias for apply-hanzo)
## Lux cluster (lux-k8s)
apply-lux: ## Apply lux gateway config to k8s
kubectl --context do-sfo3-lux-k8s -n lux-gateway create configmap gateway-config --from-file=gateway.json=configs/lux/gateway.json --dry-run=client -o yaml | kubectl --context do-sfo3-lux-k8s apply -f -
kubectl --context do-sfo3-lux-k8s apply -f k8s/lux/
kubectl --context do-sfo3-lux-k8s -n lux-gateway rollout restart deployment gateway
deploy-lux: apply-lux ## Deploy lux gateway (alias for apply-lux)
## Deploy all
deploy: deploy-hanzo deploy-lux ## Deploy to both clusters
## Status
status: ## Show gateway status on both clusters
@echo "=== Hanzo Gateway ==="
kubectl --context do-sfo3-hanzo-k8s -n hanzo get deployment gateway
kubectl --context do-sfo3-hanzo-k8s -n hanzo get pods -l app=gateway
@echo ""
@echo "=== Lux Gateway ==="
kubectl --context do-sfo3-lux-k8s -n lux-gateway get deployment gateway
kubectl --context do-sfo3-lux-k8s -n lux-gateway get pods -l app=gateway
logs-hanzo: ## Tail hanzo gateway logs
kubectl --context do-sfo3-hanzo-k8s -n hanzo logs -l app=gateway -f --tail=50
logs-lux: ## Tail lux gateway logs
kubectl --context do-sfo3-lux-k8s -n lux-gateway logs -l app=gateway -f --tail=50
clean: ## Clean build artifacts
rm -rf builder/skel/*
rm -f ${BIN_NAME}
rm -rf vendor/
rm -f cmd/gateway/schema/schema.json