github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/go/run/scripts/build_docker.sh (about)

     1  #!/bin/bash
     2  
     3  set -o nounset
     4  set -o errexit
     5  
     6  # This script assumes that the code for running the demo server and demo client
     7  # has already been built in standalone mode using build_standalone.
     8  if [ "$#" -ge 1 ]; then
     9  	export TAO_DOMAIN="$1"
    10  elif [ "$TAO_DOMAIN" == "" ]; then
    11  	echo "Must supply the path to an initialized domain, or set \$TAO_DOMAIN."
    12  	exit 1
    13  fi
    14  
    15  # arguments: build_docker <script path> <local relative app path> <policy cert # path> <tao.config path>
    16  # e.g., build_docker $0 demo_server $1 $2
    17  function build_docker() {
    18  	# This script currently only supports Linux (or any system that has a working
    19  	# readlink -e)
    20  
    21  	script_name="$1"
    22  	app_name="$2"
    23  	policy_cert="$3"
    24  	tao_config="$4"
    25  
    26  	DEMO_DIR="$(readlink -e "$(dirname "$script_name")")"/../../apps/demo
    27  	TEMP_DIR=$(mktemp -d)
    28  	cp "${DEMO_DIR}"/${app_name}/Dockerfile ${TEMP_DIR}/Dockerfile
    29  	mkdir ${TEMP_DIR}/tmp
    30  	mkdir ${TEMP_DIR}/bin
    31  	WHICH=$(which which)
    32  	APP_BIN="$(PATH="${GOPATH//://bin:}/bin" $WHICH ${app_name})"
    33  	if ldd "$APP_BIN" >/dev/null 2>&1; then
    34  		echo "Found dynamic executable: $APP_BIN"
    35  		echo "Docker requires static executables."
    36  		echo "See build_static.sh for static build instructions."
    37  		exit 1
    38  	fi
    39  	cp "$APP_BIN" ${TEMP_DIR}/bin/${app_name}
    40  	mkdir ${TEMP_DIR}/policy_keys
    41  	cp $policy_cert ${TEMP_DIR}/policy_keys/cert
    42  	cp $tao_config ${TEMP_DIR}/tao.config
    43  
    44  	tar -C ${TEMP_DIR} -czf "$APP_BIN".img.tgz $(ls ${TEMP_DIR})
    45  	rm -rf ${TEMP_DIR}
    46  }
    47  
    48  build_docker "$0" demo_server "$TAO_DOMAIN/policy_keys/cert" "$TAO_DOMAIN/tao.config"
    49  build_docker "$0" demo_client "$TAO_DOMAIN/policy_keys/cert" "$TAO_DOMAIN/tao.config"