Skip to content

建议增加一个阿里云镜像清理功能 #4

Description

@okeyear
  • 增加一个github action, 定期(on schedule, 比如每半个月) 执行清理脚本
  • 清理脚本类似如下(deepseek搜的)
#!/bin/bash
# 需提前安装aliyun-cli并配置AK:https://help.aliyun.com/document_detail/121258.html

# 配置区域和仓库(根据实际情况修改)
REGION="cn-hangzhou"
REPO_NAMESPACE="your-namespace"
REPO_NAME="your-repo-name"
CUTOFF_DATE=$(date -d "6 months ago" +%s)

# 获取镜像列表
IMAGE_LIST=$(aliyun cr GetRepoTag --RegionId $REGION --RepoNamespace $REPO_NAMESPACE --RepoName $REPO_NAME | jq -r '.data.tags[] | "\(.tag) \(.imageCreate)"')

# 清理旧镜像
while read -r line; do
    TAG=$(echo $line | awk '{print $1}')
    CREATE_TIME=$(echo $line | awk '{print $2}')
    TIMESTAMP=$(date -d "$CREATE_TIME" +%s)

    if [ $TIMESTAMP -lt $CUTOFF_DATE ]; then
        echo "Deleting $REPO_NAMESPACE/$REPO_NAME:$TAG (Created: $CREATE_TIME)"
        aliyun cr DeleteImage --RegionId $REGION --RepoNamespace $REPO_NAMESPACE --RepoName $REPO_NAME --Tag $TAG
    fi
done <<< "$IMAGE_LIST"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions