Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完善镜像数据迁移脚本 #2

Open
liangyuanpeng opened this issue Dec 13, 2023 · 1 comment
Open

完善镜像数据迁移脚本 #2

liangyuanpeng opened this issue Dec 13, 2023 · 1 comment
Labels
help wanted Extra attention is needed kind/cleanup

Comments

@liangyuanpeng
Copy link
Owner

liangyuanpeng commented Dec 13, 2023

完善镜像数据迁移脚本,脚本做了以下的事情:

  1. 遍历 tags.json 文件里面的 tags 数组
  2. 使用oras 检查一下是否有对应规则名字拼成的镜像存在,如果有,则认为 tag 版本的容器镜像已经做过一次数据迁移了,跳过
  3. 镜像没有做过数据迁移, 使用 crane 命令来将容器镜像下载下来
  4. 遍历镜像所有的 blobs ,将全部 blobs 上传到 S3 存储当中
  5. 遍历完成后, 使用 oras push 一个对应规则名字的镜像,这个镜像没有内容的,只是为了表示相关镜像完成了数据迁移

可以使用 minio 作为 S3 存储来测试, 位置可以放在本仓库的 scripts/migrate.shell, 有疑问请随时在本 issue 回帖:)

更多内容:
完善变量传参,包括 处理数据的临时目录,镜像名,远程仓库名,S3 存储相关的 地址/accessKey/accessSecret 等内容

/help

下面是目前这个脚本,基于这个脚本来完成:

#!/bin/bash

export DIRECTORY="/home/lan/tmp"
rm -f $DIRECTORY/*

export REGISTRY_IMAGES=(
    coredns/coredns
)

export BUCKET=registry
export IMAGE_REGISTRY=${IMAGE_REGISTRY:-"registry.k8s.io"}

cd $DIRECTORY

echo $REGISTRY_IMAGES

TAGS=$(jq -r '.tags[]' tags.json)

echo "TAGS:"$TAGS

for tag in $TAGS;do 
    echo "TAG:"$tag
    for IMAGE in "${REGISTRY_IMAGES[@]}"
    do
        IMAGE_EXIST=`oras manifest fetch ghcr.io/liangyuanpeng/lank8simgs:$BUCKET-$IMAGE-$tag  | grep mediaType | wc -l `
        if [ $IMAGE_EXIST -eq 1 ]; then
            echo "this ID have info:$IMAGE_REGISTRY/$IMAGE:$tag"
            continue
        fi

        echo "working for:$IMAGE_REGISTRY/$IMAGE:$tag" 

        export FILENAME=$IMAGE
        FILENAME=tmp
        crane pull --verbose $IMAGE_REGISTRY/$IMAGE:$tag $FILENAME.tgz
        tar -xf $FILENAME.tgz
        rm -f $FILENAME.tgz
        rm -f manifest.json
        rm -f sha256*
        pwd
        find ./ -name "*.tar.gz" | awk -F "." '{print $2}' | xargs -i -t mv ./{}.tar.gz  ./{}

        ls
        files=$(ls $DIRECTORY/)
        for filename in $files
        do
            echo $filename
            #TODO 使用 minio的命令 mc
        done
        oras push ghcr.io/liangyuanpeng/lank8simgs:$BUCKET-$IMAGE-$tag
        pwd
        ls
        rm -f $DIRECTORY/*
    done

done

tags.json

{
"tags":[
        "v1.7.0",
        "v1.7.1",
        "v1.8.0",
        "v1.8.3",
        "v1.8.4",
        "v1.8.5",
        "v1.8.6",
        "v1.9.3",
        "v1.9.4"
]
}
@liangyuanpeng liangyuanpeng added the help wanted Extra attention is needed label Dec 13, 2023
@liangyuanpeng
Copy link
Owner Author

/kind cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed kind/cleanup
Projects
None yet
Development

No branches or pull requests

1 participant