Last active
September 18, 2025 08:36
-
-
Save dellnoantechnp/2a6cf4a27e9fe972d02a64197b28c87d to your computer and use it in GitHub Desktop.
This is a shell script for the bitnami image for migration. Due to the [Bitnami Containers Important Notice](https://github.com/bitnami/containers?tab=readme-ov-file#%EF%B8%8F-important-notice-upcoming-changes-to-the-bitnami-catalog) policy impact, It is used for the current short-term use of the image progressively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| TARGET_REGISTRY="$1" | |
| TARGET_REGSITRY_USERNAME="$2" | |
| TARGET_REGISTRY_PASSWORD="$3" | |
| NERDCTL_DOWNLOAD_URL="https://github.com/containerd/nerdctl/releases/download/v2.1.4/nerdctl-2.1.4-linux-amd64.tar.gz" | |
| NERDCTL_TARBALL_FILE="nerdctl-2.1.4-linux-amd64.tar.gz" | |
| CONTAINER_RUNTIME_SOCK_OPTS="--address /run/containerd/containerd.sock" | |
| NERD_OPTS="-n k8s.io ${CONTAINER_RUNTIME_SOCK_OPTS}" | |
| usage() { | |
| echo "This shell script is migration bitnami image to internal registry." | |
| echo "Usage: bash $0 <REGISTRY> <AUTH_USER> <AUTH_PASS>" | |
| echo | |
| exit 1 | |
| } | |
| if [[ ${1} == "-h" ]] || [[ ${1} == "--help" ]]; then | |
| usage | |
| fi | |
| if [[ $# -ne 3 ]]; then | |
| echo "Error: Expected 3 arguments, got $#" | |
| echo "Run '$0 --help' for usage." | |
| exit 1 | |
| fi | |
| install_nerdctl(){ | |
| ## Install nerdctl tools. | |
| local dir install_exec_dir _install_exec_dirs=(/usr/local/bin /usr/bin /bin) | |
| for dir in "${_install_exec_dirs[@]}"; do | |
| case ":$PATH:" in | |
| *":$dir:"*) | |
| install_exec_dir="$dir" | |
| break | |
| ;; | |
| esac | |
| done | |
| if [[ "${install_exec_dir}" == "" ]]; then | |
| echo "ERROR: Not choose nerdctl install exec dir ..." | |
| exit 1 | |
| fi | |
| which nerdctl | |
| if [[ $? -ne 0 ]]; then | |
| echo -e "\x1b[32mINFO\x1b[0m: Install nerdctl ...." | |
| wget "${NERDCTL_DOWNLOAD_URL}" | |
| echo "INFO: Install nerdctl into ${dir}" | |
| tar Cxzvvf "${install_exec_dir}" "${NERDCTL_TARBALL_FILE}" | |
| sleep 1 | |
| install_nerdctl | |
| fi | |
| } | |
| find_bitnami_image(){ | |
| ## Find localhost images which name like "bitnami/" | |
| nerdctl ${NERD_OPTS} images | grep bitnami | grep -v '<none>' | grep -v "${TARGET_REGISTRY}" | awk '{print $1":"$2}' | |
| } | |
| gen_new_images_name(){ | |
| ## Change image url. | |
| ## eg: | |
| ## public.ecr.aws/bitnami/redis-exporter:tag ${registry}/bitnami/redis-exporter:tag | |
| ## bitnami/redis:tag ${registry}/bitnami/redis:tag | |
| local old_name=$1 registry=$2 keyword=bitnami | |
| echo "${old_name}" | sed -E 's|.*(bitnami)|'${registry}'/\1|' | |
| } | |
| login_registry(){ | |
| ## Login into registry | |
| local registry=$1 username=$2 password=$3 | |
| echo "INFO: login registry $registry ...." | |
| nerdctl login ${registry} -u "${username}" -p "${password}" | |
| if [[ $? -ne 0 ]]; then | |
| echo -e "\e1b[31mERROR\x1b[0m: login failed." | |
| exit 1 | |
| fi | |
| } | |
| main(){ | |
| install_nerdctl | |
| login_registry ${TARGET_REGISTRY} "${TARGET_REGSITRY_USERNAME}" "${TARGET_REGISTRY_PASSWORD}" | |
| for image in $(find_bitnami_image); do | |
| old_name=${image} | |
| new_name=$(gen_new_images_name ${image} ${TARGET_REGISTRY}) | |
| echo -e "\nINFO: ${old_name} \x1b[90;5m-->\x1b[0m ${new_name}" | |
| nerdctl ${NERD_OPTS} tag ${old_name} ${new_name} | |
| nerdctl ${NERD_OPTS} push ${new_name} | |
| done | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment