Skip to content

Instantly share code, notes, and snippets.

@guessi
Created July 29, 2015 00:36
Show Gist options
  • Save guessi/ba752cb412fc77685495 to your computer and use it in GitHub Desktop.
Save guessi/ba752cb412fc77685495 to your computer and use it in GitHub Desktop.
validation image name for docker agent
#!/bin/sh
PATTERN="^([a-z0-9]+([._-]{0,1}[a-z0-9])*\/)*[a-zA-Z0-9]+([._-]{0,1}[a-z0-9])*(:[A-Za-z0-9][A-Za-z0-9.-]*){0,1}$"
for input in \
i \
image \
i:t \
i:t::: \
image:t \
i:tag \
r/i \
r/i: \
r/i:t \
repo/i \
repo/i:t \
repo/i:t: \
repo/i:t:t2 \
repo_/i \
repo_test/i \
repo__test/i \
repo.s-i_tory/i; do
printf "input: %-16s ---> " $input
echo "$input" | egrep -q -s "${PATTERN}"
[ $? -eq 0 ] && echo "pass (0)" || echo "fail (1)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment