Compare commits

...

5 Commits

Author SHA1 Message Date
becomer f706968618 fix: force-remove temp container in cleanup step
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/tag/build Pipeline was successful
2026-07-01 12:49:10 +08:00
becomer 69e198f745 fix: use wget instead of curl for health check
ci/woodpecker/push/build Pipeline was successful
The 'docker' CLI image does not include curl binary,
causing the health check to always fail. Switch to wget.
2026-07-01 12:47:05 +08:00
becomer 70f907d909 fix: replace shell ${VAR} with $VAR to avoid Woodpecker pre-processing
ci/woodpecker/push/build Pipeline failed
Woodpecker interprets ${...} as its own template syntax and strips
unrecognized variables. Using $VAR (no braces) passes through to bash.
2026-07-01 12:43:56 +08:00
becomer 3a3d17e9b4 feat: blue-green zero-downtime deploy via 1Panel
ci/woodpecker/push/build Pipeline failed
- Set up 1Panel website tianshen.eu.cc (HTTP 80, ready for HTTPS)
- /api/* → likedream-go with prefix stripping
- /* → likedream-web (Caddy, port 3080)
- Blue-green deployment: start on standby port → switch proxy → stop old → switch back
- Nginx reload is hot (zero connection drops)
- Detects current active port from proxy config automatically
2026-07-01 12:40:01 +08:00
becomer d560c9f678 fix: override clone remote to local Gitea URL
ci/woodpecker/push/build Pipeline is running
ci/woodpecker/tag/build Pipeline was successful
Add clone.git.settings.remote in .woodpecker/build.yml to use
fast local clone (http://10.10.10.128:3000) instead of external
Cloudflare-proxied URL (https://git.xsvb.cn) for tag builds.
2026-07-01 01:09:16 +08:00
+99 -7
View File
@@ -4,6 +4,12 @@ when:
- event: tag
branch: [v*]
clone:
git:
image: woodpeckerci/plugin-git
settings:
remote: http://10.10.10.128:3000/becomer/likedream.git
steps:
build-image:
image: docker
@@ -16,23 +22,109 @@ steps:
deploy:
image: docker
commands: |
# ============================================================
# 蓝绿部署:零宕机切换 likedream-go 容器
# 判断当前代理使用的端口,另一个作为备用
# ============================================================
set -e
IMAGE_TAG="$CI_COMMIT_TAG"
if [ -z "$IMAGE_TAG" ]; then IMAGE_TAG="latest"; fi
# 确保网络存在
docker network create likedream-net 2>/dev/null || true
# 停止并删除旧容器
# 读取 1Panel 当前代理端口
CURRENT_PORT=$(docker exec 1Panel-openresty-ESmn \
grep -o 'proxy_pass http://10.10.10.128:[0-9]\+' \
/www/sites/tianshen/proxy/api.conf | grep -o '[0-9]\+$')
echo "=== 当前 1Panel 反代端口: $CURRENT_PORT ==="
if [ "$CURRENT_PORT" = "8091" ]; then
PORT_ACTIVE=8091
PORT_STANDBY=8092
elif [ "$CURRENT_PORT" = "8092" ]; then
PORT_ACTIVE=8092
PORT_STANDBY=8091
else
echo "未知当前端口 $CURRENT_PORT,默认使用 8091/8092"
PORT_ACTIVE=8091
PORT_STANDBY=8092
fi
echo " 活跃: $PORT_ACTIVE | 备用: $PORT_STANDBY"
# 清理之前可能残留的临时容器
docker rm -f likedream-go-new 2>/dev/null || true
echo "=== 蓝绿部署: 启动新容器 on :$PORT_STANDBY (image: $IMAGE_TAG) ==="
docker run -d --name likedream-go-new \
--restart unless-stopped \
--network likedream-net \
-p $PORT_STANDBY:8091 \
-v /opt/likedream-go/config.toml:/app/config.toml:ro \
likedream-go:$IMAGE_TAG
# 健康检查:等待新容器就绪
HEALTHY=false
for i in $(seq 1 15); do
if wget -q --timeout=3 -O /dev/null http://10.10.10.128:$PORT_STANDBY/health 2>/dev/null; then
HEALTHY=true
break
fi
echo " 等待新容器就绪... ($i/15)"
sleep 2
done
if [ "$HEALTHY" = false ]; then
echo "ERROR: 新容器未通过健康检查,回滚"
docker stop likedream-go-new
docker rm likedream-go-new
exit 1
fi
echo " 新容器已就绪 ✓"
# 切换 1Panel 代理到备用端口
echo "=== 切换 1Panel 反代 :$PORT_ACTIVE → :$PORT_STANDBY ==="
docker exec 1Panel-openresty-ESmn \
sed -i "s|:$PORT_ACTIVE|:$PORT_STANDBY|g" \
/www/sites/tianshen/proxy/api.conf
docker exec 1Panel-openresty-ESmn nginx -s reload
echo " Nginx 热加载完成(零中断)✓"
# 停止旧容器
echo "=== 清理旧容器 ==="
docker stop likedream-go 2>/dev/null || true
docker rm likedream-go 2>/dev/null || true
# 启动新容器
docker run -d \
--name likedream-go \
# 在活跃端口启动正式容器
echo "=== 启动正式容器 on :$PORT_ACTIVE ==="
docker run -d --name likedream-go \
--restart unless-stopped \
--network likedream-net \
-p 8091:8091 \
-p $PORT_ACTIVE:8091 \
-v /opt/likedream-go/config.toml:/app/config.toml:ro \
likedream-go:latest
likedream-go:$IMAGE_TAG
# 连接到 captcha 服务所在网络
# 连接到验证码服务网络
docker network connect ocr-go_default likedream-go 2>/dev/null || true
# 切回 1Panel 代理到活跃端口
echo "=== 切回 1Panel 反代 :$PORT_STANDBY → :$PORT_ACTIVE ==="
docker exec 1Panel-openresty-ESmn \
sed -i "s|:$PORT_STANDBY|:$PORT_ACTIVE|g" \
/www/sites/tianshen/proxy/api.conf
docker exec 1Panel-openresty-ESmn nginx -s reload
echo " Nginx 热加载完成(零中断)✓"
# 清理临时容器和旧镜像
echo "=== 清理 ==="
docker rm -f likedream-go-new 2>/dev/null || true
# 保留 latest 和最近 3 个 tag 镜像
docker images likedream-go --format '{{.Tag}}' | grep -v latest | head -n -3 | while read tag; do
docker rmi likedream-go:$tag 2>/dev/null || true
done
echo "=== 部署完成 ✓ ==="
volumes:
- /var/run/docker.sock:/var/run/docker.sock