ci: 切换部署脚本

This commit is contained in:
sunxiaolong
2024-08-02 19:35:05 +08:00
parent f5c3bcb5f2
commit 36a48c2ab8
3 changed files with 279 additions and 279 deletions

View File

@@ -15,18 +15,18 @@ clone:
steps:
- name: build new image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --build-arg USE_PROXY=1 --no-cache
- name: clean old container
- docker build --no-cache -t kami_frontend:${DRONE_BRANCH}${DRONE_BUILD_NUMBER} -f ./deploy/Dockerfile --build-arg USE_PROXY=1 .
- name: deploy to docker compose
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
- name: push to docker registry
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
- docker save -o /tmp/kami_frontend.tar kami_frontend:${DRONE_BRANCH}${DRONE_BUILD_NUMBER}
- mv ./deploy/docker-compose.yml /tmp/
# - name: clean unused image
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
# - docker image prune -af
trigger:
branch:
@@ -48,23 +48,40 @@ server:
from_secret: flower
clone:
depth: 1
disable: true
steps:
- name: build new image
- name: copy file
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
- name: clean old continaer
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com www@121.37.253.228:/tmp/kami_frontend.tar ./
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com www@121.37.253.228:/tmp/docker-compose.yml ./
environment:
PASSWORD:
from_secret: www_password
- name: pull image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
- docker load -i kami_frontend.tar
- name: copy tar to tmp dictionary
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
- sudo mv kami_frontend.tar /tmp/
- sudo mv docker-compose.yml /tmp/
# - name: clean old container
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
# - docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
# # - name: run docker compose
# # commands:
# # - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
# # - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
# - name: run docker compose
# commands:
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose down
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose up -d
- name: clean unused image
commands:
- docker image prune -af
depends_on:
- master-machine
trigger:
status:
@@ -88,23 +105,36 @@ server:
from_secret: ubuntu_L
clone:
depth: 1
disable: true
steps:
- name: build new image
- name: copy file
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
- name: clean old continaer
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/kami_frontend.tar ./
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/docker-compose.yml ./
environment:
PASSWORD:
from_secret: flower
- name: pull image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
- docker load -i kami_frontend.tar
- name: clean old container
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
- docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
# - name: run docker compose
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
- name: run docker compose
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose down
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose up -d
- name: clean unused image
commands:
- docker image prune -af
depends_on:
- 绝技服务器
trigger:
branch:
@@ -128,23 +158,36 @@ server:
from_secret: ubuntu-crazy_rabbit
clone:
depth: 1
disable: true
steps:
- name: build new image
- name: copy file
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
- name: clean old continaer
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/kami_frontend.tar ./
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/docker-compose.yml ./
environment:
PASSWORD:
from_secret: flower
- name: pull image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
- docker load -i kami_frontend.tar
- name: clean old container
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
- docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
# - name: run docker compose
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
- name: run docker compose
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose down
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose up -d
- name: clean unused image
commands:
- docker image prune -af
depends_on:
- 绝技服务器
trigger:
status:
@@ -164,8 +207,6 @@ name: server酱微信通知
depends_on:
- 泼兔的服务器
- 小L的服务器
- 绝技服务器
- master-machine
steps:
- name: send-wechat
image: plugins/webhook

View File

