A comprehensive, production-ready Makefile system for Go projects of any size. This Makefile provides a complete set of commands for development, testing, building, and deployment workflows while remaining flexible and customizable.
- Flexible Configuration: Support for environment variables, .env files, and command-line overrides
- Multi-Environment Support: Development, staging, and production builds
- Cross-Platform Building: Support for multiple OS/Architecture combinations
- Advanced Testing: Unit, integration, and end-to-end testing with coverage reports
- Docker Integration: Build, push, and run Docker containers
- Database Operations: Migration management and database utilities
- Development Tools: Hot reload, formatting, linting, and security scanning
- CI/CD Ready: Integrated pipeline support for common CI systems
- Documentation: Automatic API documentation generation
- Monorepo Support: Build and manage multiple services
- Comprehensive Reporting: Test coverage, benchmarks, and security reports
- Go 1.21 or higher
- Make
- Docker (optional)
- Git
- Copy the Makefile to your project root:
curl -O https://raw.githubusercontent.com/crazywolf132/ultimate-gomake/main/Makefile
- Initialize your project:
make init
This will:
- Create necessary directories
- Initialize Go modules
- Install required tools
- Create default configuration files
Create a .env
file in your project root to override default settings:
# Project Configuration
PROJECT_NAME=myapp
ORGANIZATION=myorg
ENABLE_DOCKER=true
ENABLE_PROTO=false
# Build Settings
CGO_ENABLED=0
COVERAGE_THRESHOLD=80
# Docker Settings
DOCKER_REGISTRY=docker.io
DOCKER_REPO=myorg/myapp
The Makefile assumes the following project structure:
.
βββ cmd/
β βββ myapp/
β βββ main.go
βββ pkg/
βββ internal/
βββ api/
βββ docs/
βββ scripts/
βββ build/
βββ configs/
βββ test/
β βββ e2e/
β βββ integration/
βββ Makefile
# Start development with hot reload
make dev
# Run tests
make test
# Run tests with coverage
make test-coverage
# Format and lint code
make fmt lint
# Generate mocks and protobuf
make generate
# Build for current platform
make build
# Build for all platforms
make build-all
# Build with debug symbols
make build-debug
# Build with race detector
make build-race
# Build Docker image
make docker-build
# Push Docker image
make docker-push
# Run in Docker container
make docker-run
# Run migrations
make db-migrate
# Rollback last migration
make db-rollback
# Reset database
make db-reset
# Install/update dependencies
make deps
make deps-update
# Clean build artifacts
make clean
# Update tools
make tools
For single-service projects, use default settings:
PROJECT_TYPE=basic
For multiple services, configure as follows:
PROJECT_TYPE=monorepo
MONOREPO_SERVICES=service1 service2 service3
Directory structure for monorepo:
.
βββ services/
β βββ service1/
β β βββ cmd/
β βββ service2/
β β βββ cmd/
β βββ service3/
β βββ cmd/
βββ Makefile
Generate comprehensive project reports:
make report
This creates:
- Test coverage reports
- Benchmark results
- Linting reports
- Security scan results
Reports are saved in docs/reports/
.
The Makefile includes predefined CI/CD targets:
# Run CI pipeline
make ci
# Run CD pipeline
make cd
Customize pipelines by modifying these targets in the Makefile.
# Generate documentation
make docs
# Serve documentation locally
make serve-docs
Add custom targets at the end of the Makefile:
.PHONY: custom-target
custom-target: ## Custom target description
@echo "Running custom target..."
@# Custom commands here
Override existing targets by redefining them in config.mk
:
# config.mk
.PHONY: test
test: ## Custom test implementation
@echo "Running custom tests..."
@# Custom test commands
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Special thanks to the Go community and all contributors who have helped shape this Makefile system.