157 lines
3.3 KiB
Makefile
157 lines
3.3 KiB
Makefile
# Deal Room Makefile
|
|
|
|
.PHONY: build run test clean docker migrate templ dev install lint
|
|
|
|
# Variables
|
|
APP_NAME := dealroom
|
|
BINARY_PATH := ./bin/$(APP_NAME)
|
|
DOCKER_IMAGE := $(APP_NAME):latest
|
|
|
|
# Go build flags
|
|
CGO_ENABLED := 1
|
|
LDFLAGS := -ldflags "-X main.Version=$(shell git describe --tags --always --dirty)"
|
|
|
|
# Default target
|
|
all: build
|
|
|
|
# Install dependencies
|
|
install:
|
|
go mod download
|
|
go install github.com/a-h/templ/cmd/templ@latest
|
|
|
|
# Generate templ templates
|
|
templ:
|
|
templ generate
|
|
|
|
# Build the application
|
|
build: templ
|
|
CGO_ENABLED=$(CGO_ENABLED) go build $(LDFLAGS) -o $(BINARY_PATH) ./cmd/dealroom
|
|
|
|
# Run in development mode
|
|
dev: templ
|
|
go run ./cmd/dealroom
|
|
|
|
# Run the built binary
|
|
run: build
|
|
$(BINARY_PATH)
|
|
|
|
# Run tests
|
|
test:
|
|
go test -v -race ./...
|
|
|
|
# Run tests with coverage
|
|
test-coverage:
|
|
go test -v -race -coverprofile=coverage.out ./...
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
|
|
# Run linter
|
|
lint:
|
|
golangci-lint run
|
|
|
|
# Clean build artifacts
|
|
clean:
|
|
rm -rf ./bin
|
|
rm -f coverage.out coverage.html
|
|
rm -rf ./data/temp/*
|
|
|
|
# Database migrations
|
|
migrate: build
|
|
$(BINARY_PATH) --migrate-only
|
|
|
|
# Create a new migration
|
|
migration:
|
|
@read -p "Migration name: " name; \
|
|
timestamp=$$(date +%Y%m%d%H%M%S); \
|
|
touch migrations/$${timestamp}_$${name}.sql
|
|
|
|
# Docker build
|
|
docker:
|
|
docker build -t $(DOCKER_IMAGE) .
|
|
|
|
# Docker run
|
|
docker-run: docker
|
|
docker run --rm -p 8080:8080 -v $(PWD)/data:/data $(DOCKER_IMAGE)
|
|
|
|
# Docker compose for development
|
|
docker-dev:
|
|
docker-compose up --build
|
|
|
|
# Production deployment
|
|
deploy: docker
|
|
docker tag $(DOCKER_IMAGE) registry.example.com/$(DOCKER_IMAGE)
|
|
docker push registry.example.com/$(DOCKER_IMAGE)
|
|
|
|
# Create release
|
|
release:
|
|
@if [ -z "$(VERSION)" ]; then echo "VERSION is required"; exit 1; fi
|
|
git tag -a $(VERSION) -m "Release $(VERSION)"
|
|
git push origin $(VERSION)
|
|
|
|
# Backup data
|
|
backup:
|
|
@echo "Creating backup..."
|
|
mkdir -p backups
|
|
tar -czf backups/backup-$$(date +%Y%m%d-%H%M%S).tar.gz data/
|
|
|
|
# Restore from backup
|
|
restore:
|
|
@if [ -z "$(BACKUP)" ]; then echo "BACKUP file is required"; exit 1; fi
|
|
tar -xzf $(BACKUP)
|
|
|
|
# Security scan
|
|
security:
|
|
gosec ./...
|
|
govulncheck ./...
|
|
|
|
# Format code
|
|
fmt:
|
|
go fmt ./...
|
|
templ fmt .
|
|
|
|
# Tidy dependencies
|
|
tidy:
|
|
go mod tidy
|
|
|
|
# Generate documentation
|
|
docs:
|
|
godoc -http=:6060 &
|
|
@echo "Documentation available at http://localhost:6060/pkg/dealroom/"
|
|
|
|
# Benchmark tests
|
|
bench:
|
|
go test -bench=. -benchmem ./...
|
|
|
|
# Profile the application
|
|
profile: build
|
|
go tool pprof $(BINARY_PATH) http://localhost:8080/debug/pprof/profile
|
|
|
|
# Check for outdated dependencies
|
|
deps-check:
|
|
go list -u -m all
|
|
|
|
# Update dependencies
|
|
deps-update:
|
|
go get -u ./...
|
|
go mod tidy
|
|
|
|
# Local development setup
|
|
setup: install
|
|
mkdir -p data/{db,files,backups,temp}
|
|
@echo "Development environment setup complete"
|
|
@echo "Run 'make dev' to start the development server"
|
|
|
|
# CI/CD targets
|
|
ci: lint test security
|
|
|
|
# Help target
|
|
help:
|
|
@echo "Available targets:"
|
|
@echo " build - Build the application"
|
|
@echo " run - Run the built binary"
|
|
@echo " dev - Run in development mode"
|
|
@echo " test - Run tests"
|
|
@echo " clean - Clean build artifacts"
|
|
@echo " docker - Build Docker image"
|
|
@echo " migrate - Run database migrations"
|
|
@echo " setup - Setup development environment"
|
|
@echo " help - Show this help message"
|