bootstrap: library
from: alpine:3.11.5

%labels
    maintainer "Sylabs Team <support@sylabs.io>"

%help
    export BAD_GUY=Thanos
    export SMART_GUY=tony

%environment
    GOPATH=/go
    PATH=$PATH:$GOPATH/bin:/usr/local/go/bin
    CGO_ENABLED=0
    AVENGERS=asemble
    export GOPATH PATH CGO_ENABLED AVENGERS

%setup
    echo "SETUP"
    # to test extraction to a sandbox for non root users
    mknod $SINGULARITY_ROOTFS/dev/null c 1 3

%appenv testapp
    TESTAPP=testapp
    export TESTAPP

%appinstall testapp
    echo 'echo $TESTAPP' > $SCIF_APPROOT/bin/testapp.sh
    chmod 0755 $SCIF_APPROOT/bin/testapp.sh

%apprun testapp
    $TESTAPP.sh

%appinstall foo

    echo "INSTALLING FOO"
    touch filefoo.exec

%appinstall bar

    echo "INSTALLING BAR"
    touch filebar.exec

%apphelp foo
This is the help for foo!

%applabels foo
HELLOTHISIS foo

%applabels bar
HELLOTHISIS bar

%appenv foo
HELLOTHISIS=foo
export HELLOTHISIS

%apprun foo
    echo "RUNNING FOO"

%startscript
    exec nc -l -k -p $1 -e /bin/cat

%runscript
    echo "Running command: $*"
    exec "$@"

%post
    echo "POST"
    # Needed for startscript
    apk update
    apk add nmap-ncat

    # for symlink tests, ensure runtime will bind
    # in the image and not on /etc on host filesystem
    ln -s /etc /var/etc
    mkdir /madness
    ln -s /madness /var/etc/madness

    # for underlay regression tests
    ln -s ../usr/share/zoneinfo/Etc/UTC /etc/relative-slink
    ln -s /usr/share/zoneinfo/Etc/UTC /etc/absolute-slink

%test
    exec "$@"
