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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
|
load ../common
# Notes re. the public repository pull:
#
# 1. Each repository is in a separate test because sometimes they get stuck
# and it’s nice to see which repo is at fault.
#
# 2. These images are selected to be official-ish and small. My rough goal is
# to keep them under 10MiB uncompressed, but this isn’t working great. It
# may be worth our while to upload some small test images to these places.
#
# 3. Repositories not tested (yet?):
#
# a. Harbor (issue #899): Has a demo repo (https://demo.goharbor.io) that
# you can make an account on, but I couldn’t find a public repo, and
# the demo repo gets reset every two days.
#
# 2. b. Docker registry container (https://hub.docker.com/_/registry): Would
# need to set up an instance.
#
# c. Amazon public repo (issue #901,
# https://aws.amazon.com/blogs/containers/advice-for-customers-dealing-with-docker-hub-rate-limits-and-a-coming-soon-announcement/):
# Does not exist yet; coming “within weeks” of 2020-11-02.
#
# d. Microsoft Azure registry [1] (issue #902): I could not find any
# public images. It seems that public pull is “currently a preview
# feature” as of 2020-11-06 [2].
#
# [1]: https://azure.microsoft.com/en-us/services/container-registry
# [2]: https://docs.microsoft.com/en-us/azure/container-registry/container-registry-faq#how-do-i-enable-anonymous-pull-access
#
# e. JFrog / Artifactory (https://jfrog.com/container-registry/): Could
# not find any public registry.
setup () {
scope standard
[[ $CH_TEST_BUILDER = ch-image ]] || skip 'ch-image only'
}
image_ref_parse () {
# Try to parse image ref $1; expected output is provided on stdin and
# expected exit code in $2.
ref=$1
retcode_expected=$2
echo "--- parsing: ${ref}"
set +e
out=$(ch-image pull --parse-only "$ref" 2>&1)
retcode=$?
set -e
echo "--- return code: ${retcode}"
echo '--- output:'
echo "$out"
if [[ $retcode -ne "$retcode_expected" ]]; then
echo "fail: return code differs from expected ${retcode_expected}"
exit 1
fi
diff -u -I '^hint: https://' -I '^trace:' - <(echo "$out")
}
public_repos_ok () {
if [[ -n $CH_REGY_DEFAULT_HOST ]]; then
skip 'default registry host set' # avoid Docker Hub
fi
# Verify we can reach the public WWW, except on CI, where we insist these
# should work.
if [[ -z $CI ]]; then
# Check actual web access rather than ping because the latter can fail
# in weird ways for some VMs.
wget -nv -T3 --method=HEAD https://www.google.com/ \
|| skip 'no web access'
fi
}
@test 'image ref parsing' {
# simplest
cat <<'EOF' | image_ref_parse name 0
as string: name
for filename: name
fields:
host None
port None
path []
name 'name'
tag None
digest None
EOF
# one-component path
cat <<'EOF' | image_ref_parse path1/name 0
as string: path1/name
for filename: path1%name
fields:
host None
port None
path ['path1']
name 'name'
tag None
digest None
EOF
# two-component path
cat <<'EOF' | image_ref_parse path1/path2/name 0
as string: path1/path2/name
for filename: path1%path2%name
fields:
host None
port None
path ['path1', 'path2']
name 'name'
tag None
digest None
EOF
# host with dot
cat <<'EOF' | image_ref_parse example.com/name 0
as string: example.com/name
for filename: example.com%name
fields:
host 'example.com'
port None
path []
name 'name'
tag None
digest None
EOF
# host with dot, with port
cat <<'EOF' | image_ref_parse example.com:8080/name 0
as string: example.com:8080/name
for filename: example.com+8080%name
fields:
host 'example.com'
port 8080
path []
name 'name'
tag None
digest None
EOF
# host without dot, with port
cat <<'EOF' | image_ref_parse examplecom:8080/name 0
as string: examplecom:8080/name
for filename: examplecom+8080%name
fields:
host 'examplecom'
port 8080
path []
name 'name'
tag None
digest None
EOF
# no path, tag
cat <<'EOF' | image_ref_parse name:tag 0
as string: name:tag
for filename: name+tag
fields:
host None
port None
path []
name 'name'
tag 'tag'
digest None
EOF
# no path, digest
cat <<'EOF' | image_ref_parse name@sha256:feeddad 0
as string: name@sha256:feeddad
for filename: name@sha256+feeddad
fields:
host None
port None
path []
name 'name'
tag None
digest 'feeddad'
EOF
# everything, tagged
cat <<'EOF' | image_ref_parse example.com:8080/path1/path2/name:tag 0
as string: example.com:8080/path1/path2/name:tag
for filename: example.com+8080%path1%path2%name+tag
fields:
host 'example.com'
port 8080
path ['path1', 'path2']
name 'name'
tag 'tag'
digest None
EOF
# everything, tagged, filename component
cat <<'EOF' | image_ref_parse example.com:8080%path1%path2%name:tag 0
as string: example.com:8080/path1/path2/name:tag
for filename: example.com+8080%path1%path2%name+tag
fields:
host 'example.com'
port 8080
path ['path1', 'path2']
name 'name'
tag 'tag'
digest None
EOF
# everything, digest
cat <<'EOF' | image_ref_parse example.com:8080/path1/path2/name@sha256:feeddad 0
as string: example.com:8080/path1/path2/name@sha256:feeddad
for filename: example.com+8080%path1%path2%name@sha256+feeddad
fields:
host 'example.com'
port 8080
path ['path1', 'path2']
name 'name'
tag None
digest 'feeddad'
EOF
# errors
# invalid character in image name
cat <<'EOF' | image_ref_parse 'name*' 1
error: image ref syntax, char 5: name*
hint: https://hpc.github.io/charliecloud/faq.html#how-do-i-specify-an-image-reference
EOF
# missing port number
cat <<'EOF' | image_ref_parse 'example.com:/path1/name' 1
error: image ref syntax, char 13: example.com:/path1/name
hint: https://hpc.github.io/charliecloud/faq.html#how-do-i-specify-an-image-reference
EOF
# path with leading slash
cat <<'EOF' | image_ref_parse '/path1/name' 1
error: image ref syntax, char 1: /path1/name
hint: https://hpc.github.io/charliecloud/faq.html#how-do-i-specify-an-image-reference
EOF
# path but no name
cat <<'EOF' | image_ref_parse 'path1/' 1
error: image ref syntax, at end: path1/
hint: https://hpc.github.io/charliecloud/faq.html#how-do-i-specify-an-image-reference
EOF
# bad digest algorithm
cat <<'EOF' | image_ref_parse 'name@sha512:feeddad' 1
error: image ref syntax, char 5: name@sha512:feeddad
hint: https://hpc.github.io/charliecloud/faq.html#how-do-i-specify-an-image-reference
EOF
# both tag and digest
cat <<'EOF' | image_ref_parse 'name:tag@sha512:feeddad' 1
error: image ref syntax, char 9: name:tag@sha512:feeddad
hint: https://hpc.github.io/charliecloud/faq.html#how-do-i-specify-an-image-reference
EOF
}
@test 'pull image with quirky files' {
arch_exclude aarch64 # test image not available
arch_exclude ppc64le # test image not available
# Validate that layers replace symlinks correctly. See
# test/Dockerfile.symlink and issues #819 & #825.
CH_IMAGE_STORAGE=$BATS_TMPDIR/pull-quirks
img="${CH_IMAGE_STORAGE}/img/charliecloud%file-quirks+2020-10-21"
ch-image pull -vvv charliecloud/file-quirks:2020-10-21
ls -lh "${img}/test"
output_expected=$(cat <<'EOF'
regular file 'df_member'
symbolic link 'ds_link' -> 'ds_target'
regular file 'ds_target'
directory 'fd_member'
symbolic link 'fs_link' -> 'fs_target'
regular file 'fs_target'
symbolic link 'link_b0rken' -> 'doesnotexist'
symbolic link 'link_imageonly' -> '../test'
symbolic link 'link_self' -> 'link_self'
directory 'sd_link'
regular file 'sd_target'
regular file 'sf_link'
regular file 'sf_target'
symbolic link 'ss_link' -> 'ss_target2'
regular file 'ss_target1'
regular file 'ss_target2'
EOF
)
cd "${img}/test"
ls -lh .
run stat -c '%-14F %N' -- *
echo "$output"
[[ $status -eq 0 ]]
diff -u <(echo "$output_expected") <(echo "$output")
cd -
}
@test 'pull images with uncommon manifests' {
arch_exclude aarch64 # test image not available
arch_exclude ppc64le # test image not available
if [[ -n $CH_REGY_DEFAULT_HOST ]]; then
# Manifests seem to vary by registry; we need Docker Hub.
skip 'default registry host set'
fi
storage="${BATS_TMPDIR}/tmp"
cache=$storage/dlcache
CH_IMAGE_STORAGE=$storage
# OCI manifest; see issue #1184.
img=charliecloud/ocimanifest:2021-10-12
ch-image pull "$img"
# Manifest schema version one (v1); see issue #814. Use debian:squeeze
# because 1) it always returns a v1 manifest schema (regardless of media
# type specified), and 2) it isn't very large, thus keeps test time down.
img=debian+squeeze
ch-image pull "$img"
grep -F '"schemaVersion": 1' "${cache}/${img}%skinny.manifest.json"
rm -Rf --one-file-system "$storage"
}
@test 'pull from public repo: Docker Hub' {
public_repos_ok
ch-image pull registry-1.docker.io/library/alpine:3.17
}
@test 'pull from public repo: quay.io' {
# https://quay.io/repository/lib/hello-world
public_repos_ok
ch-image pull quay.io/lib/hello-world:latest
}
@test 'pull from public repo: gitlab.com' {
# https://gitlab.com/charliecloud/charliecloud/container_registry/8720624
public_repos_ok
ch-image pull registry.gitlab.com/charliecloud/charliecloud/ci_hello
}
@test 'pull from public repo: gcr.io' {
# https://console.cloud.google.com/gcr/images/google-containers/GLOBAL
# FIXME: “latest” tags do not work, but they do in Docker (issue #896)
# FIXME: arch-aware pull does not work either (issue #1100)
public_repos_ok
ch-image pull --arch=yolo gcr.io/google-containers/busybox:1.27
}
@test 'pull from public repo: nVidia NGC' {
# https://catalog.ngc.nvidia.com/orgs/nvidia/teams/doca/containers/dpf_containers
public_repos_ok
ch-image pull -vv nvcr.io/nvidia/doca/dpf_containers:1.0.2-ubuntu22.04-distroless
}
@test 'pull from public repo: catalog.redhat.com' {
# https://catalog.redhat.com/software/containers/ubi10-minimal/66f16af45db83414cddcfc99
public_repos_ok
ch-image pull registry.access.redhat.com/ubi10-minimal
}
@test 'pull from public repo: mcr.microsoft.com' {
# https://github.com/microsoft/containerregistry
# https://mcr.microsoft.com/en-us/artifact/mar/mcr/hello-world
# Note: MS doesn’t seem to have any arch-aware images at all?
public_repos_ok
ch-image pull --arch=yolo mcr.microsoft.com/mcr/hello-world:latest
}
@test 'pull image with metadata' {
arch_exclude aarch64 # test image not available
arch_exclude ppc64le # test image not available
tag=2021-01-15
name=charliecloud/metadata:$tag
img=$CH_IMAGE_STORAGE/img/charliecloud%metadata+$tag
ch-image pull "$name"
# Volume mount points exist?
ls -lh "${img}/mnt"
test -d "${img}/mnt/foo"
test -d "${img}/mnt/bar"
# /ch/environment contents
diff -u - "${img}/ch/environment" <<'EOF'
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ch_bar=bar-ev
ch_foo=foo-ev
EOF
# /ch/metadata.json contents
diff -u -I '^.*"created":.*,$' - "${img}/ch/metadata.json" <<'EOF'
{
"arch": "amd64",
"arg": {
"FAKEROOTDONTTRYCHOWN": "1",
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TAR_OPTIONS": "--no-same-owner"
},
"cmd": [],
"cwd": "/mnt",
"entrypoint": [],
"env": {
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ch_bar": "bar-ev",
"ch_foo": "foo-ev"
},
"history": [
{
"created": "2020-04-24T01:05:35.458457398Z",
"created_by": "/bin/sh -c #(nop) ADD file:a0afd0b0db7f9ee9496186ead087ec00edd1386ea8c018557d15720053f7308e in / "
},
{
"created": "2020-04-24T01:05:35.807646609Z",
"created_by": "/bin/sh -c #(nop) CMD [\"/bin/sh\"]",
"empty_layer": true
},
{
"created": "2020-12-10T18:26:16.62246537Z",
"created_by": "/bin/sh -c #(nop) CMD [\"true\"]",
"empty_layer": true
},
{
"created": "2021-01-08T00:57:33.450706788Z",
"created_by": "/bin/sh -c #(nop) CMD [\"bar\" \"baz\"]",
"empty_layer": true
},
{
"created": "2021-01-08T00:57:33.675120552Z",
"created_by": "/bin/sh -c #(nop) ENTRYPOINT [\"/bin/echo\" \"foo\"]",
"empty_layer": true
},
{
"created": "2021-01-16T00:12:10.147564398Z",
"created_by": "/bin/sh -c #(nop) ENV ch_foo=foo-ev ch_bar=bar-ev",
"empty_layer": true
},
{
"created": "2021-01-16T00:12:10.340268945Z",
"created_by": "/bin/sh -c #(nop) EXPOSE 5309/udp 867",
"empty_layer": true
},
{
"created": "2021-01-16T00:12:10.590808975Z",
"created_by": "/bin/sh -c #(nop) HEALTHCHECK &{[\"CMD\" \"/bin/true\"] \"1m0s\" \"5s\" \"0s\" '\\x00'}",
"empty_layer": true
},
{
"created": "2021-01-16T00:12:10.749205247Z",
"created_by": "/bin/sh -c #(nop) LABEL ch_foo=foo-label ch_bar=bar-label",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:10.919558634Z",
"created_by": "/bin/sh -c #(nop) MAINTAINER charlie@example.com",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:11.080200702Z",
"created_by": "/bin/sh -c #(nop) ONBUILD RUN echo hello",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:11.900757214Z",
"created_by": "/bin/sh -c echo hello",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:12.868439691Z",
"created_by": "/bin/echo world",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:13.055783024Z",
"created_by": "/bin/ash -c #(nop) SHELL [/bin/ash -c]",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:13.473299627Z",
"created_by": "/bin/ash -c #(nop) STOPSIGNAL SIGWINCH",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:13.644005108Z",
"created_by": "/bin/ash -c #(nop) USER charlie:chargrp",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:13.83546594Z",
"created_by": "/bin/ash -c #(nop) WORKDIR /mnt",
"empty_layer": true
},
{
"author": "charlie@example.com",
"created": "2021-01-16T00:12:14.042791834Z",
"created_by": "/bin/ash -c #(nop) VOLUME [/mnt/foo /mnt/bar /mnt/foo]",
"empty_layer": true
}
],
"labels": {
"ch_bar": "bar-label",
"ch_foo": "foo-label"
},
"shell": [
"/bin/ash",
"-c"
],
"volumes": [
"/mnt/bar",
"/mnt/foo"
]
}
EOF
}
@test 'pull by arch' {
# Has fat manifest; requested arch exists. There’s not much simple to look
# for in the output, so just see if it works. NOTE: As a temporary fix for
# some test suite problems, I’m changing all instances of alpine:latest
# here to alpine:3.15. We really need a more permanent solution for this
# (see #1485)
#ch-image --arch=yolo pull alpine:3.15 # see #1953
ch-image --arch=host pull alpine:3.15
ch-image --arch=amd64 pull alpine:3.15
ch-image --arch=arm64/v8 pull alpine:3.15
# Has fat manifest, but requested arch does not exist.
run ch-image --arch=doesnotexist pull alpine:3.15
echo "$output"
[[ $status -eq 1 ]]
[[ $output = *'requested arch unavailable:'*'available:'* ]]
# Delete it so we don’t try to use a non-matching arch for other testing.
# FIXME: After #1485 is closed, revert to alpine:latest or alpine:3.17 and
# delete cache along with image.
ch-image delete alpine:3.15 || true
# No fat manifest.
ch-image --arch=yolo pull charliecloud/metadata:2021-01-15
ch-image --arch=amd64 pull charliecloud/metadata:2021-01-15
if [[ $(uname -m) == 'x86_64' ]]; then
ch-image --arch=host pull charliecloud/metadata:2021-01-15
run ch-image --arch=arm64/v8 pull charliecloud/metadata:2021-01-15
echo "$output"
[[ $status -eq 1 ]]
[[ $output = *'image is architecture-unaware'*'consider --arch=yolo'* ]]
fi
}
@test 'pull images that do not exist' {
if [[ -n $CH_REGY_DEFAULT_HOST ]]; then
skip 'default registry host set' # errors are Docker Hub specific
fi
# name does not exist remotely, in library
run ch-image pull doesnotexist:latest
echo "$output"
[[ $status -eq 1 ]]
[[ $output = *'registry-1.docker.io:443/library/doesnotexist:latest'* ]]
# tag does not exist remotely, in library
run ch-image pull alpine:doesnotexist
echo "$output"
[[ $status -eq 1 ]]
[[ $output = *'registry-1.docker.io:443/library/alpine:doesnotexist'* ]]
# name does not exist remotely, not in library
run ch-image pull charliecloud/doesnotexist:latest
echo "$output"
[[ $status -eq 1 ]]
[[ $output = *'registry-1.docker.io:443/charliecloud/doesnotexist:latest'* ]]
# tag does not exist remotely, not in library
run ch-image pull charliecloud/metadata:doesnotexist
echo "$output"
[[ $status -eq 1 ]]
[[ $output = *'registry-1.docker.io:443/charliecloud/metadata:doesnotexist'* ]]
}
# See issue #1925
@test 'remove part_ files' {
# Create a problematic file and list images to provoke it
touch "$CH_IMAGE_STORAGE"/dlcache/part_PROBLEM
run ch-image list
echo "$output"
[[ $status -eq 0 ]]
# Remove the problematic file to clean up
rm -f "$CH_IMAGE_STORAGE"/dlcache/part_PROBLEM
}
|