github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/snap/local/wrappers/fetch-oci (about)

     1  #!/bin/sh
     2  
     3  PATH=/snap/bin:$PATH
     4  
     5  # microk8s is required.
     6  if ! which microk8s.kubectl; then
     7      echo "microk8s is not installed."
     8      exit 0
     9  fi
    10  
    11  if ! which timeout; then
    12      echo "timeout is not installed."
    13      exit 0
    14  fi
    15  
    16  container_cmd=microk8s.ctr
    17  image_arg="--namespace k8s.io images"
    18  if ! which $container_cmd; then
    19      container_cmd=microk8s.docker
    20      image_arg=image
    21      if ! which $container_cmd; then
    22          echo "Neither docker or ctr image control found."
    23          exit 0
    24      fi
    25  fi
    26  
    27  # We will give up if below steps can not be finished in 110s because snapd will kill us in 120s.
    28  # It's not an install/refresh blocker if we can't get the images.
    29  timeout 110s sh <<EOT || echo "Timed out waiting to install microk8s image."
    30  
    31  echo "Wait for microk8s to be ready if needed."
    32  microk8s.status --wait-ready --timeout 30 2>&1
    33  juju_version=\$(/snap/bin/juju version | rev | cut -d- -f3- | rev)
    34  oci_image="docker.io/jujusolutions/jujud-operator:\$juju_version"
    35  mongo_image="docker.io/jujusolutions/juju-db:4.4"
    36  
    37  echo "Going to cache images: \$oci_image and \$mongo_image."
    38  echo "Pulling: \$oci_image."
    39  
    40  $container_cmd $image_arg list | grep \$oci_image || $container_cmd $image_arg pull \$oci_image || true
    41  echo "Pulling: \$mongo_image."
    42  $container_cmd $image_arg list | grep \$mongo_image || $container_cmd $image_arg pull \$mongo_image || true
    43  EOT