accounts/Makefile

218 lines
6.0 KiB
Makefile
Raw Permalink Normal View History

# =========================================
# 📦 XControl Account Service Makefile
# =========================================
APP_NAME := xcontrol-account
MAIN_FILE := ./cmd/accountsvc/main.go
PORT ?= 8080
OS := $(shell uname -s)
# Load local environment overrides if present.
-include .env
export
DB_NAME := account
DB_USER ?= $(or $(POSTGRES_USER),postgres)
DB_PASS ?= $(or $(POSTGRES_PASSWORD),password)
DB_HOST := 127.0.0.1
2026-01-24 22:42:40 +08:00
DB_PORT := 15432
DB_URL := postgres://$(DB_USER):$(DB_PASS)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable
REPLICATION_MODE ?= pgsync
DB_ADMIN_USER ?= $(DB_USER)
DB_ADMIN_PASS ?= $(DB_PASS)
GCP_PROJECT ?=
GCP_REGION ?= asia-northeast1
CLOUD_RUN_SERVICE ?= accounts-svc-plus
CLOUD_RUN_SERVICE_YAML ?= deploy/gcp/cloud-run/service.yaml
CLOUD_RUN_STUNNEL_CONF ?= deploy/gcp/cloud-run/stunnel.conf
CLOUD_RUN_IMAGE ?= $(GCP_REGION)-docker.pkg.dev/$(GCP_PROJECT)/cloud-run-source-deploy/accounts.svc.plus/accounts-svc-plus:latest
SCHEMA_FILE := ./sql/schema.sql
PGLOGICAL_INIT_FILE := ./sql/schema_pglogical_init.sql
PGLOGICAL_PATCH_FILE := ./sql/schema_pglogical_patch.sql
PGLOGICAL_REGION_FILE := ./sql/schema_pglogical_region.sql
ACCOUNT_EXPORT_FILE ?= account-export.yaml
ACCOUNT_IMPORT_FILE ?= account-export.yaml
ACCOUNT_EMAIL_KEYWORD ?=
ACCOUNT_SYNC_CONFIG ?= config/sync.yaml
SUPERADMIN_USERNAME ?= Admin
SUPERADMIN_PASSWORD ?= ChangeMe
SUPERADMIN_EMAIL ?= admin@svc.plus
export PATH := /usr/local/go/bin:$(PATH)
2026-01-24 22:36:29 +08:00
export APP_NAME MAIN_FILE PORT OS \
DB_NAME DB_USER DB_PASS DB_HOST DB_PORT DB_URL \
REPLICATION_MODE DB_ADMIN_USER DB_ADMIN_PASS \
GCP_PROJECT GCP_REGION CLOUD_RUN_SERVICE CLOUD_RUN_SERVICE_YAML CLOUD_RUN_STUNNEL_CONF CLOUD_RUN_IMAGE \
SCHEMA_FILE PGLOGICAL_INIT_FILE PGLOGICAL_PATCH_FILE PGLOGICAL_REGION_FILE \
ACCOUNT_EXPORT_FILE ACCOUNT_IMPORT_FILE ACCOUNT_EMAIL_KEYWORD ACCOUNT_SYNC_CONFIG \
SUPERADMIN_USERNAME SUPERADMIN_PASSWORD SUPERADMIN_EMAIL \
ACCOUNT_IMPORT_MERGE ACCOUNT_IMPORT_MERGE_STRATEGY ACCOUNT_IMPORT_DRY_RUN \
ACCOUNT_IMPORT_MERGE_ALLOWLIST ACCOUNT_IMPORT_EXTRA_FLAGS
# =========================================
# 🧩 基础命令
# =========================================
.PHONY: all init build clean start stop restart dev test help integration-test \
2026-01-24 22:36:29 +08:00
init-go init-db init-db-core init-db-replication init-db-pglogical \
stunnel-start \
reinit-pglogical account-sync-push account-sync-pull account-sync-mirror create-db-user db-reset \
cloudrun-build cloudrun-deploy cloudrun-stunnel
all: build
help:
@echo "🧭 XControl Account Service Makefile"
@echo "make init 初始化 Go 环境与数据库"
@echo "make init-db 执行数据库 schema支持 REPLICATION_MODE=pgsync|pglogical"
@echo "make create-db-user 创建数据库用户并授权"
@echo "make db-reset 重置整个 PostgreSQL 集群 (危险操作!)"
@echo "make migrate-db 执行数据库迁移"
@echo "make dump-schema 导出数据库 schema"
@echo "make account-export 导出账号数据为 YAML"
@echo "make account-import 从 YAML 导入账号数据"
@echo "make create-super-admin 创建超级管理员"
@echo "make reinit-db 重置业务 schema (不涉及 pglogical)"
@echo "make reinit-pglogical 重新初始化 pglogical schema"
@echo "make dev 热重载开发模式"
@echo "make clean 清理构建产物"
@echo "make integration-test 运行集成测试用例(初始化 + 创建管理员)"
@echo "make cloudrun-build 构建并推送 Cloud Run 镜像"
@echo "make cloudrun-deploy 部署 Cloud Run Service"
@echo "make cloudrun-stunnel 更新 Cloud Run stunnel 配置 secret"
# =========================================
# 🧰 初始化
# =========================================
init: init-go init-db
init-go:
2026-01-24 22:36:29 +08:00
@bash scripts/init-go.sh
2025-08-07 13:26:02 +08:00
init-db:
2026-01-24 22:36:29 +08:00
@bash scripts/init-db.sh
init-db-core:
2026-01-24 22:36:29 +08:00
@bash scripts/init-db-core.sh
init-db-replication:
2026-01-24 22:36:29 +08:00
@bash scripts/init-db-replication.sh
init-db-pglogical:
2026-01-24 22:36:29 +08:00
@bash scripts/init-db-pglogical.sh
# =========================================
# 🧠 PGLogical 双节点初始化
# =========================================
init-pglogical-region:
2026-01-24 22:36:29 +08:00
@bash scripts/init-pglogical-region.sh
init-pglogical-region-cn:
2026-01-24 22:36:29 +08:00
@bash scripts/init-pglogical-region-cn.sh
init-pglogical-region-global:
2026-01-24 22:36:29 +08:00
@bash scripts/init-pglogical-region-global.sh
# =========================================
# 📦 数据库迁移与管理
# =========================================
create-db-user:
2026-01-24 22:36:29 +08:00
@bash scripts/create-db-user.sh
migrate-db:
2026-01-24 22:36:29 +08:00
@bash scripts/migrate-db.sh
dump-schema:
2026-01-24 22:36:29 +08:00
@bash scripts/dump-schema.sh
db-reset:
2026-01-24 22:36:29 +08:00
@bash scripts/db-reset.sh
drop-db:
2026-01-24 22:36:29 +08:00
@bash scripts/drop-db.sh
reset-public-schema:
2026-01-24 22:36:29 +08:00
@bash scripts/reset-public-schema.sh
reinit-db:
2026-01-24 22:36:29 +08:00
@bash scripts/reinit-db.sh
reinit-pglogical:
2026-01-24 22:36:29 +08:00
@bash scripts/reinit-pglogical.sh
stunnel-start:
@bash scripts/stunnel-start.sh
# =========================================
# 💾 账号导入导出
# =========================================
account-export:
2026-01-24 22:36:29 +08:00
@bash scripts/account-export.sh
account-import:
2026-01-24 22:36:29 +08:00
@bash scripts/account-import.sh
account-sync-push:
2026-01-24 22:36:29 +08:00
@bash scripts/account-sync-push.sh
account-sync-pull:
2026-01-24 22:36:29 +08:00
@bash scripts/account-sync-pull.sh
account-sync-mirror:
2026-01-24 22:36:29 +08:00
@bash scripts/account-sync-mirror.sh
create-super-admin:
2026-01-24 22:36:29 +08:00
@bash scripts/create-super-admin.sh
integration-test:
@bash integration-test/superadmin-login/run-test-scripts.sh
# =========================================
# ⚙️ 编译与运行
# =========================================
build: init-go
2026-01-24 22:36:29 +08:00
@bash scripts/build.sh
upgrade: build
2026-01-24 22:36:29 +08:00
@bash scripts/upgrade.sh
start: build
2026-01-24 22:36:29 +08:00
@bash scripts/start.sh
stop:
2026-01-24 22:36:29 +08:00
@bash scripts/stop.sh
restart: stop start
test:
2026-01-24 22:36:29 +08:00
@bash scripts/test.sh
clean:
2026-01-24 22:36:29 +08:00
@bash scripts/clean.sh
dev:
@bash scripts/dev.sh
# =========================================
# ☁️ GCP Cloud Run
# =========================================
cloudrun-build:
2026-01-24 22:36:29 +08:00
@bash scripts/cloudrun-build.sh
cloudrun-deploy:
2026-01-24 22:36:29 +08:00
@bash scripts/cloudrun-deploy.sh
cloudrun-stunnel:
2026-01-24 22:36:29 +08:00
@bash scripts/cloudrun-stunnel.sh