github.com/hpcng/singularity@v3.1.1+incompatible/docs/2.x-tests/39-deffile.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2015-2016, Gregory M. Kurtzer. All rights reserved.
     4  #
     5  # "Singularity" Copyright (c) 2016, The Regents of the University of California,
     6  # through Lawrence Berkeley National Laboratory (subject to receipt of any
     7  # required approvals from the U.S. Dept. of Energy).  All rights reserved.
     8  #
     9  # This software is licensed under a customized 3-clause BSD license.  Please
    10  # consult LICENSE file distributed with the sources of this project regarding
    11  # your rights to use or distribute this software.
    12  #
    13  # NOTICE.  This Software was developed under funding from the U.S. Department of
    14  # Energy and the U.S. Government consequently retains certain rights. As such,
    15  # the U.S. Government has been granted for itself and others acting on its
    16  # behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software
    17  # to reproduce, distribute copies to the public, prepare derivative works, and
    18  # perform publicly and display publicly, and to permit other to do so.
    19  #
    20  #
    21  
    22  
    23  
    24  . ./functions
    25  
    26  test_init "Testing custom deffile options"
    27  
    28  
    29  
    30  CONTAINER="$SINGULARITY_TESTDIR/container.img"
    31  DEFFILE="$SINGULARITY_TESTDIR/container.def"
    32  
    33  
    34  cat <<EOF > "$DEFFILE"
    35  Bootstrap: docker
    36  From: busybox
    37  
    38  %runscript
    39  true
    40  EOF
    41  
    42  
    43  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
    44  stest 0 singularity exec "$CONTAINER" true
    45  stest 0 singularity run "$CONTAINER"
    46  
    47  
    48  cat <<EOF > "$DEFFILE"
    49  Bootstrap: docker
    50  From: busybox
    51  
    52  %runscript
    53  false
    54  EOF
    55  
    56  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
    57  stest 0 singularity exec "$CONTAINER" true
    58  stest 1 singularity run "$CONTAINER"
    59  
    60  
    61  cat <<EOF > "$DEFFILE"
    62  Bootstrap: docker
    63  From: busybox
    64  
    65  %files
    66  
    67   # Spaces and comments
    68  $DEFFILE /deffile
    69  
    70  ../Makefile /makefile
    71  
    72  %post
    73  touch /testfile
    74  EOF
    75  
    76  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
    77  stest 0 singularity exec "$CONTAINER" true
    78  stest 0 singularity exec "$CONTAINER" test -f /deffile
    79  stest 0 singularity exec "$CONTAINER" test -f /testfile
    80  stest 0 singularity exec "$CONTAINER" test -f /makefile
    81  
    82  
    83  cat <<EOF > "$DEFFILE"
    84  Bootstrap: docker
    85  From: busybox
    86  
    87  %environment
    88  echo "hi from environment"
    89  EOF
    90  
    91  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
    92  stest 0 singularity exec "$CONTAINER" true
    93  stest 1 singularity exec "$CONTAINER" false
    94  stest 0 sh -c "echo true | singularity shell "$CONTAINER" | grep 'hi from environment'"
    95  stest 0 sh -c "singularity exec "$CONTAINER" true | grep 'hi from environment'"
    96  
    97  
    98  # Test for #1103: Duplicate bootstrap definition key found: '#UpdateURL'
    99  cat <<EOF > "$DEFFILE"
   100  Bootstrap: docker
   101  From: busybox#comment that needs to be ignored
   102  
   103  #DuplicateKey: commented value
   104  #DuplicateKey: other commented value
   105  # also include exact example found in #1103
   106  #UpdateURL: http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/updates/\$basearch/
   107  #UpdateURL: http://mirror.centos.org/centos-7/7.4.1708/updates/x86_64/
   108  EOF
   109  
   110  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
   111  stest 0 singularity exec "$CONTAINER" true
   112  stest 1 singularity exec "$CONTAINER" false
   113  
   114  # Test multiple empty lines
   115  cat <<EOF > "$DEFFILE"
   116  Bootstrap: docker
   117  From: busybox
   118  
   119  
   120  # this is a comment
   121  EOF
   122  
   123  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
   124  stest 0 singularity exec "$CONTAINER" true
   125  stest 1 singularity exec "$CONTAINER" false
   126  
   127  # Test comments inside runscript
   128  cat <<EOF > "$DEFFILE"
   129  Bootstrap: docker
   130  From: busybox
   131  
   132  %runscript
   133  #this is a comment
   134  EOF
   135  # expected output of test below
   136  cat <<EOF >"$SINGULARITY_TESTDIR/expected.txt"
   137  #!/bin/sh 
   138  
   139  #this is a comment
   140  EOF
   141  
   142  stest 0 sudo singularity build -F "$CONTAINER" "$DEFFILE"
   143  stest 0 singularity exec "$CONTAINER" cat /.singularity.d/runscript
   144  # save output of last test, need it to compare with expected
   145  cp "$SINGULARITY_TESTDIR/output" "$SINGULARITY_TESTDIR/actual.txt"
   146  stest 0 cmp "$SINGULARITY_TESTDIR/actual.txt" "$SINGULARITY_TESTDIR/expected.txt"
   147  
   148  
   149  test_cleanup