SHELL := /usr/bin/env bash MAKEFLAGS += --no-builtin-rules EXTRA_ARGS := $(filter-out -- $(firstword $(MAKECMDGOALS)),$(MAKECMDGOALS)) .DEFAULT_GOAL := help .PHONY: help help: @printf ' \033[36m%-22s\033[0m %s\n' 'target' 'description' @awk 'BEGIN {FS = ":.*?## "} \ /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}' \ $(MAKEFILE_LIST) .PHONY: build build: cargo build --workspace .PHONY: check check: cargo check --workspace --all-targets .PHONY: test test: cargo test --workspace .PHONY: clippy clippy: cargo clippy --workspace --all-targets -- -D warnings .PHONY: fmt fmt: cargo fmt --all .PHONY: fmt-check fmt-check: cargo fmt --all --check .PHONY: clean clean: cargo clean @find . -type d -name target -prune -exec rm -rf {} + @echo "已清理 target/ 目录" # ---------- Docker ---------- DOCKER_APPS := apihost githook gitpro livechat mails .PHONY: docker-build docker-build: ## 宿主机编译并构建全部应用的 Docker 镜像 ./docker/build.sh .PHONY: docker-build-apihost docker-build-githook docker-build-gitpro docker-build-livechat docker-build-mails docker-build-apihost: ## 构建 apihost 镜像 ./docker/build.sh apihost docker-build-githook: ## 构建 githook 镜像 ./docker/build.sh githook docker-build-gitpro: ## 构建 gitpro 镜像 ./docker/build.sh gitpro docker-build-livechat: ## 构建 livechat 镜像 ./docker/build.sh livechat docker-build-mails: ## 构建 mails 镜像 ./docker/build.sh mails .PHONY: list-apps list-apps: @echo apihost githook gitpro livechat mails .PHONY: ports ports: @printf ' %-12s %s\n' app port @printf ' %-12s %s\n' apihost 8080 @printf ' %-12s %s\n' githook '(non-network)' @printf ' %-12s %s\n' gitpro '(non-network)' @printf ' %-12s %s\n' livechat 8081 @printf ' %-12s %s\n' mails '(non-network)' .PHONY: port-check port-check: @status=0; \ check() { \ port="$$1"; \ name="$$2"; \ if [ "$$port" = "0" ]; then return; fi; \ if ss -ltn 2>/dev/null | grep -q ":$$port "; then \ echo " ✗ $$name: port $$port 已占用"; \ status=1; \ else \ echo " ✓ $$name: port $$port 空闲"; \ fi; \ }; \ check 8080 apihost; \ check 8081 livechat; \ exit $$status .PHONY: run-apihost run-apihost: @if ss -ltn 2>/dev/null | grep -q ":8080 "; then \ echo "✗ apihost 默认端口 8080 已被占用"; \ echo " kill 占用进程,或 make run-apihost -- --port <其他>"; \ exit 1; \ fi @if [ -n "$(EXTRA_ARGS)" ]; then \ cargo run -p apihost -- $(EXTRA_ARGS); \ else \ cargo run -p apihost; \ fi .PHONY: build-apihost build-apihost: cargo build -p apihost .PHONY: check-apihost check-apihost: cargo check -p apihost .PHONY: test-apihost test-apihost: cargo test -p apihost .PHONY: dev-apihost dev-apihost: @command -v cargo-watch >/dev/null 2>&1 || { \ echo "缺少 cargo-watch,请先: cargo install cargo-watch --locked"; \ exit 1; \ } cargo watch -x "run -p apihost" .PHONY: run-githook run-githook: @if [ -n "$(EXTRA_ARGS)" ]; then \ cargo run -p githook -- $(EXTRA_ARGS); \ else \ cargo run -p githook; \ fi .PHONY: build-githook build-githook: cargo build -p githook .PHONY: check-githook check-githook: cargo check -p githook .PHONY: test-githook test-githook: cargo test -p githook .PHONY: dev-githook dev-githook: @command -v cargo-watch >/dev/null 2>&1 || { \ echo "缺少 cargo-watch,请先: cargo install cargo-watch --locked"; \ exit 1; \ } cargo watch -x "run -p githook" .PHONY: run-gitpro run-gitpro: @if [ -n "$(EXTRA_ARGS)" ]; then \ cargo run -p gitpro -- $(EXTRA_ARGS); \ else \ cargo run -p gitpro; \ fi .PHONY: build-gitpro build-gitpro: cargo build -p gitpro .PHONY: check-gitpro check-gitpro: cargo check -p gitpro .PHONY: test-gitpro test-gitpro: cargo test -p gitpro .PHONY: dev-gitpro dev-gitpro: @command -v cargo-watch >/dev/null 2>&1 || { \ echo "缺少 cargo-watch,请先: cargo install cargo-watch --locked"; \ exit 1; \ } cargo watch -x "run -p gitpro" .PHONY: run-livechat run-livechat: @if ss -ltn 2>/dev/null | grep -q ":8081 "; then \ echo "✗ livechat 默认端口 8081 已被占用"; \ echo " kill 占用进程,或 make run-livechat -- --port <其他>"; \ exit 1; \ fi @if [ -n "$(EXTRA_ARGS)" ]; then \ cargo run -p livechat -- $(EXTRA_ARGS); \ else \ cargo run -p livechat; \ fi .PHONY: build-livechat build-livechat: cargo build -p livechat .PHONY: check-livechat check-livechat: cargo check -p livechat .PHONY: test-livechat test-livechat: cargo test -p livechat .PHONY: dev-livechat dev-livechat: @command -v cargo-watch >/dev/null 2>&1 || { \ echo "缺少 cargo-watch,请先: cargo install cargo-watch --locked"; \ exit 1; \ } cargo watch -x "run -p livechat" .PHONY: run-mails run-mails: @if [ -n "$(EXTRA_ARGS)" ]; then \ cargo run -p mails -- $(EXTRA_ARGS); \ else \ cargo run -p mails; \ fi .PHONY: build-mails build-mails: cargo build -p mails .PHONY: check-migrate check-migrate: cargo check -p migrate .PHONY: migrate migrate: cargo run -p migrate .PHONY: check-mails check-mails: cargo check -p mails .PHONY: test-mails test-mails: cargo test -p mails .PHONY: dev-mails dev-mails: @command -v cargo-watch >/dev/null 2>&1 || { \ echo "缺少 cargo-watch,请先: cargo install cargo-watch --locked"; \ exit 1; \ } cargo watch -x "run -p mails" .PHONY: run run: run-apihost .PHONY: build-all build-all: @trap 'kill $$(jobs -p) 2>/dev/null' INT TERM cargo build -p apihost & \ cargo build -p githook & \ cargo build -p gitpro & \ cargo build -p livechat & \ cargo build -p mails & \ wait .PHONY: run-all run-all: port-check @trap 'kill $$(jobs -p) 2>/dev/null' INT TERM; \ cargo run -p apihost -- --port 8080 & \ cargo run -p githook & \ cargo run -p gitpro & \ cargo run -p livechat -- --port 8081 & \ cargo run -p mails & \ wait .PHONY: check-deps check-deps: @command -v cargo-outdated >/dev/null 2>&1 && \ cargo outdated --workspace --exit-code 0 || \ echo "未安装 cargo-outdated(cargo install cargo-outdated --locked)" @command -v cargo-deny >/dev/null 2>/dev/null && \ cargo deny check || \ echo "未安装 cargo-deny(cargo install cargo-deny --locked)"