-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
127 lines (109 loc) · 3.64 KB
/
Copy pathMakefile
File metadata and controls
127 lines (109 loc) · 3.64 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
.PHONY: build test clean install lint format help
# Binary name
BINARY_NAME=artiscanctl
BUILD_DIR=bin
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
# Build flags
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
# Default target
all: build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/artiscanctl
# Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/artiscanctl
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/artiscanctl
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/artiscanctl
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/artiscanctl
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Clean build artifacts and temporary files
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
@echo "Removing JSON scan results and temporary files..."
rm -f *.json
rm -f *.log
rm -f *.tmp
rm -f *_scan.*
rm -f *_clean.*
rm -f *_test.*
rm -f *_enhanced.*
@echo "Clean completed!"
# Install dependencies
deps:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Install the binary
install: build
@echo "Installing $(BINARY_NAME)..."
cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
# Lint the code
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found. Install it from https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run
# Format the code
format:
@echo "Formatting code..."
$(GOFMT) -s -w .
# Run the application (development)
run: build
./$(BUILD_DIR)/$(BINARY_NAME)
# Example commands
examples:
@echo "Example commands:"
@echo " ./$(BUILD_DIR)/$(BINARY_NAME) scan image nginx:latest"
@echo " ./$(BUILD_DIR)/$(BINARY_NAME) scan filesystem /usr/local"
# Development setup
dev-setup:
@echo "Setting up development environment..."
$(GOMOD) download
@echo "Installing development tools..."
$(GOGET) github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Docker build (for testing)
docker-build:
@echo "Building Docker image for testing..."
docker build -t arkeonctl:latest .
# Help
help:
@echo "Available targets:"
@echo " build - Build the binary"
@echo " build-all - Build for multiple platforms"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " clean - Clean build artifacts and temporary files (JSON, logs, etc.)"
@echo " deps - Install dependencies"
@echo " install - Install binary to /usr/local/bin"
@echo " lint - Run linter"
@echo " format - Format code"
@echo " run - Build and run the application"
@echo " examples - Show example commands"
@echo " dev-setup - Setup development environment"
@echo " docker-build - Build Docker image for testing"
@echo " help - Show this help message"