Post

Chainguard command line tools

Chainctl

chainctl docs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function cgr-find {
  if [ "${1}" = "-h" ]; then
    echo "Usage: chainguard-search [image]"
    echo "Search for an image by name with fzf."
  return
  fi
  if [ "${1}" = "" ]; then
    echo "Image name required."
    return
  fi
  # set orgs
  local privateorg="chainguard-private" # edit to your private registry
  # private images
  echo "---- private images ----"
  chainctl img repos list --parent $privateorg -o json |\
    jq -r '.items[].name' |\
    fzf --filter="${1}" |\
    sort
  # public images
  echo "---- public images ----"
  chainctl img repos list --public -o json |\
    jq -r '.items[].name' |\
    fzf --filter="${1}" |\
    sort
}

Export a list of images to a text file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function cgr-list {
  if [ "${1}" = "-h" ]; then
    echo "Usage: chainguard-list [outputfile]"
    echo "Export a list of images to a text file."
    return
  fi
  if [ "${1}" = "" ]; then
    echo "Output file required."
    return
  fi
  # get the current date
  local day=$(date +%Y-%m-%d)
  # split filename and extension with awk, keep the filename
  local filename=$(echo $1 | awk -F. '{print $1}')
  # set org name and export the list
  local privateorg="chainguard-private" # edit to your private registry
  chainctl img repos list --parent $privateorg -o json |\
    jq -r '.items[].name' |\
    sort > $filename-$day.txt
  # get length of images
  local count=$(wc -l $filename-$day.txt | awk '{print $1}')
  echo "List of $count images in $privateorg written to $filename-$day.txt 🎉"
}

Get the Chainguard group ID of a given domain

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function chainctl-id {
  if [ "${1}" = "-h" ]; then
    echo "Usage: chainctl-id [domain]"
    echo "Get the Chainguard group ID of a given domain."
    return
  fi
  if [ "${1}" = "" ]; then
    echo "Domain name required."
    return
  fi
  echo "Getting group ID for domain ${1} ..."
  chainctl iam organizations list -o json |\
    jq '.items[] | select(.name == '\"${1}\"') | .id'
}
This post is licensed under CC BY 4.0 by the author.