mirror of
https://github.com/woodchen-ink/dnspod-yxip.git
synced 2025-07-18 13:52:10 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
7126e14dfa | |||
94a1186125 | |||
b78c62bd2d | |||
544ef2af63 | |||
c39781d4dc | |||
857dd3a0cd |
41
.github/workflows/docker-publish-arm.yml
vendored
Normal file
41
.github/workflows/docker-publish-arm.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
name: Docker
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths-ignore: [ '**.md' ]
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE_NAME: dnspod-yxip
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: woodchen
|
||||||
|
password: ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: woodchen/${{ env.IMAGE_NAME }}:arm
|
||||||
|
platforms: linux/arm64
|
2
.github/workflows/docker-publish.yml
vendored
2
.github/workflows/docker-publish.yml
vendored
@ -38,4 +38,4 @@ jobs:
|
|||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: woodchen/${{ env.IMAGE_NAME }}:latest
|
tags: woodchen/${{ env.IMAGE_NAME }}:latest
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64
|
@ -18,7 +18,7 @@ COPY main.py .
|
|||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
# 创建配置文件和日志目录
|
# 创建配置文件和日志目录
|
||||||
RUN mkdir -p logs && touch .env
|
RUN mkdir -p logs && touch config.yaml
|
||||||
|
|
||||||
# 运行程序
|
# 运行程序
|
||||||
CMD ["python", "main.py"]
|
CMD ["python", "main.py"]
|
20
config.py
20
config.py
@ -1,15 +1,29 @@
|
|||||||
import os
|
import os
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
import yaml
|
import yaml
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
# 加载YAML配置
|
# 加载YAML配置
|
||||||
def load_config() -> Dict:
|
def load_config() -> Dict:
|
||||||
"""从YAML文件加载配置"""
|
"""从YAML文件加载配置"""
|
||||||
yaml_files = ["config.yaml", "config.example.yaml"]
|
yaml_files = ["config.yaml"]
|
||||||
for yaml_file in yaml_files:
|
for yaml_file in yaml_files:
|
||||||
if os.path.exists(yaml_file):
|
if os.path.exists(yaml_file):
|
||||||
with open(yaml_file, "r", encoding="utf-8") as f:
|
try:
|
||||||
return yaml.safe_load(f)
|
with open(yaml_file, "r", encoding="utf-8") as f:
|
||||||
|
config = yaml.safe_load(f)
|
||||||
|
logger.info(f"成功加载配置文件: {yaml_file}")
|
||||||
|
# 验证必要的配置项
|
||||||
|
if not config.get("tencent", {}).get("secret_id"):
|
||||||
|
logger.error(f"配置文件 {yaml_file} 中缺少必要的配置项: tencent.secret_id")
|
||||||
|
return {}
|
||||||
|
if not config.get("tencent", {}).get("secret_key"):
|
||||||
|
logger.error(f"配置文件 {yaml_file} 中缺少必要的配置项: tencent.secret_key")
|
||||||
|
return {}
|
||||||
|
return config
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"加载配置文件 {yaml_file} 失败: {str(e)}")
|
||||||
|
logger.error("未找到有效的配置文件")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# 加载配置
|
# 加载配置
|
||||||
|
30
main.py
30
main.py
@ -222,20 +222,32 @@ class DNSPodManager:
|
|||||||
else: # Linux/Unix系统
|
else: # Linux/Unix系统
|
||||||
ping_args = ['ping', '-c', '1', '-W', '1', ip]
|
ping_args = ['ping', '-c', '1', '-W', '1', ip]
|
||||||
|
|
||||||
result = subprocess.run(ping_args,
|
# 最多尝试3次ping
|
||||||
capture_output=True,
|
max_retries = 3
|
||||||
text=True)
|
for attempt in range(max_retries):
|
||||||
available = result.returncode == 0
|
result = subprocess.run(ping_args,
|
||||||
|
capture_output=True,
|
||||||
|
text=True)
|
||||||
|
if result.returncode == 0:
|
||||||
|
# 更新缓存
|
||||||
|
self.ip_availability_cache[ip] = {
|
||||||
|
'available': True,
|
||||||
|
'last_check': now
|
||||||
|
}
|
||||||
|
return True
|
||||||
|
|
||||||
|
# 如果不是最后一次尝试,等待短暂时间后重试
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
time.sleep(1) # 等待1秒后重试
|
||||||
|
|
||||||
|
# 所有尝试都失败
|
||||||
|
logger.warning(f"IP {ip} ping测试失败(尝试{max_retries}次),最后一次命令输出:{result.stdout if result.stdout else result.stderr}")
|
||||||
# 更新缓存
|
# 更新缓存
|
||||||
self.ip_availability_cache[ip] = {
|
self.ip_availability_cache[ip] = {
|
||||||
'available': available,
|
'available': False,
|
||||||
'last_check': now
|
'last_check': now
|
||||||
}
|
}
|
||||||
|
return False
|
||||||
if not available:
|
|
||||||
logger.warning(f"IP {ip} ping测试失败,命令输出:{result.stdout if result.stdout else result.stderr}")
|
|
||||||
return available
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Ping测试出错 - IP: {ip}, 错误信息: {str(e)}, 命令参数: {ping_args}")
|
logger.error(f"Ping测试出错 - IP: {ip}, 错误信息: {str(e)}, 命令参数: {ping_args}")
|
||||||
return False
|
return False
|
||||||
|
21
readme.md
21
readme.md
@ -33,25 +33,6 @@ cp config.example.yaml config.yaml
|
|||||||
```
|
```
|
||||||
|
|
||||||
2. 编辑 `config.yaml` 文件,填写您的配置:
|
2. 编辑 `config.yaml` 文件,填写您的配置:
|
||||||
```yaml
|
|
||||||
# 腾讯云API配置
|
|
||||||
tencent:
|
|
||||||
secret_id: your_secret_id_here
|
|
||||||
secret_key: your_secret_key_here
|
|
||||||
|
|
||||||
# 日志级别
|
|
||||||
log_level: INFO
|
|
||||||
|
|
||||||
# 域名配置列表
|
|
||||||
domains:
|
|
||||||
- domain: example1.com
|
|
||||||
sub_domain: "@" # 子域名,@ 表示根域名
|
|
||||||
remark: 优选IP # 记录备注
|
|
||||||
ttl: 600 # TTL值(秒)
|
|
||||||
ipv4_enabled: true # 是否启用IPv4记录
|
|
||||||
ipv6_enabled: true # 是否启用IPv6记录
|
|
||||||
enabled: true # 是否启用此域名配置
|
|
||||||
```
|
|
||||||
|
|
||||||
3. 拉取并运行容器:
|
3. 拉取并运行容器:
|
||||||
```bash
|
```bash
|
||||||
@ -63,7 +44,7 @@ docker compose up -d
|
|||||||
|
|
||||||
1. 克隆仓库:
|
1. 克隆仓库:
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/your-username/dnspod-yxip.git
|
git clone https://github.com/woodchen-ink/dnspod-yxip.git
|
||||||
cd dnspod-yxip
|
cd dnspod-yxip
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user