k8x/attach_private_registry.sh

55 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2024-05-17 21:45:52 -04:00
#!/bin/bash
echo ""
echo "... ] ATTACHING PRIVATE DOCKER REGISTRY [ ..."
echo ""
HOME=$( cd "$(dirname "$0")" && pwd )
source $HOME/config
export KUBECONFIG=$ADMIN_KUBECONFIG
#TODO: Installing the default private registry (the one we use to host and reuse it as default on kubelet worker installation)
# could also be provided with this script as a secret and use it with ImagePullSecret.
if [ -z "$1" ]; then
echo "] Usage: ./attach_private_registry.sh <secret-name>"
exit 2
fi
REG_NAME="$1"
echo -n "] Target secret namespace: "
read NSPACE
if [ -z "$NSPACE" ]; then
echo "] No namespace"
exit 1
fi
echo -n "] Enter Docker registry user: "
read REGISTRY_USER
echo -n "] Enter Docker registry password (token): "
read REGISTRY_PASS
echo -n "] Enter Docker registry email: "
read REGISTRY_EMAIL
echo -n "] Enter Docker registry url (empty for docker hub): "
read REGISTRY_URL
if [ -z "$REGISTRY_URL" ]; then
CONFIG_URL="--docker-server=https://index.docker.io/v2/"
else
CONFIG_URL="--docker-server=https://${REGISTRY_URL}/v2/"
fi
SECRET_NAME="registry-${NSPACE}-${REG_NAME}"
CONFIG_SECRET="${SECRET_NAME} ${CONFIG_URL} --docker-username=${REGISTRY_USER} --docker-password=${REGISTRY_PASS} --docker-email=${REGISTRY_EMAIL}"
CMD="/usr/local/bin/k -n ${NSPACE} create secret docker-registry ${CONFIG_SECRET}"
echo ""
echo "Executing command: ${CMD}"
echo -n "Is that okay [y/n]? "
read answer
if [ "$answer" != "${answer#[Yy]}" ]; then
${CMD}
fi