Initial commit: Tencent DNSPod DNS deployment skill
- Support for single record deployment - Batch deployment from JSON config - Service quick deployment (Web/API/CDN) - .env file support for secure credentials - Complete documentation
This commit is contained in:
163
scripts/deploy_service.py
Executable file
163
scripts/deploy_service.py
Executable file
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
快速服务部署脚本
|
||||
一键部署常见服务的DNS配置(Web服务、API服务、CDN等)
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from deploy_record import deploy_record, load_env
|
||||
|
||||
# 加载 .env
|
||||
load_env()
|
||||
|
||||
def deploy_web_service(domain, ip, include_wildcard=False, line="默认", ttl=600):
|
||||
"""部署Web服务(主域名 + www + 可选泛域名)"""
|
||||
print(f"\n{'='*50}")
|
||||
print(f"部署Web服务: {domain}")
|
||||
print(f"目标IP: {ip}")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
success_count = 0
|
||||
total_count = 2 + (1 if include_wildcard else 0)
|
||||
|
||||
# 1. 主域名 @
|
||||
if deploy_record(domain, '@', 'A', ip, line, ttl, force=True, remark='主域名'):
|
||||
success_count += 1
|
||||
|
||||
# 2. www子域名
|
||||
if deploy_record(domain, 'www', 'A', ip, line, ttl, force=True, remark='Web服务'):
|
||||
success_count += 1
|
||||
|
||||
# 3. 泛域名 *(可选)
|
||||
if include_wildcard:
|
||||
if deploy_record(domain, '*', 'A', ip, line, ttl, force=True, remark='泛域名'):
|
||||
success_count += 1
|
||||
|
||||
print(f"\n{'='*50}")
|
||||
print(f"Web服务部署完成: {success_count}/{total_count} 成功")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
return success_count == total_count
|
||||
|
||||
def deploy_api_service(domain, ip, subdomain="api", line="默认", ttl=600):
|
||||
"""部署API服务"""
|
||||
print(f"\n{'='*50}")
|
||||
print(f"部署API服务: {subdomain}.{domain}")
|
||||
print(f"目标IP: {ip}")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
success = deploy_record(domain, subdomain, 'A', ip, line, ttl, force=True, remark='API服务')
|
||||
|
||||
print(f"\n{'='*50}")
|
||||
print(f"API服务部署{'成功' if success else '失败'}")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
return success
|
||||
|
||||
def deploy_cdn_service(domain, cdn_cname, subdomain="cdn", line="默认", ttl=600):
|
||||
"""部署CDN加速"""
|
||||
print(f"\n{'='*50}")
|
||||
print(f"部署CDN加速: {subdomain}.{domain}")
|
||||
print(f"CNAME: {cdn_cname}")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
success = deploy_record(domain, subdomain, 'CNAME', cdn_cname, line, ttl, force=True, remark='CDN加速')
|
||||
|
||||
print(f"\n{'='*50}")
|
||||
print(f"CDN部署{'成功' if success else '失败'}")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
return success
|
||||
|
||||
def deploy_mx_service(domain, mx_server, priority=10, line="默认"):
|
||||
"""部署邮件服务(MX记录)"""
|
||||
print(f"\n{'='*50}")
|
||||
print(f"部署邮件服务: {domain}")
|
||||
print(f"MX服务器: {mx_server}")
|
||||
print(f"优先级: {priority}")
|
||||
print(f"{'='*50}\n")
|
||||
|
||||
# 注意: MX记录需要特殊处理,这里简化处理
|
||||
# 实际需要调用MX专用的创建接口
|
||||
print(f"提示: MX记录部署需要手动配置")
|
||||
print(f" 记录类型: MX")
|
||||
print(f" 主机记录: @")
|
||||
print(f" 记录值: {mx_server}")
|
||||
print(f" 优先级: {priority}")
|
||||
print(f" 线路: {line}\n")
|
||||
|
||||
return True
|
||||
|
||||
def main():
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='快速服务部署', formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog='''
|
||||
服务类型:
|
||||
web - Web服务(@ + www)
|
||||
api - API服务(api子域名)
|
||||
cdn - CDN加速(CNAME记录)
|
||||
mx - 邮件服务(MX记录)
|
||||
|
||||
示例:
|
||||
# 部署Web服务
|
||||
%(prog)s --domain example.com --service web --ip 1.2.3.4
|
||||
|
||||
# 部署Web服务(含泛域名)
|
||||
%(prog)s --domain example.com --service web --ip 1.2.3.4 --wildcard
|
||||
|
||||
# 部署API服务
|
||||
%(prog)s --domain example.com --service api --ip 1.2.3.5 --subdomain api
|
||||
|
||||
# 部署CDN
|
||||
%(prog)s --domain example.com --service cdn --cname cdn.example.com.cdn.dnsv1.com
|
||||
|
||||
# 部署邮件服务
|
||||
%(prog)s --domain example.com --service mx --mx-server mx.example.com --priority 10
|
||||
''')
|
||||
|
||||
parser.add_argument('--domain', required=True, help='域名(如: example.com)')
|
||||
parser.add_argument('--service', required=True, choices=['web', 'api', 'cdn', 'mx'], help='服务类型')
|
||||
parser.add_argument('--ip', help='目标IP地址(A记录)')
|
||||
parser.add_argument('--cname', help='CNAME目标域名')
|
||||
parser.add_argument('--mx-server', help='MX服务器地址')
|
||||
parser.add_argument('--priority', type=int, default=10, help='MX优先级(默认: 10)')
|
||||
parser.add_argument('--subdomain', default='api', help='API子域名(默认: api)')
|
||||
parser.add_argument('--cdn-subdomain', default='cdn', help='CDN子域名(默认: cdn)')
|
||||
parser.add_argument('--line', default='默认', help='线路(默认: 默认)')
|
||||
parser.add_argument('--ttl', type=int, default=600, help='TTL(秒, 默认: 600)')
|
||||
parser.add_argument('--wildcard', action='store_true', help='Web服务是否添加泛域名解析(*.domain)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
success = False
|
||||
|
||||
if args.service == 'web':
|
||||
if not args.ip:
|
||||
print("错误: Web服务需要指定 --ip 参数")
|
||||
sys.exit(1)
|
||||
success = deploy_web_service(args.domain, args.ip, args.wildcard, args.line, args.ttl)
|
||||
|
||||
elif args.service == 'api':
|
||||
if not args.ip:
|
||||
print("错误: API服务需要指定 --ip 参数")
|
||||
sys.exit(1)
|
||||
success = deploy_api_service(args.domain, args.ip, args.subdomain, args.line, args.ttl)
|
||||
|
||||
elif args.service == 'cdn':
|
||||
if not args.cname:
|
||||
print("错误: CDN服务需要指定 --cname 参数")
|
||||
sys.exit(1)
|
||||
success = deploy_cdn_service(args.domain, args.cname, args.cdn_subdomain, args.line, args.ttl)
|
||||
|
||||
elif args.service == 'mx':
|
||||
if not args.mx_server:
|
||||
print("错误: 邮件服务需要指定 --mx-server 参数")
|
||||
sys.exit(1)
|
||||
success = deploy_mx_service(args.domain, args.mx_server, args.priority, args.line)
|
||||
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user