forked from hashicorp/terraform-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
119 lines (95 loc) · 4.61 KB
/
Makefile
File metadata and controls
119 lines (95 loc) · 4.61 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
SHELL := /usr/bin/env bash -euo pipefail -c
BINARY_NAME ?= terraform-mcp-server
VERSION ?= $(if $(shell printenv VERSION),$(shell printenv VERSION),dev)
GO=go
DOCKER=docker
TARGET_DIR ?= $(CURDIR)/dist
# Build flags
LDFLAGS=-ldflags="-s -w -X terraform-mcp-server/version.GitCommit=$(shell git rev-parse HEAD) -X terraform-mcp-server/version.BuildDate=$(shell git show --no-show-signature -s --format=%cd --date=format:"%Y-%m-%dT%H:%M:%SZ" HEAD)"
.PHONY: all build crt-build test test-e2e test-security clean deps docker-build run-http run-http-secure docker-run-http test-http cleanup-test-containers update-server-json-version help
# Default target
all: build
# Build the binary
# Get local ARCH; on Intel Mac, 'uname -m' returns x86_64 which we turn into amd64.
# Not using 'go env GOOS/GOARCH' here so 'make docker' will work without local Go install.
# Always use CGO_ENABLED=0 to ensure a statically linked binary is built
ARCH = $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A)
OS = $(shell uname | tr [[:upper:]] [[:lower:]])
build:
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=$(OS) $(GO) build $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/terraform-mcp-server
crt-build:
@mkdir -p $(TARGET_DIR)
@$(CURDIR)/scripts/crt-build.sh build
@cp $(CURDIR)/LICENSE $(TARGET_DIR)/LICENSE.txt
# Run tests
test:
$(GO) test -v ./...
# Run e2e tests
test-e2e:
@trap '$(MAKE) cleanup-test-containers' EXIT; $(GO) test -v --tags e2e ./e2e
# Clean build artifacts
clean:
rm -f $(BINARY_NAME)
$(GO) clean
# Download dependencies
deps:
$(GO) mod download
# Build docker image
docker-build:
$(DOCKER) build --build-arg VERSION=$(VERSION) -t $(BINARY_NAME):$(VERSION) .
# Run HTTP server locally
run-http:
bin/$(BINARY_NAME) http --transport-port 8080 --transport-host 0.0.0.0
# Run HTTP server with security settings
run-http-secure:
MCP_ALLOWED_ORIGINS="http://localhost:3000,https://example.com" MCP_CORS_MODE="development" bin/$(BINARY_NAME) http --transport-port 8080 --transport-host 0.0.0.0
# Run HTTP server in Docker
docker-run-http:
$(DOCKER) run -p 8080:8080 --rm $(BINARY_NAME):$(VERSION) http --transport-port 8080 --transport-host 0.0.0.0
# Synchronise server.json version fields with version/VERSION
update-json-version:
@VERSION_FILE="$(CURDIR)/version/VERSION"; \
SERVER_JSON="$(CURDIR)/server.json"; \
"$(CURDIR)/scripts/update-json-version.sh" "$$SERVER_JSON" "$$VERSION_FILE"
# Synchronise gemini-extension.json version fields with version/VERSION
update-gemini-version:
@VERSION_FILE="$(CURDIR)/version/VERSION"; \
SERVER_JSON="$(CURDIR)/gemini-extension.json"; \
"$(CURDIR)/scripts/update-json-version.sh" "$$SERVER_JSON" "$$VERSION_FILE"
# Test HTTP endpoint
test-http:
@echo "Testing StreamableHTTP server health endpoint..."
@curl -f http://localhost:8080/health || echo "Health check failed - make sure server is running with 'make run-http'"
@echo "StreamableHTTP MCP endpoint available at: http://localhost:8080/mcp"
# Run security tests
test-security:
$(GO) test ./cmd/terraform-mcp-server -v -run "TestIs|TestLoad|TestSecurity|TestOptions"
# Run docker container
# docker-run:
# $(DOCKER) run -it --rm $(BINARY_NAME):$(VERSION)
# Clean up test containers
cleanup-test-containers:
@echo "Cleaning up test containers..."
@$(DOCKER) ps -q --filter "ancestor=$(BINARY_NAME):test-e2e" | xargs -r $(DOCKER) stop
@$(DOCKER) ps -aq --filter "ancestor=$(BINARY_NAME):test-e2e" | xargs -r $(DOCKER) rm
@echo "Test container cleanup complete"
# Show help
help:
@echo "Available targets:"
@echo " all - Build the binary (default)"
@echo " build - Build the binary"
@echo " crt-build - Build using crt-build script"
@echo " test - Run all tests"
@echo " test-e2e - Run end-to-end tests"
@echo " test-security - Run security-related tests"
@echo " test-http - Test StreamableHTTP health endpoint"
@echo " clean - Remove build artifacts"
@echo " deps - Download dependencies"
@echo " docker-build - Build docker image"
@echo " run-http - Run StreamableHTTP server locally on port 8080"
@echo " run-http-secure - Run StreamableHTTP server with security settings"
@echo " docker-run-http - Run StreamableHTTP server in Docker on port 8080"
@echo " update-json-version - Update server.json to match version/VERSION"
@echo " update-gemini-version - Update gemini-extension.json to match version/VERSION"
@echo " cleanup-test-containers - Stop and remove all test containers"
@echo " help - Show this help message"