Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot perform an interactive login from a non TTY device #1

Open
alieismy opened this issue Sep 29, 2024 · 1 comment
Open

Comments

@alieismy
Copy link

按照作者步骤,在执行github action时报错如下:
Run docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY
docker login -u $ALIYUN_REGISTRY_USER -p $ALIYUN_REGISTRY_PASSWORD $ALIYUN_REGISTRY

数据预处理,判断镜像是否重名

declare -A duplicate_images
declare -A temp_map
while IFS= read -r line || [ -n "$line" ]; do
# 忽略空行与注释
[[ -z "$line" ]] && continue
if echo "$line" | grep -q '^\s*#'; then
continue
fi

  # 获取镜像的完整名称,例如kasmweb/nginx:1.[2](https://github.com/alieismy/aliyun-docker-image-mirror/actions/runs/11093801067/job/30820529818#step:8:2)5.3(命名空间/镜像名:版本号)
  image=$(echo "$line" | awk '{print $NF}')
  # 将@sha256:等字符删除
  image="${image%%@*}"
  echo "image $image"
  # 获取镜像名:版本号  例如nginx:1.25.[3](https://github.com/alieismy/aliyun-docker-image-mirror/actions/runs/11093801067/job/30820529818#step:8:3)
  image_name_tag=$(echo "$image" | awk -F'/' '{print $NF}')
  echo "image_name_tag $image_name_tag"
  # 获取命名空间 例如kasmweb,  这里有种特殊情况 docker.io/nginx,把docker.io当成命名空间,也OK
  name_space=$(echo "$image" | awk -F'/' '{if (NF==3) print $2; else if (NF==2) print $1; else print ""}')
  echo "name_space: $name_space"
  # 这里不要是空值影响判断
  name_space="${name_space}_"
  # 获取镜像名例如nginx
  image_name=$(echo "$image_name_tag" | awk -F':' '{print $1}')
  echo "image_name: $image_name"

  # 如果镜像存在于数组中,则添加temp_map
  if [[ -n "${temp_map[$image_name]}" ]]; then
       # 如果temp_map已经存在镜像名,判断是不是同一命名空间
       if [[ "${temp_map[$image_name]}" != $name_space  ]]; then
          echo "duplicate image name: $image_name"
          duplicate_images[$image_name]="true"
       fi
  else
      # 存镜像的命名空间
      temp_map[$image_name]=$name_space
  fi       

done < images.txt

while IFS= read -r line || [ -n "$line" ]; do
# 忽略空行与注释
[[ -z "$line" ]] && continue
if echo "$line" | grep -q '^\s*#'; then
continue
fi

  echo "docker pull $line"
  docker pull $line
  platform=$(echo "$line" | awk -F'--platform[ =]' '{if (NF>1) print $2}' | awk '{print $1}')
  echo "platform is $platform"
  # 如果存在架构信息 将架构信息拼到镜像名称前面
  if [ -z "$platform" ]; then
      platform_prefix=""
  else
      platform_prefix="${platform//\//_}_"
  fi
  echo "platform_prefix is $platform_prefix"
  # 获取镜像的完整名称,例如kasmweb/nginx:1.2[5](https://github.com/alieismy/aliyun-docker-image-mirror/actions/runs/11093801067/job/30820529818#step:8:5).3(命名空间/镜像名:版本号)
  image=$(echo "$line" | awk '{print $NF}')

  # 获取 镜像名:版本号  例如nginx:1.25.3
  image_name_tag=$(echo "$image" | awk -F'/' '{print $NF}')
  # 获取命名空间 例如kasmweb  这里有种特殊情况 docker.io/nginx,把docker.io当成命名空间,也OK
  name_space=$(echo "$image" | awk -F'/' '{if (NF==3) print $2; else if (NF==2) print $1; else print ""}')
  # 获取镜像名例  例如nginx
  image_name=$(echo "$image_name_tag" | awk -F':' '{print $1}')

  name_space_prefix=""
  # 如果镜像名重名
  if [[ -n "${duplicate_images[$image_name]}" ]]; then
     #如果命名空间非空,将命名空间加到前缀
     if [[ -n "${name_space}" ]]; then
        name_space_prefix="${name_space}_"
     fi
  fi

  # 将@sha25[6](https://github.com/alieismy/aliyun-docker-image-mirror/actions/runs/11093801067/job/30820529818#step:8:6):等字符删除
  image_name_tag="${image_name_tag%%@*}"
  new_image="$ALIYUN_REGISTRY/$ALIYUN_NAME_SPACE/$platform_prefix$name_space_prefix$image_name_tag"
  echo "docker tag $image $new_image"
  docker tag $image $new_image
  echo "docker push $new_image"
  docker push $new_image
  echo "开始清理磁盘空间"
  echo "=============================================================================="
  df -hT
  echo "=============================================================================="
  docker rmi $image
  docker rmi $new_image
  echo "磁盘空间清理完毕"
  echo "=============================================================================="
  df -hT
  echo "=============================================================================="     

done < images.txt
shell: /usr/bin/bash -e {0}
env:
ALIYUN_REGISTRY:
ALIYUN_NAME_SPACE:
ALIYUN_REGISTRY_USER:
ALIYUN_REGISTRY_PASSWORD:
Error: Cannot perform an interactive login from a non TTY device
Error: Process completed with exit code 1.

还需要在哪里设置呢?

@shxxhs
Copy link

shxxhs commented Oct 14, 2024

同样的问题,在setting中分别设置4个登陆凭证的的secret解决了。
pic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants