...

Text file src/github.com/docker/distribution/contrib/docker-integration/helpers.bash

Documentation: github.com/docker/distribution/contrib/docker-integration

     1# has_digest enforces the last output line is "Digest: sha256:..."
     2# the input is the output from a docker push cli command
     3function has_digest() {
     4	filtered=$(echo "$1" |sed -rn '/[dD]igest\: sha(256|384|512)/ p')
     5	[ "$filtered" != "" ]
     6	# See http://wiki.alpinelinux.org/wiki/Regex#BREs before making changes to regex
     7	digest=$(expr "$filtered" : ".*\(sha[0-9]\{3,3\}:[a-z0-9]*\)")
     8}
     9
    10# tempImage creates a new image using the provided name
    11# requires bats
    12function tempImage() {
    13	dir=$(mktemp -d)
    14	run dd if=/dev/urandom of="$dir/f" bs=1024 count=512
    15	cat <<DockerFileContent > "$dir/Dockerfile"
    16FROM scratch
    17COPY f /f
    18
    19CMD []
    20DockerFileContent
    21
    22	cp_t $dir "/tmpbuild/"
    23	exec_t "cd /tmpbuild/; docker build --no-cache -t $1 .; rm -rf /tmpbuild/"
    24}
    25
    26# skip basic auth tests with Docker 1.6, where they don't pass due to
    27# certificate issues, requires bats
    28function basic_auth_version_check() {
    29	run sh -c 'docker version | fgrep -q "Client version: 1.6."'
    30	if [ "$status" -eq 0 ]; then
    31		skip "Basic auth tests don't support 1.6.x"
    32	fi
    33}
    34
    35email="a@nowhere.com"
    36
    37# docker_t_login calls login with email depending on version
    38function docker_t_login() {
    39	# Only pass email field pre 1.11, no deprecation warning
    40	parse_version "$GOLEM_DIND_VERSION"
    41	v=$version
    42	parse_version "1.11.0"
    43	if [ "$v" -lt "$version" ]; then
    44		run docker_t login -e $email $@
    45	else
    46		run docker_t login $@
    47	fi
    48}
    49
    50# login issues a login to docker to the provided server
    51# uses user, password, and email variables set outside of function
    52# requies bats
    53function login() {
    54	rm -f /root/.docker/config.json
    55
    56	docker_t_login -u $user -p $password $1
    57	if [ "$status" -ne 0 ]; then
    58		echo $output
    59	fi
    60	[ "$status" -eq 0 ]
    61
    62	# Handle different deprecation warnings
    63	parse_version "$GOLEM_DIND_VERSION"
    64	v=$version
    65	parse_version "1.11.0"
    66	if [ "$v" -lt "$version" ]; then
    67		# First line is WARNING about credential save or email deprecation (maybe both)
    68		[ "${lines[2]}" = "Login Succeeded" -o "${lines[1]}" = "Login Succeeded" ]
    69	else
    70		[ "${lines[0]}" = "Login Succeeded" ]
    71	fi
    72
    73}
    74
    75function login_oauth() {
    76	login $@
    77
    78	tmpFile=$(mktemp)
    79	get_file_t /root/.docker/config.json $tmpFile
    80	run awk -v RS="" "/\"$1\": \\{[[:space:]]+\"auth\": \"[[:alnum:]]+\",[[:space:]]+\"identitytoken\"/ {exit 3}" $tmpFile
    81	[ "$status" -eq 3 ]
    82}
    83
    84function parse_version() {
    85	version=$(echo "$1" | cut -d '-' -f1) # Strip anything after '-'
    86	major=$(echo "$version" | cut -d . -f1)
    87	minor=$(echo "$version" | cut -d . -f2)
    88	rev=$(echo "$version" | cut -d . -f3)
    89
    90	version=$((major * 1000 * 1000 + minor * 1000 + rev))
    91}
    92
    93function version_check() {
    94	name=$1
    95	checkv=$2
    96	minv=$3
    97	parse_version "$checkv"
    98	v=$version
    99	parse_version "$minv"
   100	if [ "$v" -lt "$version" ]; then
   101		skip "$name version \"$checkv\" does not meet required version \"$minv\""
   102	fi
   103}
   104
   105function get_file_t() {
   106	docker cp dockerdaemon:$1 $2
   107}
   108
   109function cp_t() {
   110	docker cp $1 dockerdaemon:$2
   111}
   112
   113function exec_t() {
   114	docker exec dockerdaemon sh -c "$@"
   115}
   116
   117function docker_t() {
   118	docker exec dockerdaemon docker $@
   119}
   120
   121# build creates a new docker image id from another image
   122function build() {
   123	docker exec -i dockerdaemon docker build --no-cache -t $1 - <<DOCKERFILE
   124FROM $2
   125MAINTAINER distribution@docker.com
   126DOCKERFILE
   127}

View as plain text