container-tools/tests/roles/run_bats_tests/files/helper.buildah-root.sh

37 lines
1.0 KiB
Bash

#!/bin/bash
#
# setup and teardown helpers for buildah test
#
function setup() {
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:2 \
-Bbn testuser testpassword > $AUTHDIR/htpasswd
fi
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:2
}
function teardown() {
podman rm -f registry
}