fix: 使用本地Docker构建方式,无需远程镜像仓库
Some checks failed
continuous-integration/drone/push Build is failing

- 改为挂载 docker.sock 本地构建
- 删除 docker_username/password secrets
- 添加 database_url, redis_* secrets
- 与其他项目配置方式保持一致
This commit is contained in:
111
2026-01-24 19:38:01 +08:00
parent 998211c483
commit e49b75e483

View File

@@ -1,9 +1,7 @@
---
kind: pipeline
type: docker
name: test-deploy
name: build-and-deploy
# 仅在 test 分支触发测试环境部署
trigger:
branch:
- test
@@ -11,120 +9,84 @@ trigger:
- push
steps:
# Step 1: 构建后端镜像
# 构建后端镜像
- name: build-backend
image: plugins/docker
settings:
registry: registry.cn-shenzhen.aliyuncs.com
repo: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-backend
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: backend/Dockerfile
context: backend
tags:
- test
- ${DRONE_COMMIT_SHA:0:8}
image: docker:dind
volumes:
- name: docker-sock
path: /var/run/docker.sock
commands:
- cd backend
- docker build -t kaopeilian-backend:${DRONE_COMMIT_SHA:0:8} -f Dockerfile .
- docker tag kaopeilian-backend:${DRONE_COMMIT_SHA:0:8} kaopeilian-backend:test
# Step 2: 构建前端镜像
# 构建前端镜像
- name: build-frontend
image: plugins/docker
settings:
registry: registry.cn-shenzhen.aliyuncs.com
repo: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-frontend
username:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: frontend/Dockerfile
context: frontend
tags:
- test
- ${DRONE_COMMIT_SHA:0:8}
image: docker:dind
volumes:
- name: docker-sock
path: /var/run/docker.sock
commands:
- cd frontend
- docker build -t kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8} -f Dockerfile --build-arg VITE_API_BASE_URL=http://kaopeilian-backend-test:8000 .
- docker tag kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8} kaopeilian-frontend:test
# Step 3: 部署测试服务器
# 部署测试环境
- name: deploy-test
image: appleboy/drone-ssh
settings:
host: 47.107.172.23
username: root
password:
from_secret: ssh_password
port: 22
script:
- echo "=== 部署考培练系统测试环境 ==="
- cd /data/kaopeilian-test || mkdir -p /data/kaopeilian-test
- |
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
backend:
image: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-backend:test
container_name: kaopeilian-backend-test
restart: always
ports:
- "18000:8000"
image: docker:dind
volumes:
- name: docker-sock
path: /var/run/docker.sock
environment:
- DATABASE_URL=${DATABASE_URL}
- REDIS_HOST=${REDIS_HOST}
- REDIS_PORT=${REDIS_PORT}
- REDIS_PASSWORD=${REDIS_PASSWORD}
networks:
- kaopeilian-net
frontend:
image: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-frontend:test
container_name: kaopeilian-frontend-test
restart: always
ports:
- "13001:80"
depends_on:
- backend
networks:
- kaopeilian-net
networks:
kaopeilian-net:
driver: bridge
EOF
- docker-compose pull
- docker-compose up -d
DATABASE_URL:
from_secret: database_url
REDIS_HOST:
from_secret: redis_host
REDIS_PORT:
from_secret: redis_port
REDIS_PASSWORD:
from_secret: redis_password
commands:
- docker network create kaopeilian-network 2>/dev/null || true
- docker stop kaopeilian-backend-test kaopeilian-frontend-test 2>/dev/null || true
- docker rm kaopeilian-backend-test kaopeilian-frontend-test 2>/dev/null || true
- |
docker run -d \
--name kaopeilian-backend-test \
--network kaopeilian-network \
-p 18000:8000 \
--restart unless-stopped \
-e DATABASE_URL=$DATABASE_URL \
-e REDIS_HOST=$REDIS_HOST \
-e REDIS_PORT=$REDIS_PORT \
-e REDIS_PASSWORD=$REDIS_PASSWORD \
kaopeilian-backend:test
- |
docker run -d \
--name kaopeilian-frontend-test \
--network kaopeilian-network \
-p 13001:80 \
--restart unless-stopped \
kaopeilian-frontend:test
- docker ps | grep kaopeilian
- echo "=== 部署完成 ==="
- echo "=== 考培练系统测试环境部署完成 ==="
# Step 4: 通知部署结果
- name: notify
image: plugins/webhook
settings:
urls:
from_secret: webhook_url
content_type: application/json
template: |
{
"msgtype": "text",
"text": {
"content": "🚀 考培练系统测试环境部署完成\n分支: ${DRONE_BRANCH}\n提交: ${DRONE_COMMIT_SHA:0:8}\n作者: ${DRONE_COMMIT_AUTHOR}"
}
}
when:
status:
- success
- failure
volumes:
- name: docker-sock
host:
path: /var/run/docker.sock
---
kind: pipeline
type: docker
name: code-check
# 所有分支推送时进行代码检查
trigger:
event:
- push
- pull_request
steps:
# Python 代码检查
- name: python-lint
image: python:3.9-slim
commands:
@@ -133,10 +95,8 @@ steps:
- flake8 app --count --select=E9,F63,F7,F82 --show-source --statistics || true
- echo "Python lint completed"
# Node.js 代码检查
- name: frontend-lint
- name: frontend-check
image: node:18-alpine
commands:
- cd frontend
- npm install -q 2>/dev/null || true
- npm run lint 2>/dev/null || echo "Frontend lint completed"
- echo "Frontend check completed"