@@ -1,235 +0,0 @@
---
kind: pipeline
type: ssh
name: master-machine
server:
host: 121.37.253.228
user: www
password:
from_secret: www_password
clone:
depth: 1
steps:
- name: build new image
commands:
- docker build --no-cache -t kami_frontend:${DRONE_BRANCH}${DRONE_BUILD_NUMBER} -f ./deploy/Dockerfile --build-arg USE_PROXY=1 .
- name: deploy to docker compose
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
- name: push to docker registry
commands:
- docker save -o /tmp/kami_frontend.tar kami_frontend:${DRONE_BRANCH}${DRONE_BUILD_NUMBER}
- mv ./deploy/docker-compose.yml /tmp/
# - name: clean unused image
# commands:
# - docker image prune -af
trigger:
branch:
- develop
- production
when:
event:
- push
---
kind: pipeline
type: ssh
name: 绝技服务器
server:
host: 43.133.200.219
user: ubuntu
password:
from_secret: flower
clone:
disable: true
steps:
- name: copy file
commands:
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com www@121.37.253.228:/tmp/kami_frontend.tar ./
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com www@121.37.253.228:/tmp/docker-compose.yml ./
environment:
PASSWORD:
from_secret: www_password
- name: pull image
commands:
- docker load -i kami_frontend.tar
- name: copy tar to tmp dictionary
commands:
- sudo mv kami_frontend.tar /tmp/
- sudo mv docker-compose.yml /tmp/
# - name: clean old container
# commands:
# - docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
# # - name: run docker compose
# # commands:
# # - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
# # - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
# - name: run docker compose
# commands:
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose down
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose up -d
- name: clean unused image
commands:
- docker image prune -af
depends_on:
- master-machine
trigger:
status:
- success
- failure
branch:
- production
when:
event:
- push
---
kind: pipeline
type: ssh
name: 小L的服务器
server:
host: 43.130.238.110
user: ubuntu
password:
from_secret: ubuntu_L
clone:
disable: true
steps:
- name: copy file
commands:
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/kami_frontend.tar ./
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/docker-compose.yml ./
environment:
PASSWORD:
from_secret: flower
- name: pull image
commands:
- docker load -i kami_frontend.tar
- name: clean old container
commands:
- docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
# - name: run docker compose
# commands:
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
- name: run docker compose
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose down
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose up -d
- name: clean unused image
commands:
- docker image prune -af
depends_on:
- 绝技服务器
trigger:
branch:
- production
status:
- success
- failure
when:
event:
- push
---
kind: pipeline
type: ssh
name: 泼兔的服务器
server:
host: 43.163.223.93
user: ubuntu
password:
from_secret: ubuntu-crazy_rabbit
clone:
disable: true
steps:
- name: copy file
commands:
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/kami_frontend.tar ./
- sshpass -p $PASSWORD scp -C -c chacha20-poly1305@openssh.com ubuntu@43.133.200.219:/tmp/docker-compose.yml ./
environment:
PASSWORD:
from_secret: flower
- name: pull image
commands:
- docker load -i kami_frontend.tar
- name: clean old container
commands:
- docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
# - name: run docker compose
# commands:
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml down
# - VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose -f ./deploy/docker-compose.yml up -d
- name: run docker compose
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose down
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} USE_PROXY=1 docker compose up -d
- name: clean unused image
commands:
- docker image prune -af
depends_on:
- 绝技服务器
trigger:
status:
- success
- failure
branch:
- production
when:
event:
- push
---
kind: pipeline
type: docker
name: server酱微信通知
depends_on:
- 泼兔的服务器
- 小L的服务器
steps:
- name: send-wechat
image: plugins/webhook
pull: if-not-exists
settings:
urls: https://open.feishu.cn/open-apis/bot/v2/hook/1f4a9795-84a9-4cc5-b2c5-0bf05686336b
content_type: application/json
template: |
{
"msg_type":"text",
"content":
{
"text": "项目名称: ${DRONE_REPO_NAME}\n分支${DRONE_BRANCH}\n构建编号${DRONE_BUILD_NUMBER}\n项目构建状态{{ build.status }}"
}
}
trigger:
branch:
- develop
- production
status:
- success
- failure
when:
event:
- push

194
.drone.yml.bak1 Normal file
View File

@@ -0,0 +1,194 @@
---
kind: pipeline
type: ssh
name: master-machine
server:
host: 121.37.253.228
user: www
password:
from_secret: www_password
clone:
depth: 1
steps:
- name: build new image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --build-arg USE_PROXY=1 --no-cache
- name: clean old container
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
trigger:
branch:
- develop
- production
when:
event:
- push
---
kind: pipeline
type: ssh
name: 绝技服务器
server:
host: 43.133.200.219
user: ubuntu
password:
from_secret: flower
clone:
depth: 1
steps:
- name: build new image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
- name: clean old continaer
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
trigger:
status:
- success
- failure
branch:
- production
when:
event:
- push
---
kind: pipeline
type: ssh
name: 小L的服务器
server:
host: 43.130.238.110
user: ubuntu
password:
from_secret: ubuntu_L
clone:
depth: 1
steps:
- name: build new image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
- name: clean old continaer
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
trigger:
branch:
- production
status:
- success
- failure
when:
event:
- push
---
kind: pipeline
type: ssh
name: 泼兔的服务器
server:
host: 43.163.223.93
user: ubuntu
password:
from_secret: ubuntu-crazy_rabbit
clone:
depth: 1
steps:
- name: build new image
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml build --no-cache
- name: clean old continaer
commands:
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker container inspect kami_frontend &> /dev/null && docker container rm -f kami_frontend
- name: start new container
commands:
- echo start build
- VERSION=${DRONE_BRANCH}${DRONE_BUILD_NUMBER} docker compose -f ./deploy/docker-compose.yml -p kami_frontend up -d
# - name: clean old image and container
# commands:
# - docker images --filter "dangling=true" -q | xargs -r docker rmi -f
# - docker images --filter "label=none" -q | xargs -r docker rmi -f
trigger:
status:
- success
- failure
branch:
- production
when:
event:
- push
---
kind: pipeline
type: docker
name: server酱微信通知
depends_on:
- 泼兔的服务器
- 小L的服务器
- 绝技服务器
- master-machine
steps:
- name: send-wechat
image: plugins/webhook
pull: if-not-exists
settings:
urls: https://open.feishu.cn/open-apis/bot/v2/hook/1f4a9795-84a9-4cc5-b2c5-0bf05686336b
content_type: application/json
template: |
{
"msg_type":"text",
"content":
{
"text": "项目名称: ${DRONE_REPO_NAME}\n分支${DRONE_BRANCH}\n构建编号${DRONE_BUILD_NUMBER}\n项目构建状态{{ build.status }}"
}
}
trigger:
branch:
- develop
- production
status:
- success
- failure
when:
event:
- push