buildah/tests/test_buildah.sh
Ed Santiago d3311a0623 buildah test helper: run registry:2.6, not :2
The docker.io/registry:2 image broke suddenly and with no warning:

https://github.com/docker/distribution-library-image/issues/106

Symptom: running 'htpasswd' from that container no longer works,
even though it's been documented for years (at docker.com) and
as of this writing still remains documented.

One solution is to run htpasswd locally (requires installing the
httpd-tools package) or using any crypt library to hash. Not
hard, but tedious, and it doesn't address the issue of the
docker registry:2 image being a moving target.

I choose to force the use of the :2.6 tag, in hopes that that
image will remain unmodified. Refactored to use FQIN instead
of shortname, and to define it in only one place.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-06-24 13:11:01 -06:00

66 lines
1.8 KiB
Bash
Executable File

#!/bin/bash -e
# Log program and kernel versions
echo "Important package versions:"
(
uname -r
rpm -qa | egrep 'buildah|podman|conmon|crun|runc|iptable|slirp|systemd' | sort
) | sed -e 's/^/ /'
# Log environment; or at least the useful bits
echo "Environment:"
env | grep -v LS_COLORS= | sort | sed -e 's/^/ /'
export BUILDAH_BINARY=/usr/bin/buildah
export IMGTYPE_BINARY=/usr/bin/buildah-imgtype
###############################################################################
# BEGIN setup/teardown
# Start a registry
pre_bats_setup() {
REGISTRY_FQIN=docker.io/library/registry:2.6
AUTHDIR=/tmp/buildah-tests-auth.$$
mkdir -p $AUTHDIR
CERT=$AUTHDIR/domain.crt
if [ ! -e $CERT ]; then
openssl req -newkey rsa:4096 -nodes -sha256 \
-keyout $AUTHDIR/domain.key -x509 -days 2 \
-out $AUTHDIR/domain.crt \
-subj "/C=US/ST=Foo/L=Bar/O=Red Hat, Inc./CN=localhost"
fi
if [ ! -e $AUTHDIR/htpasswd ]; then
podman run --rm --entrypoint htpasswd $REGISTRY_FQIN \
-Bbn testuser testpassword > $AUTHDIR/htpasswd
fi
podman rm -f registry || true
podman run -d -p 5000:5000 \
--name registry \
-v $AUTHDIR:/auth:Z \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/auth/domain.key \
$REGISTRY_FQIN
}
post_bats_teardown() {
podman rm -f registry
}
# END setup/teardown
###############################################################################
# BEGIN actual test
pre_bats_setup
bats /usr/share/buildah/test/system
rc=$?
post_bats_teardown
exit $rc