refactor: 简化CI/CD,复用生产服务器的测试环境
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- 测试环境使用 kpl.ireborn.com.cn(已存在) - 不再在 DevOps 服务器单独部署 - 添加双 Git remote 支持(origin=Gitea, github=GitHub)
This commit is contained in:
96
.drone.yml
96
.drone.yml
@@ -2,7 +2,7 @@ kind: pipeline
|
|||||||
type: docker
|
type: docker
|
||||||
name: deploy-test
|
name: deploy-test
|
||||||
|
|
||||||
# 测试环境:test 分支触发
|
# 测试环境:test 分支触发,部署到生产服务器的开发环境
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- test
|
- test
|
||||||
@@ -10,69 +10,39 @@ trigger:
|
|||||||
- push
|
- push
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build-backend
|
- name: sync-code
|
||||||
image: docker:dind
|
image: appleboy/drone-ssh
|
||||||
volumes:
|
settings:
|
||||||
- name: docker-sock
|
host: 120.79.247.16
|
||||||
path: /var/run/docker.sock
|
username: root
|
||||||
commands:
|
password:
|
||||||
- cd backend
|
from_secret: prod_ssh_password
|
||||||
- docker build -t kaopeilian-backend:${DRONE_COMMIT_SHA:0:8} -f Dockerfile .
|
port: 22
|
||||||
- docker tag kaopeilian-backend:${DRONE_COMMIT_SHA:0:8} kaopeilian-backend:test
|
command_timeout: 5m
|
||||||
|
script:
|
||||||
|
- echo "=== 同步代码到测试环境 ==="
|
||||||
|
- cd /root/aiedu
|
||||||
|
- git fetch origin
|
||||||
|
- git checkout test 2>/dev/null || git checkout -b test origin/test
|
||||||
|
- git reset --hard origin/test
|
||||||
|
- echo "代码同步完成"
|
||||||
|
|
||||||
- name: build-frontend
|
- name: rebuild-dev
|
||||||
image: docker:dind
|
image: appleboy/drone-ssh
|
||||||
volumes:
|
settings:
|
||||||
- name: docker-sock
|
host: 120.79.247.16
|
||||||
path: /var/run/docker.sock
|
username: root
|
||||||
commands:
|
password:
|
||||||
- cd frontend
|
from_secret: prod_ssh_password
|
||||||
- docker build -t kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8} -f Dockerfile --build-arg VITE_API_BASE_URL=http://kaopeilian.test.ai.ireborn.com.cn .
|
port: 22
|
||||||
- docker tag kaopeilian-frontend:${DRONE_COMMIT_SHA:0:8} kaopeilian-frontend:test
|
command_timeout: 10m
|
||||||
|
script:
|
||||||
- name: deploy-test
|
- echo "=== 重建测试环境 ==="
|
||||||
image: docker:dind
|
- cd /root/aiedu
|
||||||
volumes:
|
- docker-compose -f docker-compose.dev.yml up -d --build
|
||||||
- name: docker-sock
|
- sleep 5
|
||||||
path: /var/run/docker.sock
|
- docker ps | grep kpl-
|
||||||
environment:
|
- echo "=== 测试环境部署完成: https://kpl.ireborn.com.cn ==="
|
||||||
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 "=== 测试环境部署完成: http://kaopeilian.test.ai.ireborn.com.cn ==="
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
- name: docker-sock
|
|
||||||
host:
|
|
||||||
path: /var/run/docker.sock
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
|
|||||||
Reference in New Issue
Block a user