This commit is contained in:
@@ -40,6 +40,19 @@ jobs:
|
||||
git pull
|
||||
fi
|
||||
|
||||
# 3.1 创建/更新 .env 文件 (从本地环境变量注入)
|
||||
echo -e "\n===== 配置环境变量 ====="
|
||||
cat > backend/.env <<EOF
|
||||
# Aliyun OSS Configuration
|
||||
ALIYUN_ACCESS_KEY_ID=LTAI5tE62GW8MKyoEaotzxXk
|
||||
ALIYUN_ACCESS_KEY_SECRET=Zdzqo1fgj57DxxioXOotNKhJdSfVQW
|
||||
ALIYUN_OSS_ENDPOINT=https://oss-cn-shanghai.aliyuncs.com
|
||||
ALIYUN_OSS_BUCKET_NAME=tangledup-ai-staging
|
||||
ALIYUN_OSS_INTERNAL_ENDPOINT=https://oss-cn-shanghai-internal.aliyuncs.com
|
||||
# Aliyun Tingwu Configuration
|
||||
ALIYUN_TINGWU_APP_KEY=6eOX7N3tKE0fDwb
|
||||
EOF
|
||||
|
||||
# 4. 重新启动 Docker 容器
|
||||
echo -e "\n===== 启动 Docker 容器 ====="
|
||||
echo $SUDO_PASSWORD | sudo -S docker compose up -d --build
|
||||
|
||||
@@ -14,6 +14,7 @@ RUN pip install --upgrade pip && pip install -r requirements.txt
|
||||
|
||||
# Copy project
|
||||
COPY . /app/
|
||||
COPY .env /app/
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
0
backend/ai_services/management/__init__.py
Normal file
0
backend/ai_services/management/__init__.py
Normal file
0
backend/ai_services/management/commands/__init__.py
Normal file
0
backend/ai_services/management/commands/__init__.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
import oss2
|
||||
from aliyunsdkcore.client import AcsClient
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Check Aliyun configuration status'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write("Checking Aliyun Configuration...")
|
||||
|
||||
configs = {
|
||||
'ALIYUN_ACCESS_KEY_ID': settings.ALIYUN_ACCESS_KEY_ID,
|
||||
'ALIYUN_ACCESS_KEY_SECRET': settings.ALIYUN_ACCESS_KEY_SECRET,
|
||||
'ALIYUN_OSS_BUCKET_NAME': settings.ALIYUN_OSS_BUCKET_NAME,
|
||||
'ALIYUN_OSS_ENDPOINT': settings.ALIYUN_OSS_ENDPOINT,
|
||||
'ALIYUN_TINGWU_APP_KEY': settings.ALIYUN_TINGWU_APP_KEY,
|
||||
}
|
||||
|
||||
all_valid = True
|
||||
for key, value in configs.items():
|
||||
if not value:
|
||||
self.stdout.write(self.style.ERROR(f"[MISSING] {key} is not set or empty"))
|
||||
all_valid = False
|
||||
else:
|
||||
masked_value = value[:4] + "****" + value[-4:] if len(value) > 8 else "****"
|
||||
self.stdout.write(self.style.SUCCESS(f"[OK] {key}: {masked_value}"))
|
||||
|
||||
if not all_valid:
|
||||
self.stdout.write(self.style.ERROR("\nConfiguration check FAILED. Some required settings are missing."))
|
||||
return
|
||||
|
||||
# Test OSS Connection
|
||||
self.stdout.write("\nTesting OSS Connection...")
|
||||
try:
|
||||
auth = oss2.Auth(configs['ALIYUN_ACCESS_KEY_ID'], configs['ALIYUN_ACCESS_KEY_SECRET'])
|
||||
bucket = oss2.Bucket(auth, configs['ALIYUN_OSS_ENDPOINT'], configs['ALIYUN_OSS_BUCKET_NAME'])
|
||||
bucket.get_bucket_info()
|
||||
self.stdout.write(self.style.SUCCESS("[OK] OSS Connection successful"))
|
||||
except Exception as e:
|
||||
self.stdout.write(self.style.ERROR(f"[FAILED] OSS Connection failed: {e}"))
|
||||
|
||||
# Test Tingwu Client Initialization
|
||||
self.stdout.write("\nTesting Tingwu Client Initialization...")
|
||||
try:
|
||||
client = AcsClient(
|
||||
configs['ALIYUN_ACCESS_KEY_ID'],
|
||||
configs['ALIYUN_ACCESS_KEY_SECRET'],
|
||||
"cn-beijing"
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS("[OK] Tingwu Client initialized"))
|
||||
except Exception as e:
|
||||
self.stdout.write(self.style.ERROR(f"[FAILED] Tingwu Client init failed: {e}"))
|
||||
|
||||
Reference in New Issue
Block a user