Files
2026-07-04 00:17:11 +08:00

69 lines
2.5 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
REGISTRY ?= your-registry
BACKEND_IMAGE ?= $(REGISTRY)/stock-tracker-backend
FRONTEND_IMAGE ?= $(REGISTRY)/stock-tracker-frontend
TAG ?= latest
PLATFORMS ?= linux/amd64,linux/arm64
.PHONY: help build build-backend build-frontend push push-backend \
push-frontend multiarch multiarch-backend multiarch-frontend \
compose-up compose-down compose-build clean
help: ## 显示帮助信息
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# ── 本地构建(当前架构) ──────────────────────────────────
build: build-backend build-frontend ## 构建后端和前端镜像(当前架构)
build-backend: ## 构建后端镜像
docker build -t $(BACKEND_IMAGE):$(TAG) ./backend
build-frontend: ## 构建前端镜像
docker build -t $(FRONTEND_IMAGE):$(TAG) ./frontend
# ── 推送单架构镜像 ──────────────────────────────────────
push: push-backend push-frontend ## 推送后端和前端镜像
push-backend: build-backend ## 构建并推送后端镜像
docker push $(BACKEND_IMAGE):$(TAG)
push-frontend: build-frontend ## 构建并推送前端镜像
docker push $(FRONTEND_IMAGE):$(TAG)
# ── 多架构构建(arm64 + amd64) ─────────────────────────
multiarch: multiarch-backend multiarch-frontend ## 构建并推送多架构镜像(arm64 + amd64
multiarch-backend: ## 构建并推送后端多架构镜像
docker buildx build \
--platform $(PLATFORMS) \
-t $(BACKEND_IMAGE):$(TAG) \
./backend \
--push
multiarch-frontend: ## 构建并推送前端多架构镜像
docker buildx build \
--platform $(PLATFORMS) \
-t $(FRONTEND_IMAGE):$(TAG) \
./frontend \
--push
# ── docker compose 管理 ────────────────────────────────
compose-up: ## 启动所有服务
docker compose up -d
compose-down: ## 停止所有服务
docker compose down
compose-build: ## 构建所有服务(本地架构)
docker compose build
# ── 清理 ───────────────────────────────────────────────
clean: ## 清理本地构建的镜像
-docker rmi $(BACKEND_IMAGE):$(TAG) 2>/dev/null || true
-docker rmi $(FRONTEND_IMAGE):$(TAG) 2>/dev/null || true