Makefile Recipes for Real Projects

Production-oriented Makefile targets for apps, Docker, Terraform, Python, Node, Go, and deployment workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Project bootstrap and help
Help target
.PHONY: help
help: ## Show available targets
  @grep -E '^[a-zA-Z0-9_.-]+:.*?## ' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-24s %s
", $$1, $$2}'

# List available targets and descriptions.

Bootstrap target
.PHONY: bootstrap
bootstrap: ## Install local dependencies
  pnpm install
  pre-commit install

# Install development dependencies and prepare local state.

All target
.PHONY: all
all: lint test build

# Aggregate common build steps.

## Language and framework examples
Node.js targets
.PHONY: lint test build
lint:
  pnpm lint

test:
  pnpm test

build:
  pnpm build

# Lint, test, and build JavaScript or TypeScript projects.

Python targets
.PHONY: fmt lint test
fmt:
  ruff format .

lint:
  ruff check .

test:
  pytest -q

# Format, lint, and test a Python project.

Go targets
.PHONY: fmt test build
fmt:
  go fmt ./...

test:
  go test ./...

build:
  go build ./...

# Format, test, and build Go projects.

Delegate to gradle or maven
build:
  ./gradlew build

test:
  ./gradlew test

# Wrap build tool commands in stable team-facing targets.

## Infrastructure and deployment recipes
Docker build target
IMAGE ?= example/app
TAG ?= latest

.PHONY: docker-build
docker-build:
  docker build -t $(IMAGE):$(TAG) .

# Build a container image with a version tag.

Docker push target
docker-push:
  docker push $(IMAGE):$(TAG)

# Push a previously built image.

Terraform plan target
ENV ?= dev

terraform-plan:
  cd infra/$(ENV) && terraform init && terraform plan -out=tfplan

# Run a named plan file for a chosen environment.

Terraform apply target
terraform-apply:
  cd infra/$(ENV) && terraform apply tfplan

# Apply the previously generated plan.

Deploy static site to S3
deploy-web:
  aws s3 sync dist/ s3://$(WEB_BUCKET) --delete
  aws cloudfront create-invalidation --distribution-id $(DIST_ID) --paths '/*'

# Sync built files to a bucket and invalidate a CDN.

## Release and versioning targets
Generate version file
version.txt:
  @printf '%s
' '$(VERSION)' > $@

# Write current version metadata into an artifact.

Create Git tag
tag-release:
  git tag v$(VERSION)
  git push origin v$(VERSION)

# Tag the current commit with a release version.

Generate changelog snippet
changelog:
  git log --oneline --decorate $$(git describe --tags --abbrev=0)..HEAD

# Capture commit history since the last tag.

Recommended next

No recommendations yet.