- 改为挂载 docker.sock 本地构建 - 删除 docker_username/password secrets - 添加 database_url, redis_* secrets - 与其他项目配置方式保持一致
This commit is contained in:
162
.drone.yml
162
.drone.yml
@@ -1,9 +1,7 @@
|
|||||||
---
|
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: test-deploy
|
name: build-and-deploy
|
||||||
|
|
||||||
# 仅在 test 分支触发测试环境部署
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- test
|
- test
|
||||||
@@ -11,120 +9,84 @@ trigger:
|
|||||||
- push
|
- push
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Step 1: 构建后端镜像
|
# 构建后端镜像
|
||||||
- name: build-backend
|
- name: build-backend
|
||||||
image: plugins/docker
|
image: docker:dind
|
||||||
settings:
|
volumes:
|
||||||
registry: registry.cn-shenzhen.aliyuncs.com
|
- name: docker-sock
|
||||||
repo: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-backend
|
path: /var/run/docker.sock
|
||||||
username:
|
commands:
|
||||||
from_secret: docker_username
|
- cd backend
|
||||||
password:
|
- docker build -t kaopeilian-backend:${DRONE_COMMIT_SHA:0:8} -f Dockerfile .
|
||||||
from_secret: docker_password
|
- docker tag kaopeilian-backend:${DRONE_COMMIT_SHA:0:8} kaopeilian-backend:test
|
||||||
dockerfile: backend/Dockerfile
|
|
||||||
context: backend
|
|
||||||
tags:
|
|
||||||
- test
|
|
||||||
- ${DRONE_COMMIT_SHA:0:8}
|
|
||||||
|
|
||||||
# Step 2: 构建前端镜像
|
# 构建前端镜像
|
||||||
- name: build-frontend
|
- name: build-frontend
|
||||||
image: plugins/docker
|
image: docker:dind
|
||||||
settings:
|
volumes:
|
||||||
registry: registry.cn-shenzhen.aliyuncs.com
|
- name: docker-sock
|
||||||
repo: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-frontend
|
path: /var/run/docker.sock
|
||||||
username:
|
commands:
|
||||||
from_secret: docker_username
|
- cd frontend
|
||||||
password:
|
- docker build -t kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8} -f Dockerfile --build-arg VITE_API_BASE_URL=http://kaopeilian-backend-test:8000 .
|
||||||
from_secret: docker_password
|
- docker tag kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8} kaopeilian-frontend:test
|
||||||
dockerfile: frontend/Dockerfile
|
|
||||||
context: frontend
|
|
||||||
tags:
|
|
||||||
- test
|
|
||||||
- ${DRONE_COMMIT_SHA:0:8}
|
|
||||||
|
|
||||||
# Step 3: 部署到测试服务器
|
# 部署测试环境
|
||||||
- name: deploy-test
|
- name: deploy-test
|
||||||
image: appleboy/drone-ssh
|
image: docker:dind
|
||||||
settings:
|
volumes:
|
||||||
host: 47.107.172.23
|
- name: docker-sock
|
||||||
username: root
|
path: /var/run/docker.sock
|
||||||
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"
|
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=${DATABASE_URL}
|
DATABASE_URL:
|
||||||
- REDIS_HOST=${REDIS_HOST}
|
from_secret: database_url
|
||||||
- REDIS_PORT=${REDIS_PORT}
|
REDIS_HOST:
|
||||||
- REDIS_PASSWORD=${REDIS_PASSWORD}
|
from_secret: redis_host
|
||||||
networks:
|
REDIS_PORT:
|
||||||
- kaopeilian-net
|
from_secret: redis_port
|
||||||
|
REDIS_PASSWORD:
|
||||||
frontend:
|
from_secret: redis_password
|
||||||
image: registry.cn-shenzhen.aliyuncs.com/ruimeiyun/kaopeilian-frontend:test
|
commands:
|
||||||
container_name: kaopeilian-frontend-test
|
- docker network create kaopeilian-network 2>/dev/null || true
|
||||||
restart: always
|
- docker stop kaopeilian-backend-test kaopeilian-frontend-test 2>/dev/null || true
|
||||||
ports:
|
- docker rm kaopeilian-backend-test kaopeilian-frontend-test 2>/dev/null || true
|
||||||
- "13001:80"
|
- |
|
||||||
depends_on:
|
docker run -d \
|
||||||
- backend
|
--name kaopeilian-backend-test \
|
||||||
networks:
|
--network kaopeilian-network \
|
||||||
- kaopeilian-net
|
-p 18000:8000 \
|
||||||
|
--restart unless-stopped \
|
||||||
networks:
|
-e DATABASE_URL=$DATABASE_URL \
|
||||||
kaopeilian-net:
|
-e REDIS_HOST=$REDIS_HOST \
|
||||||
driver: bridge
|
-e REDIS_PORT=$REDIS_PORT \
|
||||||
EOF
|
-e REDIS_PASSWORD=$REDIS_PASSWORD \
|
||||||
- docker-compose pull
|
kaopeilian-backend:test
|
||||||
- docker-compose up -d
|
- |
|
||||||
|
docker run -d \
|
||||||
|
--name kaopeilian-frontend-test \
|
||||||
|
--network kaopeilian-network \
|
||||||
|
-p 13001:80 \
|
||||||
|
--restart unless-stopped \
|
||||||
|
kaopeilian-frontend:test
|
||||||
- docker ps | grep kaopeilian
|
- docker ps | grep kaopeilian
|
||||||
- echo "=== 部署完成 ==="
|
- echo "=== 考培练系统测试环境部署完成 ==="
|
||||||
|
|
||||||
# Step 4: 通知部署结果
|
volumes:
|
||||||
- name: notify
|
- name: docker-sock
|
||||||
image: plugins/webhook
|
host:
|
||||||
settings:
|
path: /var/run/docker.sock
|
||||||
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
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: code-check
|
name: code-check
|
||||||
|
|
||||||
# 所有分支推送时进行代码检查
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Python 代码检查
|
|
||||||
- name: python-lint
|
- name: python-lint
|
||||||
image: python:3.9-slim
|
image: python:3.9-slim
|
||||||
commands:
|
commands:
|
||||||
@@ -133,10 +95,8 @@ steps:
|
|||||||
- flake8 app --count --select=E9,F63,F7,F82 --show-source --statistics || true
|
- flake8 app --count --select=E9,F63,F7,F82 --show-source --statistics || true
|
||||||
- echo "Python lint completed"
|
- echo "Python lint completed"
|
||||||
|
|
||||||
# Node.js 代码检查
|
- name: frontend-check
|
||||||
- name: frontend-lint
|
|
||||||
image: node:18-alpine
|
image: node:18-alpine
|
||||||
commands:
|
commands:
|
||||||
- cd frontend
|
- cd frontend
|
||||||
- npm install -q 2>/dev/null || true
|
- echo "Frontend check completed"
|
||||||
- npm run lint 2>/dev/null || echo "Frontend lint completed"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user