[[ -z "$line" ]] && continue
if echo "$line" | grep -q '^\s*#'; then
continue
fi
echo "docker pull $line"
docker pull $line
platform=$(echo "$line" | awk -F'--platform[ =]' '{if (NF>1) print $2}' | awk '{print $1}')
echo "platform is $platform"
# 如果存在架构信息 将架构信息拼到镜像名称前面
if [ -z "$platform" ]; then
platform_prefix=""
else
platform_prefix="${platform//\//_}_"
fi
echo "platform_prefix is $platform_prefix"
# 获取镜像的完整名称,例如kasmweb/nginx:1.2[5](https://github.com/alieismy/aliyun-docker-image-mirror/actions/runs/11093801067/job/30820529818#step:8:5).3(命名空间/镜像名:版本号)
image=$(echo "$line" | awk '{print $NF}')
# 获取 镜像名:版本号 例如nginx:1.25.3
image_name_tag=$(echo "$image" | awk -F'/' '{print $NF}')
# 获取命名空间 例如kasmweb 这里有种特殊情况 docker.io/nginx,把docker.io当成命名空间,也OK
name_space=$(echo "$image" | awk -F'/' '{if (NF==3) print $2; else if (NF==2) print $1; else print ""}')
# 获取镜像名例 例如nginx
image_name=$(echo "$image_name_tag" | awk -F':' '{print $1}')
name_space_prefix=""
# 如果镜像名重名
if [[ -n "${duplicate_images[$image_name]}" ]]; then
#如果命名空间非空,将命名空间加到前缀
if [[ -n "${name_space}" ]]; then
name_space_prefix="${name_space}_"
fi
fi
# 将@sha25[6](https://github.com/alieismy/aliyun-docker-image-mirror/actions/runs/11093801067/job/30820529818#step:8:6):等字符删除
image_name_tag="${image_name_tag%%@*}"
new_image="$ALIYUN_REGISTRY/$ALIYUN_NAME_SPACE/$platform_prefix$name_space_prefix$image_name_tag"
echo "docker tag $image $new_image"
docker tag $image $new_image
echo "docker push $new_image"
docker push $new_image
echo "开始清理磁盘空间"
echo "=============================================================================="
df -hT
echo "=============================================================================="
docker rmi $image
docker rmi $new_image
echo "磁盘空间清理完毕"
echo "=============================================================================="
df -hT
echo "=============================================================================="
done < images.txt
shell: /usr/bin/bash -e {0}
env:
ALIYUN_REGISTRY:
ALIYUN_NAME_SPACE:
ALIYUN_REGISTRY_USER:
ALIYUN_REGISTRY_PASSWORD:
Error: Cannot perform an interactive login from a non TTY device
Error: Process completed with exit code 1.
按照作者步骤,在执行github action时报错如下: Run docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY
数据预处理,判断镜像是否重名
declare -A duplicate_images declare -A temp_map while IFS= read -r line || [ -n "$line" ]; do
忽略空行与注释
done < images.txt
while IFS= read -r line || [ -n "$line" ]; do
忽略空行与注释
done < images.txt shell: /usr/bin/bash -e {0} env: ALIYUN_REGISTRY: ALIYUN_NAME_SPACE: ALIYUN_REGISTRY_USER: ALIYUN_REGISTRY_PASSWORD: Error: Cannot perform an interactive login from a non TTY device Error: Process completed with exit code 1.
还需要在哪里设置呢?