mirror of
https://github.com/woodchen-ink/dnspod-yxip.git
synced 2025-07-19 14:22:07 +08:00
Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
41
.github/workflows/docker-publish-arm.yml
vendored
41
.github/workflows/docker-publish-arm.yml
vendored
@ -1,41 +0,0 @@
|
|||||||
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
|
platforms: linux/amd64,linux/arm64
|
@ -18,7 +18,7 @@ COPY main.py .
|
|||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
# 创建配置文件和日志目录
|
# 创建配置文件和日志目录
|
||||||
RUN mkdir -p logs && touch config.yaml
|
RUN mkdir -p logs && touch .env
|
||||||
|
|
||||||
# 运行程序
|
# 运行程序
|
||||||
CMD ["python", "main.py"]
|
CMD ["python", "main.py"]
|
18
config.py
18
config.py
@ -1,29 +1,15 @@
|
|||||||
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"]
|
yaml_files = ["config.yaml", "config.example.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):
|
||||||
try:
|
|
||||||
with open(yaml_file, "r", encoding="utf-8") as f:
|
with open(yaml_file, "r", encoding="utf-8") as f:
|
||||||
config = yaml.safe_load(f)
|
return 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 {}
|
||||||
|
|
||||||
# 加载配置
|
# 加载配置
|
||||||
|
24
main.py
24
main.py
@ -222,32 +222,20 @@ class DNSPodManager:
|
|||||||
else: # Linux/Unix系统
|
else: # Linux/Unix系统
|
||||||
ping_args = ['ping', '-c', '1', '-W', '1', ip]
|
ping_args = ['ping', '-c', '1', '-W', '1', ip]
|
||||||
|
|
||||||
# 最多尝试3次ping
|
|
||||||
max_retries = 3
|
|
||||||
for attempt in range(max_retries):
|
|
||||||
result = subprocess.run(ping_args,
|
result = subprocess.run(ping_args,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True)
|
text=True)
|
||||||
if result.returncode == 0:
|
available = result.returncode == 0
|
||||||
|
|
||||||
# 更新缓存
|
# 更新缓存
|
||||||
self.ip_availability_cache[ip] = {
|
self.ip_availability_cache[ip] = {
|
||||||
'available': True,
|
'available': available,
|
||||||
'last_check': now
|
'last_check': now
|
||||||
}
|
}
|
||||||
return True
|
|
||||||
|
|
||||||
# 如果不是最后一次尝试,等待短暂时间后重试
|
if not available:
|
||||||
if attempt < max_retries - 1:
|
logger.warning(f"IP {ip} ping测试失败,命令输出:{result.stdout if result.stdout else result.stderr}")
|
||||||
time.sleep(1) # 等待1秒后重试
|
return available
|
||||||
|
|
||||||
# 所有尝试都失败
|
|
||||||
logger.warning(f"IP {ip} ping测试失败(尝试{max_retries}次),最后一次命令输出:{result.stdout if result.stdout else result.stderr}")
|
|
||||||
# 更新缓存
|
|
||||||
self.ip_availability_cache[ip] = {
|
|
||||||
'available': False,
|
|
||||||
'last_check': now
|
|
||||||
}
|
|
||||||
return False
|
|
||||||
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,6 +33,25 @@ 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
|
||||||
@ -44,7 +63,7 @@ docker compose up -d
|
|||||||
|
|
||||||
1. 克隆仓库:
|
1. 克隆仓库:
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/woodchen-ink/dnspod-yxip.git
|
git clone https://github.com/your-username/dnspod-yxip.git
|
||||||
cd dnspod-yxip
|
cd dnspod-yxip
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user