Skip to content

Commit

Permalink
molior-deploy: support login for multiple docker registries
Browse files Browse the repository at this point in the history
using multiline env var $MOLIOR_DOCKER_LOGINS
  • Loading branch information
neolynx committed Jun 12, 2023
1 parent e9ec03a commit d7ee6d6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions doc/molior-deploy.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ DOCKER PARAMETERS
DOCKER_UPGRADE_DEDUP_IGNORE Do not deduplicate newline separated list of docker images when creating a upgrade deployment
MOLIOR_DOCKER_LOGIN_USER Login user and server for pulling images ([email protected])
MOLIOR_DOCKER_LOGIN_TOKEN Login token for pulling images
MOLIOR_DOCKER_LOGINS Use individual logins for multiple registries (list of user:pass@registry, separated by whitespace, replaces MOLIOR_DOCKER_LOGIN_USER/TOKEN above)


NOTE
Expand Down
50 changes: 35 additions & 15 deletions molior-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -1259,26 +1259,46 @@ install_docker_pull()
if [ -f $target/tmp/docker-compose/.env ]; then
container=`. $target/tmp/docker-compose/.env; eval echo $container`
fi
if [ -n "$MOLIOR_DOCKER_LOGIN_USER" ] && [ -n "$MOLIOR_DOCKER_LOGIN_TOKEN" ]; then
if echo $MOLIOR_DOCKER_LOGIN_USER | grep -q "@"; then
docker_user=`echo $MOLIOR_DOCKER_LOGIN_USER | cut -d@ -f1`
if [ -n "$MOLIOR_DOCKER_LOGIN_USER" -a -n "$MOLIOR_DOCKER_LOGIN_TOKEN" ] || [ -n "$MOLIOR_DOCKER_LOGINS" ]; then
docker_registry=""
docker_user=""
docker_pass=""
if [ -n "$MOLIOR_DOCKER_LOGINS" ]; then
for docker_login in $MOLIOR_DOCKER_LOGINS
do
test -z "$docker_login" && continue
docker_registry=`echo $docker_login | cut -d@ -f2`

if echo "$container" | grep -q "^$docker_registry"; then
l=`echo $docker_login | cut -d@ -f1`
docker_user=`echo $l | cut -d: -f1`
docker_pass=`echo $l | cut -d: -f2`
break
fi
done
elif echo $MOLIOR_DOCKER_LOGIN_USER | grep -q "@"; then
docker_registry=`echo $MOLIOR_DOCKER_LOGIN_USER | cut -d@ -f2`
docker_user=`echo $MOLIOR_DOCKER_LOGIN_USER | cut -d@ -f1`
docker_pass=$MOLIOR_DOCKER_LOGIN_TOKEN
else
docker_user=$MOLIOR_DOCKER_LOGIN_USER
docker_registry=`echo $container | cut -d: -f1`
docker_user=$MOLIOR_DOCKER_LOGIN_USER
docker_pass=$MOLIOR_DOCKER_LOGIN_TOKEN
fi
if ! echo $docker_login_registries | grep -w -q $docker_registry; then
log "docker login '$docker_registry'"
echo chroot $target sh -c "docker login $docker_registry -u $docker_user -p ****" >&2
set +x
echo $MOLIOR_DOCKER_LOGIN_TOKEN | chroot $target sh -c "docker login $docker_registry -u $docker_user --password-stdin" >&2
ret=$?
set -x
if [ "$ret" -ne 0 ]; then
log_warn "Error docker login $docker_registry"
return $ret
if [ -n "$docker_user" ]; then
if ! echo $docker_login_registries | grep -w -q $docker_registry; then
log "docker login '$docker_registry'"
echo chroot $target sh -c "docker login $docker_registry -u $docker_user -p ****" >&2
set +x
echo $docker_pass | chroot $target sh -c "docker login $docker_registry -u $docker_user --password-stdin" >&2
ret=$?
set -x
if [ "$ret" -ne 0 ]; then
log_warn "Error docker login $docker_registry"
return $ret
fi
docker_login_registries="$docker_login_registries $docker_registry"
fi
docker_login_registries="$docker_login_registries $docker_registry"
fi
fi
log "docker pull $container ($i/$total_docker_images)"
Expand Down

0 comments on commit d7ee6d6

Please sign in to comment.