Skip to content

Commit

Permalink
Change image artifact to OCI format
Browse files Browse the repository at this point in the history
Signed-off-by: tu1h <[email protected]>
  • Loading branch information
0ekk committed Nov 3, 2023
1 parent 12586ec commit 7df5ffd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
12 changes: 4 additions & 8 deletions artifacts/generate_offline_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,15 @@ function create_images() {
fi

while read -r image_name; do
## quay.io/metallb/controller:v0.12.1 => dir:somedir/metallb%controller:v0.12.1
## quay.io/metallb/controller:v0.12.1 => dir:somedir/quay.io%metallb%controller:v0.12.1 ## keep host with multi harbor projects

## new_dir_name=${image_name#*/} ## remote host
new_dir_name=${image_name} ## keep host
new_dir_name=${new_dir_name//\//%} ## replace all / with %
echo "download image $(replace_image_name "$image_name") to local $new_dir_name"
image_name=$(replace_image_name "$image_name")
echo "download image $image_name to local"
ret=0
skopeo copy --insecure-policy --retry-times=3 --override-os linux --override-arch ${ARCH} docker://"$(replace_image_name "$image_name")" dir:offline-images/"$new_dir_name" || ret=$?
skopeo copy --insecure-policy --retry-times=3 --override-os linux --override-arch ${ARCH} "docker://$image_name" "oci:offline-images:$image_name" || ret=$?
if [ ${ret} -ne 0 ]; then
echo "skopeo copy image failed, image name: ${image_name}."
exit 1
fi
echo "$image_name" >> offline-images/images.list
done <<< "$images_list_content"

tar -czvf $OFFLINE_IMAGES_DIR/offline-images.tar.gz offline-images
Expand Down
23 changes: 10 additions & 13 deletions artifacts/import_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function check_local_image_files() {
if [ $(ls -A offline-images | wc -l) -eq 0 ]; then
return
fi
for dir_name in offline-images/*; do
if skopeo inspect dir:"$dir_name" >/dev/null 2>&1; then
echo "check $dir_name successfully"
while read -r image_name; do
if skopeo inspect "oci:offline-images:$image_name" >/dev/null 2>&1; then
echo "check $image_name successfully"
else
echo "check $dir_name and $dir_name maybe bad image file"
echo "$image_name maybe bad image file"
exit 1
fi
done
done < offline-images/images.list
}

function import_images() {
Expand All @@ -39,23 +39,20 @@ function import_images() {

check_local_image_files

for dir_name in offline-images/*; do
while read -r image_name; do
copy_cmd="skopeo copy --insecure-policy -a "
if [ "$DEST_TLS_VERIFY" = false ]; then
copy_cmd=$copy_cmd" --dest-tls-verify=false "
fi
if [ -n "$DEST_USER" ]; then
copy_cmd=$copy_cmd" --dest-creds=$DEST_USER:$DEST_PASS "
fi
## dir:offline-images/abc.com%coreos%etcd:v3.5.4 docker://1.2.3.4:5000/abc.com/coreos/etcd:v3.5.4
image_name=${dir_name#*/} # remove dir prefix
image_name=${image_name//%/\/} # replace % with /
image_name="$REGISTRY_ADDR"/"$image_name"
target_image_name="$REGISTRY_ADDR"/"$image_name"

echo "import $dir_name to $image_name"
echo "import $image_name to $target_image_name"

$copy_cmd --retry-times=3 dir:"$dir_name" docker://"$image_name"
done
$copy_cmd --retry-times=3 "oci:offline-images:$image_name" "docker://$target_image_name"
done < offline-images/images.list

echo "import completed!"
}
Expand Down

0 comments on commit 7df5ffd

Please sign in to comment.