github.com/cvmfs/docker-graphdriver@v0.0.0-20181206110523-155ec6df0521/tests/common.sh (about) 1 #!/bin/bash 2 3 function prepare_plugin 4 { 5 plugin_bin=$1 6 rootfs_tar=$2 7 8 # create workdir 9 mkdir plugin_workdir 10 pushd plugin_workdir 11 12 # create config.json 13 cp /data/config.json . 14 sed -i "s/__binary__/$PLUGIN_NAME/" config.json 15 16 # create unpack rootfs 17 mkdir rootfs 18 sudo tar xjf "$ROOTFS_TAR" -C rootfs 19 20 # copy binary 21 sudo cp -v "$PLUGIN_BIN" rootfs/usr/local/bin 22 popd 23 } 24 25 function install_plugin 26 { 27 mkdir graph 28 sudo dockerd --log-level=fatal -s aufs -g graph & #&>/dev/null & 29 30 while [ "$(pidof dockerd)" == "" ] 31 do 32 sleep 1 33 echo "." 34 done 35 36 # create & enable plugin 37 sudo docker plugin create "atlantic777/$PLUGIN_NAME" plugin_workdir 38 docker plugin enable "atlantic777/$PLUGIN_NAME" 39 40 sudo rm -rf plugin_workdir 41 42 # stop daemon 43 sudo pkill dockerd 44 45 while [ "$(pidof dockerd)" != "" ] 46 do 47 sleep 1 48 echo "." 49 done 50 } 51 52 function wait_process 53 { 54 process=$1 55 target_status=$2 56 57 if [ "$target_status" == "up" ]; then 58 while [ "$(pidof $process)" == "" ] 59 do 60 sleep 1 61 echo "." 62 done 63 docker info &>/dev/null 64 elif [ "$target_status" == "down" ]; then 65 while [ "$(pidof $process)" != "" ] 66 do 67 sleep 1 68 echo "." 69 done 70 fi 71 } 72 73 function start_docker 74 { 75 graph_driver=$1 76 77 if [ "$graph_driver" == "" ]; then 78 graph_driver="aufs" 79 fi 80 81 if [ ! -e graph ]; then 82 mkdir -p graph 83 fi 84 85 sudo dockerd --experimental -D -s $graph_driver -g graph & # &>/dev/null & 86 wait_process dockerd up 87 } 88 89 function stop_docker 90 { 91 sudo pkill dockerd 92 wait_process dockerd down 93 } 94 95 function hello_world_test 96 { 97 PLUGIN_BIN=$1 98 ROOTFS_TAR=$2 99 100 prepare_plugin $PLUGIN_BIN $ROOTFS_TAR 101 start_docker aufs 102 103 # create & enable plugin 104 sudo docker plugin create "atlantic777/$PLUGIN_NAME" plugin_workdir 105 docker plugin enable "atlantic777/$PLUGIN_NAME" 106 107 # switch to new graphdriver 108 stop_docker 109 start_docker "atlantic777/$PLUGIN_NAME" 110 111 # run the echo test 112 docker run ubuntu:16.04 echo "Hello world!" 113 status=$? 114 115 # cleanup 116 stop_docker 117 sudo rm -rf plugin_workdir 118 sudo rm -rf graph 119 120 return $status 121 } 122 123 export -f prepare_plugin 124 export -f install_plugin 125 export -f start_docker 126 export -f stop_docker 127 export -f wait_process 128 export -f hello_world_test