-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMakefile
More file actions
163 lines (138 loc) · 4.34 KB
/
Copy pathMakefile
File metadata and controls
163 lines (138 loc) · 4.34 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
.PHONY: build run clean test docker-build docker-run docker-stop help
# Variables
SERVICE_NAME := go-convert-service
DOCKER_IMAGE := $(SERVICE_NAME):latest
PORT ?= 8090
LOG_LEVEL ?= debug
MAX_BATCH_SIZE ?= 100
MAX_YAML_BYTES ?= 5242880
# Default target
.DEFAULT_GOAL := help
## help: Display this help message
help:
@echo "Available targets:"
@echo ""
@grep -E '^##' $(MAKEFILE_LIST) | sed 's/## / /'
@echo ""
## build: Build the service binary
build:
@echo "Building $(SERVICE_NAME)..."
@go build -o $(SERVICE_NAME) ./cmd/server
@echo "Build complete: $(SERVICE_NAME)"
## run: Build and run the service locally
run: build
@echo "Starting $(SERVICE_NAME) on port $(PORT)..."
@PORT=$(PORT) \
LOG_LEVEL=$(LOG_LEVEL) \
MAX_BATCH_SIZE=$(MAX_BATCH_SIZE) \
MAX_YAML_BYTES=$(MAX_YAML_BYTES) \
./$(SERVICE_NAME)
## run-debug: Run the service with debug logging
run-debug:
@$(MAKE) run LOG_LEVEL=debug
## run-info: Run the service with info logging
run-info:
@$(MAKE) run LOG_LEVEL=info
## test: Run all tests
test:
@echo "Running tests..."
@go test -v ./service/... ./cmd/...
## test-coverage: Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
@go test -v -coverprofile=coverage.out ./service/... ./cmd/...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
## clean: Remove build artifacts
clean:
@echo "Cleaning up..."
@rm -f $(SERVICE_NAME)
@rm -f coverage.out coverage.html
@echo "Clean complete"
## docker-build: Build Docker image
docker-build:
@echo "Building Docker image: $(DOCKER_IMAGE)..."
@docker build -f Dockerfile.service -t $(DOCKER_IMAGE) .
@echo "Docker image built: $(DOCKER_IMAGE)"
## docker-run: Run service in Docker container
docker-run: docker-build
@echo "Running Docker container on port $(PORT)..."
@docker run -d \
--name $(SERVICE_NAME) \
-p $(PORT):8090 \
-e LOG_LEVEL=$(LOG_LEVEL) \
-e MAX_BATCH_SIZE=$(MAX_BATCH_SIZE) \
-e MAX_YAML_BYTES=$(MAX_YAML_BYTES) \
$(DOCKER_IMAGE)
@echo "Container started. Check logs with: make docker-logs"
## docker-run-foreground: Run service in Docker container (foreground)
docker-run-foreground: docker-build
@echo "Running Docker container on port $(PORT)..."
@docker run --rm \
--name $(SERVICE_NAME) \
-p $(PORT):8090 \
-e LOG_LEVEL=$(LOG_LEVEL) \
-e MAX_BATCH_SIZE=$(MAX_BATCH_SIZE) \
-e MAX_YAML_BYTES=$(MAX_YAML_BYTES) \
$(DOCKER_IMAGE)
## docker-stop: Stop and remove Docker container
docker-stop:
@echo "Stopping Docker container..."
@docker stop $(SERVICE_NAME) || true
@docker rm $(SERVICE_NAME) || true
@echo "Container stopped and removed"
## docker-logs: Show Docker container logs
docker-logs:
@docker logs -f $(SERVICE_NAME)
## docker-shell: Open shell in running container
docker-shell:
@docker exec -it $(SERVICE_NAME) /bin/sh
## health-check: Check if service is running
health-check:
@echo "Checking service health..."
@curl -s http://localhost:$(PORT)/healthz || echo "Service not responding"
## example-request: Send example batch request
example-request:
@echo "Sending example batch request..."
@curl -X POST http://localhost:$(PORT)/api/v1/convert/batch \
-H "Content-Type: application/json" \
-d @test_batch_request.json | jq
## dev: Run in development mode with live reload (requires air)
dev:
@if command -v air > /dev/null; then \
air; \
else \
echo "air not installed. Install with: go install github.com/air-verse/air@latest"; \
echo "Falling back to normal run..."; \
$(MAKE) run-debug; \
fi
## install-tools: Install development tools
install-tools:
@echo "Installing development tools..."
@go install github.com/air-verse/air@latest
@echo "Tools installed"
## mod-download: Download Go module dependencies
mod-download:
@echo "Downloading dependencies..."
@go mod download
@echo "Dependencies downloaded"
## mod-tidy: Tidy Go module dependencies
mod-tidy:
@echo "Tidying dependencies..."
@go mod tidy
@echo "Dependencies tidied"
## fmt: Format Go code
fmt:
@echo "Formatting code..."
@go fmt ./...
@echo "Code formatted"
## lint: Run linters (requires golangci-lint)
lint:
@if command -v golangci-lint > /dev/null; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Install from: https://golangci-lint.run/"; \
fi
## all: Build, test, and create Docker image
all: clean test build docker-build
@echo "All tasks complete"