UiPath Documentation
automation-suite
2.2510
true
Linux 版 Automation Suite 安装指南
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

如何将本地 Docker 映像推送到集群内注册表

使用提供的 bash 脚本,将本地可用的 Docker 映像推送到 Automation Suite High Availability (HA) 集群内注册表中的所有注册表 Pod。

使用此脚本将本地可用的 Docker 映像推送到 Automation Suite High Availability (HA) 集群内注册表中的所有注册表 Pod。

备注:

集群内注册表在 HA 环境中有多个副本。无法通过registry.FQDN推送 Docker 映像。要将 Docker 映像推送到所有注册表 Pod,请使用以下脚本。

先决条件

要推送的 Docker 映像必须存在于localhost:30071下的本地 Podman 存储中。

步骤

  1. 将以下脚本保存到文件中,例如push-to-registry.sh

    #!/bin/bash
    # Image must already be present in the local Podman store under localhost:30071
    # run command as ./script.sh localhost:30071/myimage:1.0.0
    set -euo pipefail
    [[ $# -lt 1 ]] && { echo "Usage: $0 <image-name>"; exit 1; }
    IMAGE=$1
    DOCKER_REGISTRY_NODEPORT=30071
    function error() {
      echo -e "\e[0;31m[ERROR][$(date +'%Y-%m-%dT%H:%M:%S%z')]:\e[0m $*" >&2
      exit 1
    }
    function info() {
      echo "[INFO] [$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*"
    }
    function warn() {
      echo -e "\e[0;33m[WARN] [$(date +'%Y-%m-%dT%H:%M:%S%z')]:\e[0m $*" >&2
    }
    function get_registry_addresses() {
      local namespace="docker-registry"
      local lh_registry
      local server_node_count
      lh_registry=$(kubectl get deployment -n "${namespace}" docker-registry --ignore-not-found --no-headers | wc -l)
      server_node_count=$(kubectl get nodes -l "node-role.kubernetes.io/master=true" --no-headers | wc -l)
      IFS=" " read -r -a registry_addresses <<< \
        "$(kubectl get pods -n "${namespace}" -o jsonpath="{.items[*].status.podIP}" -l app=docker-registry)"
      if [[ "${lh_registry}" -eq 1 ]]; then
        [[ "${#registry_addresses[@]}" -eq 1 ]] || error "Expected 1 registry pod; found ${#registry_addresses[@]}."
      else
        [[ "${#registry_addresses[@]}" -eq "${server_node_count}" ]] || \
          error "Expected ${server_node_count} registry pods; found ${#registry_addresses[@]}."
      fi
      echo "${registry_addresses[@]}"
    }
    podman image exists "localhost:${DOCKER_REGISTRY_NODEPORT}/${IMAGE}" \
      || error "Image not found locally: localhost:${DOCKER_REGISTRY_NODEPORT}/${IMAGE}"
    IFS=" " read -r -a registry_addresses <<< "$(get_registry_addresses)"
    info "Found ${#registry_addresses[@]} registry pod(s)"
    for ip in "${registry_addresses[@]}"; do
      local_ref="localhost:${DOCKER_REGISTRY_NODEPORT}/${IMAGE}"
      remote_ref="${ip}:5000/${IMAGE}"
      local try=0
      local max_tries=10
      local pushed=false
      info "Tagging ${local_ref} → ${remote_ref}"
      podman tag "${local_ref}" "${remote_ref}"
      podman login "${ip}:5000" --tls-verify=false
      while [[ "${pushed}" == false ]] && (( try < max_tries )); do
        try=$(( try + 1 ))
        info "Pushing ${IMAGE} → ${ip}:5000 (attempt ${try}/${max_tries})"
        if podman push "${remote_ref}" --tls-verify=false; then
          pushed=true
        else
          warn "Push failed — retrying in 60s"
          sleep 60
        fi
      done
      [[ "${pushed}" == true ]] || error "Failed to push ${IMAGE} to ${ip}:5000 after ${max_tries} attempts"
    done
    info "Done — ${IMAGE} pushed to all registry pods"
    #!/bin/bash
    # Image must already be present in the local Podman store under localhost:30071
    # run command as ./script.sh localhost:30071/myimage:1.0.0
    set -euo pipefail
    [[ $# -lt 1 ]] && { echo "Usage: $0 <image-name>"; exit 1; }
    IMAGE=$1
    DOCKER_REGISTRY_NODEPORT=30071
    function error() {
      echo -e "\e[0;31m[ERROR][$(date +'%Y-%m-%dT%H:%M:%S%z')]:\e[0m $*" >&2
      exit 1
    }
    function info() {
      echo "[INFO] [$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*"
    }
    function warn() {
      echo -e "\e[0;33m[WARN] [$(date +'%Y-%m-%dT%H:%M:%S%z')]:\e[0m $*" >&2
    }
    function get_registry_addresses() {
      local namespace="docker-registry"
      local lh_registry
      local server_node_count
      lh_registry=$(kubectl get deployment -n "${namespace}" docker-registry --ignore-not-found --no-headers | wc -l)
      server_node_count=$(kubectl get nodes -l "node-role.kubernetes.io/master=true" --no-headers | wc -l)
      IFS=" " read -r -a registry_addresses <<< \
        "$(kubectl get pods -n "${namespace}" -o jsonpath="{.items[*].status.podIP}" -l app=docker-registry)"
      if [[ "${lh_registry}" -eq 1 ]]; then
        [[ "${#registry_addresses[@]}" -eq 1 ]] || error "Expected 1 registry pod; found ${#registry_addresses[@]}."
      else
        [[ "${#registry_addresses[@]}" -eq "${server_node_count}" ]] || \
          error "Expected ${server_node_count} registry pods; found ${#registry_addresses[@]}."
      fi
      echo "${registry_addresses[@]}"
    }
    podman image exists "localhost:${DOCKER_REGISTRY_NODEPORT}/${IMAGE}" \
      || error "Image not found locally: localhost:${DOCKER_REGISTRY_NODEPORT}/${IMAGE}"
    IFS=" " read -r -a registry_addresses <<< "$(get_registry_addresses)"
    info "Found ${#registry_addresses[@]} registry pod(s)"
    for ip in "${registry_addresses[@]}"; do
      local_ref="localhost:${DOCKER_REGISTRY_NODEPORT}/${IMAGE}"
      remote_ref="${ip}:5000/${IMAGE}"
      local try=0
      local max_tries=10
      local pushed=false
      info "Tagging ${local_ref} → ${remote_ref}"
      podman tag "${local_ref}" "${remote_ref}"
      podman login "${ip}:5000" --tls-verify=false
      while [[ "${pushed}" == false ]] && (( try < max_tries )); do
        try=$(( try + 1 ))
        info "Pushing ${IMAGE} → ${ip}:5000 (attempt ${try}/${max_tries})"
        if podman push "${remote_ref}" --tls-verify=false; then
          pushed=true
        else
          warn "Push failed — retrying in 60s"
          sleep 60
        fi
      done
      [[ "${pushed}" == true ]] || error "Failed to push ${IMAGE} to ${ip}:5000 after ${max_tries} attempts"
    done
    info "Done — ${IMAGE} pushed to all registry pods"
    
  2. 使脚本可执行:

    chmod +x push-to-registry.sh
    chmod +x push-to-registry.sh
    
  3. 运行脚本,并将映像名称作为参数传递:

    ./push-to-registry.sh localhost:30071/<image-name>:<tag>
    ./push-to-registry.sh localhost:30071/<image-name>:<tag>
    

结果

脚本成功完成后,将输出类似于以下内容的消息:

[INFO] [2024-01-01T00:00:00+0000]: Done — localhost:30071/myimage:1.0.0 pushed to all registry pods
[INFO] [2024-01-01T00:00:00+0000]: Done — localhost:30071/myimage:1.0.0 pushed to all registry pods
  • 先决条件
  • 步骤
  • 结果

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新