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

Targets most projects should expose.

Help target

List available targets and descriptions.

makefileANYhelpbootstrap
makefile
.PHONY: help
help: ## Show available targets
  @grep -E '^[a-zA-Z0-9_.-]+:.*?## ' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-24s %s
", $$1, $$2}'

A standard self-documenting help target.

Bootstrap target

Install development dependencies and prepare local state.

makefileANYbootstrapdependencies
makefile
.PHONY: bootstrap
bootstrap: ## Install local dependencies
  pnpm install
  pre-commit install

Adapt to your stack.

All target

Aggregate common build steps.

makefileANYaggregateall
makefile
.PHONY: all
all: lint test build

Often paired with `.DEFAULT_GOAL := all` or `help`.

Language and framework examples

Reusable targets for common stacks.

Node.js targets

Lint, test, and build JavaScript or TypeScript projects.

makefileANYnodetypescriptrecipes
makefile
.PHONY: lint test build
lint:
  pnpm lint

test:
  pnpm test

build:
  pnpm build

Simple and team-friendly task aliases.

Python targets

Format, lint, and test a Python project.

makefileANYpythonrecipes
makefile
.PHONY: fmt lint test
fmt:
  ruff format .

lint:
  ruff check .

test:
  pytest -q

Great entry point for Python apps and libraries.

Go targets

Format, test, and build Go projects.

makefileANYgorecipes
makefile
.PHONY: fmt test build
fmt:
  go fmt ./...

test:
  go test ./...

build:
  go build ./...

A common pattern in Go repositories.

Delegate to gradle or maven

Wrap build tool commands in stable team-facing targets.

makefileANYjavagradlerecipes
makefile
build:
  ./gradlew build

test:
  ./gradlew test

Make can serve as a repo-level command facade across multiple languages.

Infrastructure and deployment recipes

Operational targets for containers and cloud workflows.

Docker build target

Build a container image with a version tag.

makefileANYdockercontainers
makefile
IMAGE ?= example/app
TAG ?= latest

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

Common deployment building block.

Docker push target

Push a previously built image.

makefileANYdockerpublish
makefile
docker-push:
  docker push $(IMAGE):$(TAG)

Often combined with auth/login steps elsewhere.

Terraform plan target

Run a named plan file for a chosen environment.

makefileANYterraforminfra
makefile
ENV ?= dev

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

A nice wrapper around verbose infra commands.

Terraform apply target

Apply the previously generated plan.

makefileANYterraforminfradeploy
makefile
terraform-apply:
  cd infra/$(ENV) && terraform apply tfplan

Consider adding approval guards for production.

Deploy static site to S3

Sync built files to a bucket and invalidate a CDN.

makefileANYawsdeployments3cloudfront
makefile
deploy-web:
  aws s3 sync dist/ s3://$(WEB_BUCKET) --delete
  aws cloudfront create-invalidation --distribution-id $(DIST_ID) --paths '/*'

A realistic cloud deployment target.

Release and versioning targets

Tagging, changelogs, and release preparation.

Generate version file

Write current version metadata into an artifact.

makefileANYreleaseversioning
makefile
version.txt:
  @printf '%s
' '$(VERSION)' > $@

Useful for app metadata and build info.

Create Git tag

Tag the current commit with a release version.

makefileANYreleasegittag
makefile
tag-release:
  git tag v$(VERSION)
  git push origin v$(VERSION)

Pair with required-variable guards.

Generate changelog snippet

Capture commit history since the last tag.

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

Double-dollar escapes shell command substitution through make.

Recommended next

No recommendations yet.