From d3c4d4bd86cab12acd3c4a91514ab24a83b78027 Mon Sep 17 00:00:00 2001 From: Alberto Moretti Date: Tue, 16 Jun 2026 14:49:22 +0200 Subject: [PATCH] chore: add developer make targets --- Makefile | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..abbd5a5 --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +SHELL := /bin/sh + +CARGO ?= cargo +DOCKER ?= docker +IMAGE ?= pokedex-api +TAG ?= local +BASE_URL ?= http://localhost:8000 +POKEMON ?= mewtwo +PLATFORMS ?= linux/amd64,linux/arm64 +GIT_SHA ?= $(shell git rev-parse HEAD 2>/dev/null || printf unknown) + +.PHONY: help run docker-build docker-run health pokemon translated metrics fmt clippy test check contract-test docker-buildx + +help: + @printf 'Available targets:\n' + @printf ' make run Run the API locally with cargo\n' + @printf ' make docker-build Build the Docker image\n' + @printf ' make docker-run Run the Docker image on port 8000\n' + @printf ' make health curl /health\n' + @printf ' make pokemon curl /pokemon/$${POKEMON}\n' + @printf ' make translated curl /pokemon/translated/$${POKEMON}\n' + @printf ' make metrics curl /metrics\n' + @printf ' make check Run fmt, clippy, and tests\n' + @printf ' make contract-test Run ignored external contract tests\n' + @printf ' make docker-buildx Build multi-arch Docker image\n' + +run: + $(CARGO) run --bin pokedex-api + +docker-build: + $(DOCKER) build -t $(IMAGE) . + +docker-run: + $(DOCKER) run --rm -p 8000:8000 $(IMAGE) + +health: + curl -fsS $(BASE_URL)/health + +pokemon: + curl -fsS $(BASE_URL)/pokemon/$(POKEMON) + +translated: + curl -fsS $(BASE_URL)/pokemon/translated/$(POKEMON) + +metrics: + curl -fsS $(BASE_URL)/metrics + +fmt: + $(CARGO) fmt --all --check + +clippy: + $(CARGO) clippy --locked --all-targets -- -D warnings + +test: + $(CARGO) test --locked + +check: fmt clippy test + +contract-test: + $(CARGO) test --locked --test external_contract -- --ignored --test-threads=1 + +docker-buildx: + $(DOCKER) buildx build --platform $(PLATFORMS) --build-arg GIT_SHA=$(GIT_SHA) -t $(IMAGE):$(TAG) .