Skip to content

Instantly share code, notes, and snippets.

@FriendlyUser
Created December 5, 2020 19:04
Show Gist options
  • Save FriendlyUser/b25d11002a46364a99b9c0f442eff6c9 to your computer and use it in GitHub Desktop.
Save FriendlyUser/b25d11002a46364a99b9c0f442eff6c9 to your computer and use it in GitHub Desktop.
Transfer Images from dockerhub to ghcr
#!/bin/bash
# Simple script to repush docker images from one repository to another
# This is done incremently because my images are massive
original_image="grandfleet/dolwarp"
# github packages has a strange way of having images, you can have
new_image="friendlyuser/dimages/lwarp_docker"
# Github package registry with a repository
target_acr="docker.pkg.github.com"
temp_file="image_list.txt"
rm $temp_file
wget -q https://registry.hub.docker.com/v1/repositories/$original_image/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n'| awk -F: '{print $3}' >> $temp_file
while read -r line; do
tag="$line"
if [[ "$line" == "latest" ]]; then
echo "Found line latest"
else
# docker image push and delete
docker pull $original_image:$tag
docker tag $original_image:$tag $target_acr/$new_image:$tag
docker push $target_acr/$new_image:$tag
docker image rm $original_image:$tag
docker image rm $target_acr/$new_image:$tag
fi
done < "$temp_file"
rm $temp_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment