bootstrap: docker
from: registry:2.7.1

%environment
    export REGISTRY_AUTH=token
    export REGISTRY_AUTH_TOKEN_REALM=http://localhost:5001/auth
    export REGISTRY_AUTH_TOKEN_SERVICE=Authentication
    export REGISTRY_AUTH_TOKEN_ISSUER=E2E
    export REGISTRY_AUTH_TOKEN_ROOTCERTBUNDLE=/certs/root.crt

%post
    apk add openssl
    apk add skopeo runc --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community

    mkdir /certs

    openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 \
      -keyout /certs/root.key -out /certs/root.pem -subj "/C=US/CN=localhost"
    openssl x509 -outform pem -in /certs/root.pem -out /certs/root.crt

    chmod 644 /certs/root.*

%startscript
    /.singularity.d/runscript &

    # wait until docker registry is up
    while ! wget -q -O /dev/null 127.0.0.1:5000 ; do sleep 0.5; done

    skopeo --insecure-policy copy --dest-tls-verify=false docker://busybox docker://localhost:5000/my-busybox

    # e2e PrepRegistry will repeatedly trying to connect to this port
    # giving indication that it can start
    nc -l -p 5111
