Merge branch 'dev' of https://gitea.airlabs.art/zyc/video-shuoshan into dev
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 4m39s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 4m39s
This commit is contained in:
commit
2e72c82116
@ -49,28 +49,45 @@ jobs:
|
|||||||
id: build_backend
|
id: build_backend
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
echo "Build backend attempt $attempt/3..."
|
||||||
DOCKER_BUILDKIT=0 docker build \
|
DOCKER_BUILDKIT=0 docker build \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:${{ env.IMAGE_TAG }} \
|
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:${{ env.IMAGE_TAG }} \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest \
|
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest \
|
||||||
./backend 2>&1 | tee /tmp/build.log
|
./backend 2>&1 | tee /tmp/build.log && break
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:${{ env.IMAGE_TAG }}
|
echo "Attempt $attempt failed, retrying in 10s..." && sleep 10
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest
|
done
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:${{ env.IMAGE_TAG }} && \
|
||||||
|
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest && break
|
||||||
|
echo "Push attempt $attempt failed, retrying in 10s..." && sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
- name: Build and Push Web
|
- name: Build and Push Web
|
||||||
id: build_web
|
id: build_web
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
echo "Build web attempt $attempt/3..."
|
||||||
DOCKER_BUILDKIT=0 docker build \
|
DOCKER_BUILDKIT=0 docker build \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:${{ env.IMAGE_TAG }} \
|
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:${{ env.IMAGE_TAG }} \
|
||||||
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest \
|
--tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest \
|
||||||
./web 2>&1 | tee -a /tmp/build.log
|
./web 2>&1 | tee -a /tmp/build.log && break
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:${{ env.IMAGE_TAG }}
|
echo "Attempt $attempt failed, retrying in 10s..." && sleep 10
|
||||||
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest
|
done
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:${{ env.IMAGE_TAG }} && \
|
||||||
|
docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest && break
|
||||||
|
echo "Push attempt $attempt failed, retrying in 10s..." && sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
- name: Setup Kubectl
|
- name: Setup Kubectl
|
||||||
run: |
|
run: |
|
||||||
if ! command -v kubectl &>/dev/null; then
|
if ! command -v kubectl &>/dev/null; then
|
||||||
curl -LO "https://mirrors.aliyun.com/kubernetes/kubectl/v1.28.0/bin/linux/amd64/kubectl"
|
for attempt in 1 2 3; do
|
||||||
|
curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl" && break
|
||||||
|
echo "Download attempt $attempt failed, retrying in 5s..." && sleep 5
|
||||||
|
done
|
||||||
chmod +x kubectl && mv kubectl /usr/local/bin/
|
chmod +x kubectl && mv kubectl /usr/local/bin/
|
||||||
fi
|
fi
|
||||||
kubectl version --client
|
kubectl version --client
|
||||||
@ -79,11 +96,13 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p $HOME/.kube
|
mkdir -p $HOME/.kube
|
||||||
if [[ "${{ github.ref_name }}" == "master" ]]; then
|
if [[ "${{ github.ref_name }}" == "master" ]]; then
|
||||||
echo "${{ secrets.VOLCANO_PROD_KUBE_CONFIG }}" > $HOME/.kube/config
|
printf '%s\n' '${{ secrets.VOLCANO_PROD_KUBE_CONFIG }}' > $HOME/.kube/config
|
||||||
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
|
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
|
||||||
echo "${{ secrets.VOLCANO_TEST_KUBE_CONFIG }}" > $HOME/.kube/config
|
printf '%s\n' '${{ secrets.VOLCANO_TEST_KUBE_CONFIG }}' > $HOME/.kube/config
|
||||||
fi
|
fi
|
||||||
chmod 600 $HOME/.kube/config
|
chmod 600 $HOME/.kube/config
|
||||||
|
echo "kubeconfig lines: $(wc -l < $HOME/.kube/config)"
|
||||||
|
grep server $HOME/.kube/config || echo "WARNING: no server found in kubeconfig"
|
||||||
|
|
||||||
- name: Deploy to K3s
|
- name: Deploy to K3s
|
||||||
id: deploy
|
id: deploy
|
||||||
@ -113,6 +132,10 @@ jobs:
|
|||||||
sed -i "s|redis://zyc:Zyc188208@redis-shzlsczo52dft8mia.redis.ivolces.com:6379/0|${{ env.REDIS_URL }}|g" k8s/backend-deployment.yaml
|
sed -i "s|redis://zyc:Zyc188208@redis-shzlsczo52dft8mia.redis.ivolces.com:6379/0|${{ env.REDIS_URL }}|g" k8s/backend-deployment.yaml
|
||||||
sed -i "s|redis://zyc:Zyc188208@redis-shzlsczo52dft8mia.redis.ivolces.com:6379/0|${{ env.REDIS_URL }}|g" k8s/celery-deployment.yaml
|
sed -i "s|redis://zyc:Zyc188208@redis-shzlsczo52dft8mia.redis.ivolces.com:6379/0|${{ env.REDIS_URL }}|g" k8s/celery-deployment.yaml
|
||||||
|
|
||||||
|
# All kubectl operations with retry (K3s 内网连接可能抖动)
|
||||||
|
for attempt in 1 2 3; do
|
||||||
|
echo "Deploy attempt $attempt/3..."
|
||||||
|
{
|
||||||
# Create/update image pull secret for CR
|
# Create/update image pull secret for CR
|
||||||
kubectl create secret docker-registry cr-pull-secret \
|
kubectl create secret docker-registry cr-pull-secret \
|
||||||
--docker-server="${{ env.CR_SERVER_ACTIVE }}" \
|
--docker-server="${{ env.CR_SERVER_ACTIVE }}" \
|
||||||
@ -131,8 +154,6 @@ jobs:
|
|||||||
--dry-run=client -o yaml | kubectl apply -f -
|
--dry-run=client -o yaml | kubectl apply -f -
|
||||||
|
|
||||||
# Apply manifests
|
# Apply manifests
|
||||||
set -o pipefail
|
|
||||||
{
|
|
||||||
kubectl apply -f k8s/backend-deployment.yaml
|
kubectl apply -f k8s/backend-deployment.yaml
|
||||||
kubectl apply -f k8s/celery-deployment.yaml
|
kubectl apply -f k8s/celery-deployment.yaml
|
||||||
kubectl apply -f k8s/web-deployment.yaml
|
kubectl apply -f k8s/web-deployment.yaml
|
||||||
@ -144,7 +165,10 @@ jobs:
|
|||||||
kubectl rollout restart deployment/video-backend
|
kubectl rollout restart deployment/video-backend
|
||||||
kubectl rollout restart deployment/celery-worker
|
kubectl rollout restart deployment/celery-worker
|
||||||
kubectl rollout restart deployment/video-web
|
kubectl rollout restart deployment/video-web
|
||||||
} 2>&1 | tee /tmp/deploy.log
|
} 2>&1 | tee /tmp/deploy.log && break
|
||||||
|
echo "Attempt $attempt failed, retrying in 10s..."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
# ===== Log Center: failure reporting =====
|
# ===== Log Center: failure reporting =====
|
||||||
- name: Report failure to Log Center
|
- name: Report failure to Log Center
|
||||||
@ -204,3 +228,13 @@ jobs:
|
|||||||
\"run_url\": \"https://gitea.airlabs.art/${{ github.repository }}/actions/runs/${{ github.run_number }}\"
|
\"run_url\": \"https://gitea.airlabs.art/${{ github.repository }}/actions/runs/${{ github.run_number }}\"
|
||||||
}
|
}
|
||||||
}" || true
|
}" || true
|
||||||
|
|
||||||
|
# ===== Cleanup: remove unused Docker resources =====
|
||||||
|
- name: Docker Cleanup
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
docker container prune -f
|
||||||
|
docker image prune -a -f
|
||||||
|
docker builder prune -a -f
|
||||||
|
echo "Disk usage after cleanup:"
|
||||||
|
df -h / | tail -1
|
||||||
|
|||||||
@ -30,4 +30,4 @@ RUN chmod +x /app/entrypoint.sh
|
|||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "config.wsgi:application"]
|
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--worker-class", "gevent", "--worker-connections", "200", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "config.wsgi:application"]
|
||||||
|
|||||||
@ -21,19 +21,29 @@ def poll_video_task(self, record_id):
|
|||||||
from apps.generation.models import GenerationRecord
|
from apps.generation.models import GenerationRecord
|
||||||
from utils.airdrama_client import query_task, map_status
|
from utils.airdrama_client import query_task, map_status
|
||||||
|
|
||||||
|
# 防重复:同一 record 同一时刻只允许一个 poll 在执行
|
||||||
|
from django.core.cache import cache
|
||||||
|
lock_key = f'poll_lock:{record_id}'
|
||||||
|
if not cache.add(lock_key, '1', timeout=POLL_INTERVAL * 3):
|
||||||
|
logger.info('poll_video_task: record %s already being polled, skipping', record_id)
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
record = GenerationRecord.objects.get(pk=record_id)
|
record = GenerationRecord.objects.get(pk=record_id)
|
||||||
except GenerationRecord.DoesNotExist:
|
except GenerationRecord.DoesNotExist:
|
||||||
logger.warning('poll_video_task: record %s not found', record_id)
|
logger.warning('poll_video_task: record %s not found', record_id)
|
||||||
|
cache.delete(lock_key)
|
||||||
return
|
return
|
||||||
|
|
||||||
ark_task_id = record.ark_task_id
|
ark_task_id = record.ark_task_id
|
||||||
if not ark_task_id:
|
if not ark_task_id:
|
||||||
logger.warning('poll_video_task: record %s has no ark_task_id', record_id)
|
logger.warning('poll_video_task: record %s has no ark_task_id', record_id)
|
||||||
|
cache.delete(lock_key)
|
||||||
return
|
return
|
||||||
|
|
||||||
if record.status not in ('queued', 'processing'):
|
if record.status not in ('queued', 'processing'):
|
||||||
logger.info('poll_video_task: record %s already in terminal state: %s', record_id, record.status)
|
logger.info('poll_video_task: record %s already in terminal state: %s', record_id, record.status)
|
||||||
|
cache.delete(lock_key)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Poll Volcano API
|
# Poll Volcano API
|
||||||
@ -42,12 +52,14 @@ def poll_video_task(self, record_id):
|
|||||||
new_status = map_status(ark_resp.get('status', ''))
|
new_status = map_status(ark_resp.get('status', ''))
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('poll_video_task: API query failed for %s, will retry', ark_task_id)
|
logger.exception('poll_video_task: API query failed for %s, will retry', ark_task_id)
|
||||||
|
cache.delete(lock_key)
|
||||||
raise self.retry(countdown=POLL_INTERVAL)
|
raise self.retry(countdown=POLL_INTERVAL)
|
||||||
|
|
||||||
if new_status in ('queued', 'processing'):
|
if new_status in ('queued', 'processing'):
|
||||||
# Still running — update status, then re-enqueue
|
# Still running — update status, then re-enqueue
|
||||||
record.status = new_status
|
record.status = new_status
|
||||||
record.save(update_fields=['status', 'updated_at'])
|
record.save(update_fields=['status', 'updated_at'])
|
||||||
|
cache.delete(lock_key)
|
||||||
raise self.retry(countdown=POLL_INTERVAL)
|
raise self.retry(countdown=POLL_INTERVAL)
|
||||||
|
|
||||||
# Terminal state reached — process result
|
# Terminal state reached — process result
|
||||||
|
|||||||
@ -189,7 +189,7 @@ CELERY_BEAT_SCHEDULE = {
|
|||||||
LANGUAGE_CODE = 'zh-hans'
|
LANGUAGE_CODE = 'zh-hans'
|
||||||
TIME_ZONE = 'Asia/Shanghai'
|
TIME_ZONE = 'Asia/Shanghai'
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
USE_TZ = True
|
USE_TZ = False
|
||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user