COMPOSE ?= docker compose
SERVICE ?= smartup

.PHONY: up down build build-nc up-build log restart ps

# 日常启动（不重新构建镜像，启动已有容器）
up:
	$(COMPOSE) up -d
	@port=$$(grep -E '^SERVER_PORT=' .env 2>/dev/null | tail -n 1 | cut -d= -f2-); \
	printf '访问地址：http://localhost:%s\n' "$${port:-8899}"

# 构建镜像（带 BuildKit 缓存）
build:
	DOCKER_BUILDKIT=1 $(COMPOSE) build

# 强制重新构建（忽略 Docker 层缓存，npm/pip/apt 下载缓存仍可能复用）
build-nc:
	DOCKER_BUILDKIT=1 $(COMPOSE) build --no-cache

# 构建并启动（依赖变更后使用）
up-build:
	DOCKER_BUILDKIT=1 $(COMPOSE) up -d --build
	@port=$$(grep -E '^SERVER_PORT=' .env 2>/dev/null | tail -n 1 | cut -d= -f2-); \
	printf '访问地址：http://localhost:%s\n' "$${port:-8899}"

down:
	$(COMPOSE) down

log:
	$(COMPOSE) logs -f --tail=200 $(SERVICE)

restart: down up

ps:
	$(COMPOSE) ps
