-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (95 loc) · 3.21 KB
/
Copy pathMakefile
File metadata and controls
116 lines (95 loc) · 3.21 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
.PHONY: build install clean test lint fmt deps run help
# Binary name
BINARY_NAME=sentinel
VERSION?=0.1.0
BUILD_DIR=./bin
GO=go
# Get git commit and build date
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Build flags
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildDate=$(BUILD_DATE) -s -w"
# Default target
all: deps build
## build: Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/sentinel
## build-all: Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/sentinel
GOOS=linux GOARCH=arm64 $(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/sentinel
GOOS=darwin GOARCH=amd64 $(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/sentinel
GOOS=darwin GOARCH=arm64 $(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/sentinel
GOOS=windows GOARCH=amd64 $(GO) build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/sentinel
## install: Install the binary to /usr/local/bin
install: build
@echo "Installing $(BINARY_NAME)..."
sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@echo "Installed to /usr/local/bin/$(BINARY_NAME)"
## uninstall: Remove the installed binary
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
sudo rm -f /usr/local/bin/$(BINARY_NAME)
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
$(GO) mod download
$(GO) mod tidy
## test: Run tests
test:
@echo "Running tests..."
$(GO) test -v -race -cover ./...
## test-coverage: Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
$(GO) test -v -race -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## lint: Run linter
lint:
@echo "Running linter..."
golangci-lint run ./...
## fmt: Format code
fmt:
@echo "Formatting code..."
$(GO) fmt ./...
goimports -w .
## vet: Run go vet
vet:
@echo "Running go vet..."
$(GO) vet ./...
## clean: Clean build artifacts
clean:
@echo "Cleaning..."
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
## run: Run the application
run: build
$(BUILD_DIR)/$(BINARY_NAME)
## run-validate: Run validation example
run-validate: build
$(BUILD_DIR)/$(BINARY_NAME) validate -- run --privileged nginx
## run-scan: Run scan example
run-scan: build
$(BUILD_DIR)/$(BINARY_NAME) scan nginx:latest
## docker-build: Build Docker image
docker-build:
docker build -t docker-sentinel:$(VERSION) .
## init-config: Initialize default configuration
init-config:
@echo "Initializing configuration..."
mkdir -p ~/.sentinel/policies
cp configs/policies/default.yaml ~/.sentinel/policies/
@echo "Configuration initialized at ~/.sentinel/"
## help: Show this help message
help:
@echo "Docker Sentinel - Pre-runtime Container Security"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'