-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
132 lines (110 loc) · 3.55 KB
/
Makefile
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
# Variables
APP_NAME := tfkycv
IMAGE_NAME := ghcr.io/threefoldtech/tf-kyc-verifier
MAIN_PATH := cmd/api/main.go
SWAGGER_GENERAL_API_INFO_PATH := internal/handlers/handlers.go
DOCKER_COMPOSE := docker compose
# Go related variables
GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/bin
GOFILES := $(wildcard *.go)
# Git related variables
GIT_COMMIT := $(shell git rev-parse --short HEAD)
VERSION := $(shell git describe --tags --always)
# Build flags
LDFLAGS := -X github.com/threefoldtech/tf-kyc-verifier/internal/build.Version=$(VERSION)
.PHONY: all build clean test coverage lint swagger run docker-build docker-up docker-down help
# Default target
all: clean build
# Build the application
build:
@echo "Building $(APP_NAME)..."
@go build -ldflags "$(LDFLAGS)" -o $(GOBIN)/$(APP_NAME) $(MAIN_PATH)
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(GOBIN)
@go clean
# Run tests
test:
@echo "Running tests..."
@go test -v ./...
# Run tests with coverage
coverage:
@echo "Running tests with coverage..."
@go test -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out
@rm coverage.out
# Run linter
lint:
@echo "Running linter..."
@golangci-lint run
# Generate swagger documentation
swagger:
@echo "Generating Swagger documentation..."
@export PATH=$PATH:$(go env GOPATH)/bin
@swag init -g $(SWAGGER_GENERAL_API_INFO_PATH) --output api/docs
# Run the application locally
run: swagger build
@echo "Running $(APP_NAME)..."
@set -o allexport; . ./.app.env; set +o allexport; $(GOBIN)/$(APP_NAME)
# Build docker image
docker-build:
@echo "Building Docker image..."
@docker build -t $(IMAGE_NAME):$(VERSION) .
# Start docker compose services
docker-up:
@echo "Starting Docker services..."
@$(DOCKER_COMPOSE) up --build -d
# Stop docker compose services
docker-down:
@echo "Stopping Docker services..."
@$(DOCKER_COMPOSE) down
# Start development environment
dev: swagger docker-up
@echo "Starting development environment..."
@$(DOCKER_COMPOSE) logs -f api
# Update dependencies
deps-update:
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy
# Verify dependencies
deps-verify:
@echo "Verifying dependencies..."
@go mod verify
# Check for security vulnerabilities
security-check:
@echo "Checking for security vulnerabilities..."
@gosec ./...
# Format code
fmt:
@echo "Formatting code..."
@go fmt ./...
# Show help
help:
@echo "Available targets:"
@echo " make : Build the application after cleaning"
@echo " make build : Build the application"
@echo " make clean : Clean build artifacts"
@echo " make test : Run tests"
@echo " make coverage : Run tests with coverage report"
@echo " make lint : Run linter"
@echo " make swagger : Generate Swagger documentation"
@echo " make run : Run the application locally"
@echo " make docker-build : Build Docker image"
@echo " make docker-up : Start Docker services"
@echo " make docker-down : Stop Docker services"
@echo " make dev : Start development environment"
@echo " make deps-update : Update dependencies"
@echo " make deps-verify : Verify dependencies"
@echo " make security-check: Check for security vulnerabilities"
@echo " make fmt : Format code"
@echo " make install-tools: Install development tools"
# Install development tools
.PHONY: install-tools
install-tools:
@echo "Installing development tools..."
@go install github.com/swaggo/swag/cmd/swag@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install github.com/securego/gosec/v2/cmd/gosec@latest