This commit is contained in:
16
.drone.yml
16
.drone.yml
@@ -24,11 +24,15 @@ steps:
|
||||
|
||||
# 2. 删除同前缀的旧镜像(排除当前构建标签)
|
||||
echo "清理旧镜像..."
|
||||
# 只处理有ID和标签的镜像,跳过空值
|
||||
docker images --filter "reference=node-app:*" --format "{{.ID}} {{.Tag}}" | \
|
||||
while read -r image_id tag; do
|
||||
if [ "$tag" != "${DRONE_COMMIT_SHA:0:8}" ] && [ "$tag" != "<none>" ]; then
|
||||
# 检查image_id和tag是否有效
|
||||
if [ -n "$image_id" ] && [ -n "$tag" ] && [ "$tag" != "${DRONE_COMMIT_SHA:0:8}" ] && [ "$tag" != "<none>" ]; then
|
||||
echo "删除旧镜像: node-app:${tag} (ID: ${image_id})"
|
||||
docker rmi -f ${image_id} || true
|
||||
docker rmi -f "${image_id}" || true
|
||||
else
|
||||
echo "跳过无效镜像: ID=${image_id}, Tag=${tag}"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -36,7 +40,8 @@ steps:
|
||||
echo "清理悬空镜像..."
|
||||
dangling_images=$(docker images -f "dangling=true" -q)
|
||||
if [ -n "$dangling_images" ]; then
|
||||
docker rmi -f $dangling_images || true
|
||||
# 确保只传递非空ID
|
||||
echo "$dangling_images" | xargs -I {} docker rmi -f {} || true
|
||||
else
|
||||
echo "没有悬空镜像需要清理"
|
||||
fi
|
||||
@@ -45,11 +50,8 @@ steps:
|
||||
- name: install-dependencies
|
||||
image: node:18-bullseye
|
||||
commands:
|
||||
# 安装iproute2工具
|
||||
- apt-get update && apt-get install -y iproute2
|
||||
# 验证ip命令是否可用
|
||||
- ip -V
|
||||
# 安装项目依赖
|
||||
- npm install
|
||||
volumes:
|
||||
- name: node_modules
|
||||
@@ -83,7 +85,6 @@ steps:
|
||||
branch:
|
||||
- main
|
||||
|
||||
# 定义卷用于共享依赖和Docker socket
|
||||
volumes:
|
||||
- name: node_modules
|
||||
temp: {}
|
||||
@@ -91,7 +92,6 @@ volumes:
|
||||
host:
|
||||
path: /var/run/docker.sock
|
||||
|
||||
# 构建触发条件
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
|
||||
Reference in New Issue
Block a user