77 lines
2.7 KiB
YAML
77 lines
2.7 KiB
YAML
# 第 95 次部署
|
|
variables:
|
|
# --- 仓库与私服配置 ---
|
|
- &APP_REGISTRY "push.lovestory.cyou" # 推送镜像的私服域名
|
|
- &APP_PULL_REGISTRY "registry.lovestory.cyou" # 拉取基础镜像的私服域名
|
|
- &PROJECT_NAME "abhors/demo" # 项目镜像路径与名称
|
|
- &PROJECT_PORT "8080"
|
|
- &FULL_PUSH_REPO "push.lovestory.cyou/abhors/demo" # 拼接后的完整推送地址
|
|
- &FULL_PULL_REPO "push.lovestory.cyou/abhors/demo:latest" # 远程部署拉取的目标地址
|
|
|
|
# --- 部署目标机配置 ---
|
|
- &CONTAINER_NAME "demo-container"
|
|
- &DEPLOY_HOST "43.143.243.136"
|
|
- &DEPLOY_PORT "22"
|
|
- &DEPLOY_USER_SECRET "136_ssh_user"
|
|
- &DEPLOY_PASS_SECRET "136_ssh_password"
|
|
|
|
steps:
|
|
- name: Java 构建
|
|
image: library/maven:3.9.6-eclipse-temurin-17
|
|
pull: true
|
|
commands:
|
|
- mvn clean package -DskipTests
|
|
volumes:
|
|
- /tmp/maven-cache:/root/.m2
|
|
when:
|
|
event: [push, pull_request]
|
|
branch: master
|
|
|
|
- name: 官方标准构建与推送 (宿主机物理硬缓存版)
|
|
image: docker.m.daocloud.io/woodpeckerci/plugin-docker-buildx:latest-insecure
|
|
privileged: true
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
settings:
|
|
repo: *FULL_PUSH_REPO
|
|
registry: *APP_REGISTRY
|
|
username:
|
|
from_secret: nexus_docker_username
|
|
password:
|
|
from_secret: nexus_docker_password
|
|
mirror: https://registry.lovestory.cyou
|
|
when:
|
|
event: push
|
|
branch: master
|
|
|
|
- name: 远程终端部署
|
|
image: registry.lovestory.cyou/appleboy/drone-ssh:latest
|
|
settings:
|
|
host: *DEPLOY_HOST
|
|
port: *DEPLOY_PORT
|
|
username:
|
|
from_secret: *DEPLOY_USER_SECRET
|
|
password:
|
|
from_secret: *DEPLOY_PASS_SECRET
|
|
secrets: [ nexus_docker_username, nexus_docker_password ]
|
|
envs:
|
|
- nexus_docker_username
|
|
- nexus_docker_password
|
|
- DEPLOY_HOST=*DEPLOY_HOST
|
|
- CONTAINER_NAME=*CONTAINER_NAME
|
|
- FULL_PULL_REPO=*FULL_PULL_REPO
|
|
- APP_REGISTRY=*APP_REGISTRY
|
|
- PROJECT_PORT=*PROJECT_PORT
|
|
|
|
script:
|
|
- echo "========================================="
|
|
- echo "🚀 开始部署节点:$DEPLOY_HOST"
|
|
- echo "========================================="
|
|
- docker login --username "$nexus_docker_username" --password "$nexus_docker_password" "$APP_REGISTRY"
|
|
- docker stop "$CONTAINER_NAME" || true
|
|
- docker rm "$CONTAINER_NAME" || true
|
|
- docker pull "$FULL_PULL_REPO"
|
|
- docker run -d --name "$CONTAINER_NAME" -p "$PROJECT_PORT":"$PROJECT_PORT" --restart always "$FULL_PULL_REPO"
|
|
when:
|
|
event: push
|
|
branch: master |