Home

Awesome

Ultimate Golang Makefile

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.

šŸš€ Features

šŸ“‹ Prerequisites

šŸ›  Installation

  1. Copy the Makefile to your project root:
curl -O https://raw.githubusercontent.com/crazywolf132/ultimate-gomake/main/Makefile
  1. Initialize your project:
make init

This will:

āš™ļø Configuration

Environment Variables

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

Project Structure

The Makefile assumes the following project structure:

.
ā”œā”€ā”€ cmd/
ā”‚   ā””ā”€ā”€ myapp/
ā”‚       ā””ā”€ā”€ main.go
ā”œā”€ā”€ pkg/
ā”œā”€ā”€ internal/
ā”œā”€ā”€ api/
ā”œā”€ā”€ docs/
ā”œā”€ā”€ scripts/
ā”œā”€ā”€ build/
ā”œā”€ā”€ configs/
ā”œā”€ā”€ test/
ā”‚   ā”œā”€ā”€ e2e/
ā”‚   ā””ā”€ā”€ integration/
ā””ā”€ā”€ Makefile

šŸŽÆ Common Commands

Development

# 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

Building

# 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

Docker Operations

# Build Docker image
make docker-build

# Push Docker image
make docker-push

# Run in Docker container
make docker-run

Database Operations

# Run migrations
make db-migrate

# Rollback last migration
make db-rollback

# Reset database
make db-reset

Maintenance

# Install/update dependencies
make deps
make deps-update

# Clean build artifacts
make clean

# Update tools
make tools

šŸ—ļø Project Types

Basic Project

For single-service projects, use default settings:

PROJECT_TYPE=basic

Monorepo

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

šŸ“Š Reports

Generate comprehensive project reports:

make report

This creates:

Reports are saved in docs/reports/.

šŸ”„ CI/CD Integration

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.

šŸ“š Documentation

# Generate documentation
make docs

# Serve documentation locally
make serve-docs

šŸŽØ Customization

Adding New Targets

Add custom targets at the end of the Makefile:

.PHONY: custom-target
custom-target: ## Custom target description
    @echo "Running custom target..."
    @# Custom commands here

Modifying Existing Targets

Override existing targets by redefining them in config.mk:

# config.mk
.PHONY: test
test: ## Custom test implementation
    @echo "Running custom tests..."
    @# Custom test commands

šŸ¤ Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

šŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

šŸ™ Acknowledgements

Special thanks to the Go community and all contributors who have helped shape this Makefile system.