This commit is contained in:
@@ -11,11 +11,6 @@ steps:
|
|||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
commands:
|
commands:
|
||||||
- |
|
- |
|
||||||
# 定义应用相关的名称标识
|
|
||||||
# APP_NAME="node-app"
|
|
||||||
# CONTAINER_NAME="node-app-prod"
|
|
||||||
CURRENT_TAG="${DRONE_COMMIT_SHA:0:8}"
|
|
||||||
|
|
||||||
echo "开始清理残留资源..."
|
echo "开始清理残留资源..."
|
||||||
|
|
||||||
# 1. 停止并删除正在运行的旧容器
|
# 1. 停止并删除正在运行的旧容器
|
||||||
@@ -31,7 +26,7 @@ steps:
|
|||||||
echo "清理旧镜像..."
|
echo "清理旧镜像..."
|
||||||
docker images --filter "reference=node-app:*" --format "{{.ID}} {{.Tag}}" | \
|
docker images --filter "reference=node-app:*" --format "{{.ID}} {{.Tag}}" | \
|
||||||
while read -r image_id tag; do
|
while read -r image_id tag; do
|
||||||
if [ "$tag" != "$CURRENT_TAG" ] && [ "$tag" != "<none>" ]; then
|
if [ "$tag" != "${DRONE_COMMIT_SHA:0:8}" ] && [ "$tag" != "<none>" ]; then
|
||||||
echo "删除旧镜像: node-app:${tag} (ID: ${image_id})"
|
echo "删除旧镜像: node-app:${tag} (ID: ${image_id})"
|
||||||
docker rmi -f ${image_id} || true
|
docker rmi -f ${image_id} || true
|
||||||
fi
|
fi
|
||||||
@@ -104,3 +99,4 @@ trigger:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
Reference in New Issue
Block a user