diff --git a/.dockerignore b/.dockerignore index a453ead..d13fcca 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,6 @@ *.db config.yaml -xiaji-go +ops-assistant .git .gitignore README.md diff --git a/.gitignore b/.gitignore index 6f96c69..f0f23e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,19 @@ # 二进制文件 -xiaji-go -xiaji-go-linux-amd64 +ops-assistant +ops-assistant-linux-amd64 +/main +/xiaji-go +/xiaji-go-linux-amd64 +/dist/ # 数据库 *.db +# 运行时产物(日志 / 备份) +/run/ +/cpa/ +*.log + # 配置文件(含敏感信息) config.yaml @@ -19,4 +28,4 @@ config.yaml Thumbs.db # Go -vendor/ +vendor/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 25f5035..ac36459 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,10 +19,10 @@ COPY . . # 编译 RUN CGO_ENABLED=1 go build \ - -ldflags "-X xiaji-go/version.Version=${VERSION} \ - -X xiaji-go/version.GitCommit=${GIT_COMMIT} \ - -X xiaji-go/version.BuildTime=${BUILD_TIME}" \ - -o xiaji-go cmd/main.go + -ldflags "-X ops-assistant/version.Version=${VERSION} \ + -X ops-assistant/version.GitCommit=${GIT_COMMIT} \ + -X ops-assistant/version.BuildTime=${BUILD_TIME}" \ + -o ops-assistant cmd/main.go # ============ 运行阶段 ============ FROM debian:bookworm-slim @@ -34,7 +34,7 @@ ENV TZ=Asia/Shanghai WORKDIR /app # 从构建阶段复制 -COPY --from=builder /build/xiaji-go . +COPY --from=builder /build/ops-assistant . COPY --from=builder /build/templates/ ./templates/ COPY --from=builder /build/config.yaml.example ./config.yaml.example @@ -44,9 +44,9 @@ COPY --from=builder /go/pkg/mod/github.com/yanyiwu/gojieba@v1.3.0/dict/ /app/dic # 数据目录 VOLUME ["/app/data"] -EXPOSE 9521 +EXPOSE 9621 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD curl -f http://localhost:9521/health || exit 1 + CMD curl -f http://localhost:9621/health || exit 1 -ENTRYPOINT ["./xiaji-go"] +ENTRYPOINT ["./ops-assistant"] diff --git a/Makefile b/Makefile index 7bd5d4f..fd3292a 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,19 @@ -APP_NAME := xiaji-go -VERSION := 1.1.12 +APP_NAME := ops-assistant +VERSION_FILE := VERSION +VERSION ?= $(shell cat $(VERSION_FILE) 2>/dev/null || echo "0.1.0") GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ') -LDFLAGS := -X xiaji-go/version.Version=$(VERSION) \ - -X xiaji-go/version.GitCommit=$(GIT_COMMIT) \ - -X xiaji-go/version.BuildTime=$(BUILD_TIME) +LDFLAGS := -X ops-assistant/version.Version=$(VERSION) \ + -X ops-assistant/version.GitCommit=$(GIT_COMMIT) \ + -X ops-assistant/version.BuildTime=$(BUILD_TIME) -DOCKER_IMAGE := ouaone/xiaji-go +DOCKER_IMAGE := ouaone/ops-assistant DOCKER_TAG := $(VERSION) +RELEASE_TAG := v$(VERSION) +DIST_DIR := dist +ASSET_NAME := $(APP_NAME)-$(RELEASE_TAG)-linux-amd64 -.PHONY: build clean run docker docker-push release help +.PHONY: build clean run docker docker-push release help version show-version set-version bump-patch bump-minor bump-major release-plan package-release tag-release release-check ## build: 编译二进制文件 build: @@ -39,10 +43,65 @@ docker-push: docker push $(DOCKER_IMAGE):$(DOCKER_TAG) docker push $(DOCKER_IMAGE):latest +## show-version: 显示语义化版本(vx.y.z) +show-version: + @echo "v$(VERSION)" + ## version: 显示版本信息 version: @echo "$(APP_NAME) v$(VERSION) ($(GIT_COMMIT))" +## set-version: 设置版本号(示例: make set-version VERSION=1.2.3) +set-version: + @echo "$(VERSION)" > $(VERSION_FILE) + @echo "✅ version set to v$(VERSION)" + +## bump-patch: 补丁版本 +1(x.y.z -> x.y.z+1) +bump-patch: + @python3 -c 'from pathlib import Path;p=Path("VERSION");s=p.read_text().strip() if p.exists() else "0.1.0";a,b,c=[int(x) for x in s.split(".")[:3]];n=f"{a}.{b}.{c+1}";p.write_text(n+"\n");print(f"✅ bump patch: v{s} -> v{n}")' + +## bump-minor: 次版本 +1(x.y.z -> x.y+1.0) +bump-minor: + @python3 -c 'from pathlib import Path;p=Path("VERSION");s=p.read_text().strip() if p.exists() else "0.1.0";a,b,c=[int(x) for x in s.split(".")[:3]];n=f"{a}.{b+1}.0";p.write_text(n+"\n");print(f"✅ bump minor: v{s} -> v{n}")' + +## bump-major: 主版本 +1(x.y.z -> x+1.0.0) +bump-major: + @python3 -c 'from pathlib import Path;p=Path("VERSION");s=p.read_text().strip() if p.exists() else "0.1.0";a,b,c=[int(x) for x in s.split(".")[:3]];n=f"{a+1}.0.0";p.write_text(n+"\n");print(f"✅ bump major: v{s} -> v{n}")' + +## release-plan: 显示发布参数预览 +release-plan: + @echo "APP_NAME=$(APP_NAME)" + @echo "VERSION=$(VERSION)" + @echo "RELEASE_TAG=$(RELEASE_TAG)" + @echo "DOCKER_IMAGE=$(DOCKER_IMAGE)" + @echo "DOCKER_TAG=$(DOCKER_TAG)" + @echo "ASSET=$(DIST_DIR)/$(ASSET_NAME)" + +## release-check: 发布前基础检查(工作区、版本格式) +release-check: + @test -z "$$(git status --porcelain)" || (echo "❌ git 工作区不干净,请先提交" && exit 1) + @echo "$(VERSION)" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$' || (echo "❌ VERSION 格式必须是 x.y.z" && exit 1) + @echo "✅ release-check passed (v$(VERSION))" + +## package-release: 产出发布二进制与 sha256 +package-release: + @mkdir -p $(DIST_DIR) + @CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/$(ASSET_NAME) cmd/main.go + @sha256sum $(DIST_DIR)/$(ASSET_NAME) > $(DIST_DIR)/$(ASSET_NAME).sha256 + @echo "✅ package ready: $(DIST_DIR)/$(ASSET_NAME)" + +## tag-release: 创建并推送 git tag(vX.Y.Z) +tag-release: + @git rev-parse -q --verify refs/tags/$(RELEASE_TAG) >/dev/null && (echo "❌ tag exists: $(RELEASE_TAG)" && exit 1) || true + @git tag -a $(RELEASE_TAG) -m "release: $(RELEASE_TAG)" + @git push origin $(RELEASE_TAG) + @echo "✅ pushed tag $(RELEASE_TAG)" + +## release: 本地发布编排(check + build + docker + package) +release: release-check build docker package-release + @echo "✅ release local artifacts ready for $(RELEASE_TAG)" + @echo " next: make docker-push && make tag-release" + ## help: 显示帮助 help: @echo "$(APP_NAME) v$(VERSION)" diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/config.yaml.example b/config.yaml.example index f9c5129..313d787 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -1,5 +1,5 @@ server: - port: 9521 + port: 9621 key: "your-secret-key-change-me" database: diff --git a/docker-compose.yml b/docker-compose.yml index 1a2fddd..d0fc616 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,12 @@ version: '3.8' services: - xiaji-go: - image: ouaone/xiaji-go:latest - container_name: xiaji-go + ops-assistant: + image: ouaone/ops-assistant:latest + container_name: ops-assistant restart: unless-stopped ports: - - "9521:9521" + - "9621:9621" volumes: - ./config.yaml:/app/config.yaml:ro - ./data:/app/data