
Some checks failed
CI/CD Pipeline / Run Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
CI/CD Pipeline / Build Docker Image (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Create Release (push) Has been cancelled
81 lines
2.1 KiB
Makefile
81 lines
2.1 KiB
Makefile
.PHONY: build run test clean deps fmt vet lint docker-build docker-run docker-clean help
|
|
|
|
# Variables
|
|
BINARY_NAME=gorz
|
|
VERSION=$(shell git describe --tags --always --dirty --match="v*")
|
|
BUILD_TIME=$(shell date -u '+%Y-%m-%d %H:%M:%S')
|
|
GIT_COMMIT=$(shell git rev-parse --short HEAD)
|
|
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.BuildTime='${BUILD_TIME}' -X main.GitCommit=${GIT_COMMIT}"
|
|
|
|
# Default target
|
|
all: deps fmt vet lint build
|
|
|
|
# Build the binary
|
|
build:
|
|
go build ${LDFLAGS} -o ${BINARY_NAME} ./cmd/server
|
|
|
|
# Run the binary
|
|
run: build
|
|
./${BINARY_NAME}
|
|
|
|
# Run tests
|
|
test:
|
|
go test -v -race -coverprofile=coverage.out ./...
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
|
|
# Clean build artifacts
|
|
clean:
|
|
go clean
|
|
rm -f ${BINARY_NAME}
|
|
rm -f coverage.out coverage.html
|
|
|
|
# Download dependencies
|
|
deps:
|
|
go mod download
|
|
go mod tidy
|
|
|
|
# Format code
|
|
fmt:
|
|
go fmt ./...
|
|
|
|
# Vet checks for errors
|
|
vet:
|
|
go vet ./...
|
|
|
|
# Run linter
|
|
lint:
|
|
golangci-lint run
|
|
|
|
# Build Docker image
|
|
docker-build:
|
|
docker build -t ${BINARY_NAME}:${VERSION} .
|
|
|
|
# Run Docker container
|
|
docker-run: docker-build
|
|
docker run -p 8080:8080 -p 9090:9090 -v $(PWD)/config.yaml:/app/config.yaml ${BINARY_NAME}:${VERSION}
|
|
|
|
# Clean Docker images
|
|
docker-clean:
|
|
docker rmi ${BINARY_NAME}:${VERSION} || true
|
|
|
|
# Generate default config
|
|
config:
|
|
go run ./cmd/server -config=config.yaml && echo "Default configuration created at config.yaml"
|
|
|
|
# Show help
|
|
help:
|
|
@echo "Available targets:"
|
|
@echo " all - Run deps, fmt, vet, lint, and build"
|
|
@echo " build - Build the binary"
|
|
@echo " run - Build and run the binary"
|
|
@echo " test - Run tests and generate coverage report"
|
|
@echo " clean - Clean build artifacts"
|
|
@echo " deps - Download dependencies"
|
|
@echo " fmt - Format code"
|
|
@echo " vet - Run go vet"
|
|
@echo " lint - Run linter"
|
|
@echo " docker-build - Build Docker image"
|
|
@echo " docker-run - Build and run Docker container"
|
|
@echo " docker-clean - Clean Docker images"
|
|
@echo " config - Generate default configuration"
|
|
@echo " help - Show this help message"
|