Skip to content

Instantly share code, notes, and snippets.

@linuxmaniac
Last active April 20, 2023 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxmaniac/2d513333b6b0ebf3faa4b0dadb38afa1 to your computer and use it in GitHub Desktop.
Save linuxmaniac/2d513333b6b0ebf3faa4b0dadb38afa1 to your computer and use it in GitHub Desktop.
migrate script to push docker hub images to Github Packages
#!/bin/bash
set -ex
# Simple script to repush docker images from one repository to another
# This is done incremently because my images are massive
original_image="kamailio/kamailio-ci"
# github packages has a strange way of having images, you can have
new_image="kamailio/kamailio-ci"
# Github package registry with a repository
target_acr="ghcr.io"
temp_file="image_list.txt"
rm -f $temp_file
wget -q https://registry.hub.docker.com/v2/repositories/$original_image/tags -O tmp.json
jq -r '.results | .[] | .name' tmp.json >> $temp_file
next_url=$(jq -r '.next' tmp.json)
while [[ -n ${next_url} ]] && [[ ${next_url} != null ]]; do
wget -q "${next_url}" -O tmp.json
jq -r '.results | .[] | .name' tmp.json >> $temp_file
next_url=$(jq -r '.next' tmp.json)
done
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment