-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
191 lines (165 loc) · 6.53 KB
/
Makefile
File metadata and controls
191 lines (165 loc) · 6.53 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
182
183
184
185
186
187
188
189
190
# Makefile for building the rhobs-synthetics-agent binary
# Replace 'your-quay-namespace' with your actual Quay.io namespace.
IMAGE_URL ?= quay.io/app-sre/rhobs/rhobs-synthetics-agent
# Image tag, defaults to 'latest'
TAG ?= latest
# Namespace where the resources will be deployed
NAMESPACE ?= rhobs
# Konflux manifests directory
KONFLUX_DIR := konflux
# The name of the binary to be built
BINARY_NAME=rhobs-synthetics-agent
# The main package of the application
MAIN_PACKAGE=./cmd/agent/main.go
# podman vs. docker
CONTAINER_ENGINE ?= podman
TESTOPTS ?= -cover
.PHONY: all build clean run help lint lint-fix lint-ci go-mod-tidy go-mod-download test test-race test-integration test-e2e test-e2e-real test-e2e-all coverage docker-build docker-push example-config
all: build
# Build the Go binary
build:
@echo "Building $(BINARY_NAME)..."
@go build -o $(BINARY_NAME) $(MAIN_PACKAGE)
@echo "$(BINARY_NAME) built successfully."
# Golangci-lint setup similar to API project
GOLANGCI_LINT_VERSION ?= v2.0.2
GOLANGCI_LINT_BIN := $(shell go env GOPATH)/bin/golangci-lint
lint: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run ./...
lint-ci: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run ./... --output.text.path=stdout --timeout=5m
lint-fix: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run --fix ./...
$(GOLANGCI_LINT_BIN):
@echo "Checking for golangci-lint..."
@if [ ! -f "$@" ]; then \
echo "golangci-lint not found. Installing $(GOLANGCI_LINT_VERSION)..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(dir $@) $(GOLANGCI_LINT_VERSION); \
else \
echo "golangci-lint already installed."; \
fi
test: go-mod-download
@echo "Running unit tests..."
go test $(TESTOPTS) ./cmd/... ./internal/...
test-race: go-mod-download
@echo "Running tests with race detection..."
go test -race $(TESTOPTS) ./cmd/... ./internal/...
test-integration: go-mod-download
@echo "Running integration tests..."
go test -v ./internal/agent -run TestWorker_FullIntegration
test-e2e: go-mod-download
@echo "Running end-to-end tests with mock API..."
go test -v ./test/e2e -run "TestAgent_E2E_WithAPI" -timeout 30s
test-e2e-real: go-mod-download
@echo "Running end-to-end tests with real API..."
@if [ -z "$$RHOBS_SYNTHETICS_API_PATH" ]; then \
echo "Error: RHOBS_SYNTHETICS_API_PATH environment variable is not set"; \
exit 1; \
fi
go test -v ./test/e2e -run "TestAgent_E2E_.*RealAPI" -timeout 60s
test-e2e-all: go-mod-download
@echo "Running all end-to-end tests..."
@if [ -z "$$RHOBS_SYNTHETICS_API_PATH" ]; then \
echo "Error: RHOBS_SYNTHETICS_API_PATH environment variable is not set"; \
exit 1; \
fi
go test -v ./test/e2e -timeout 60s
.PHONY: coverage
coverage:
hack/codecov.sh
@echo ""
@echo "Overall coverage:"
@go tool cover -func=coverage.out | tail -1
go-mod-tidy:
go mod tidy
go-mod-download:
go mod download
# Build the Docker image
docker-build:
@echo "Building Docker image for linux/amd64: $(IMAGE_URL):$(TAG)"
$(CONTAINER_ENGINE) build --platform linux/amd64 -t $(IMAGE_URL):$(TAG) .
# Push the Docker image to the registry
docker-push:
@echo "Pushing Docker image: $(IMAGE_URL):$(TAG)"
$(CONTAINER_ENGINE) push $(IMAGE_URL):$(TAG)
# Create example configuration file
example-config:
@echo "Creating example configuration file..."
@if [ ! -f example-config.yaml ]; then \
echo "log_level: debug" > example-config.yaml; \
echo "log_format: json" >> example-config.yaml; \
echo "polling_interval: 10s" >> example-config.yaml; \
echo "graceful_timeout: 30s" >> example-config.yaml; \
echo "" >> example-config.yaml; \
echo "# API Configuration" >> example-config.yaml; \
echo "api_base_urls:" >> example-config.yaml; \
echo " - \"https://observatorium-api-1.example.com\"" >> example-config.yaml; \
echo " - \"https://observatorium-api-2.example.com\"" >> example-config.yaml; \
echo " - \"https://observatorium-api-3.example.com\"" >> example-config.yaml; \
echo "" >> example-config.yaml; \
echo "api_tenant: \"default\"" >> example-config.yaml; \
echo "label_selector: \"private=false\"" >> example-config.yaml; \
echo "" >> example-config.yaml; \
echo "# Kubernetes Configuration" >> example-config.yaml; \
echo "namespace: \"monitoring\"" >> example-config.yaml; \
echo "Example configuration created: example-config.yaml"; \
else \
echo "example-config.yaml already exists"; \
fi
# Run the application
run: build example-config
@echo "Running $(BINARY_NAME) with example configuration..."
./$(BINARY_NAME) start --config example-config.yaml --log-level debug
# Run the application without API (for testing)
run-local: build
@echo "Running $(BINARY_NAME) in local mode (no API configured)..."
./$(BINARY_NAME) start --log-level debug --interval 10s
# Clean up build artifacts
clean:
@echo "Cleaning up..."
@go clean
@rm -f $(BINARY_NAME)
@rm -f coverage.out coverage.html
@rm -f example-config.yaml
@$(CONTAINER_ENGINE) rmi -f $(IMAGE_URL):$(TAG) 2>/dev/null || true
@echo "Cleanup complete."
# Display help information
help:
@echo "Available targets:"
@echo ""
@echo "Build and Run:"
@echo " build - Build the Go binary"
@echo " run - Build and run with example configuration"
@echo " run-local - Build and run without API (for testing)"
@echo " example-config - Create example configuration file"
@echo ""
@echo "Testing:"
@echo " test - Run unit tests with coverage"
@echo " test-race - Run tests with race detection"
@echo " test-integration - Run integration tests"
@echo " test-e2e - Run end-to-end tests with mock API"
@echo " test-e2e-real - Run end-to-end tests with real API"
@echo " test-e2e-all - Run all end-to-end tests"
@echo " coverage - Generate detailed coverage report"
@echo ""
@echo "Code Quality:"
@echo " lint - Run golangci-lint"
@echo " lint-fix - Run golangci-lint with --fix"
@echo " lint-ci - Run golangci-lint for CI"
@echo ""
@echo "Dependencies:"
@echo " go-mod-tidy - Run go mod tidy"
@echo " go-mod-download - Run go mod download"
@echo ""
@echo "Docker:"
@echo " docker-build - Build Docker image"
@echo " docker-push - Push Docker image to registry"
@echo ""
@echo "Utilities:"
@echo " clean - Clean up build artifacts"
@echo " help - Show this help message"
@echo ""
@echo "Example Usage:"
@echo " make build test # Build and test"
@echo " make run # Quick start with example config"
@echo " make coverage # Generate test coverage report"