github.com/jaypipes/ghw@v0.21.1/hack/run-against-snapshot.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-docker}
     4  SNAPSHOT_FILEPATH=${SNAPSHOT_FILEPATH:-$1}
     5  
     6  if [[ ! -f $SNAPSHOT_FILEPATH ]]; then
     7      echo "Cannot find snapshot file. Please call $0 with path to snapshot or set SNAPSHOT_FILEPATH envvar."
     8      exit 1
     9  fi
    10  
    11  root_dir=$(cd "$(dirname "$0")/.."; pwd)
    12  ghwc_image_name="ghwc"
    13  local_git_version=$(git describe --tags --always --dirty)
    14  IMAGE_VERSION=${IMAGE_VERSION:-$local_git_version}
    15  
    16  snap_tmp_dir=$(mktemp -d -t ghw-snap-test-XXX)
    17  # needed to enabled PRESERVE and EXCLUSIVE (see README.md)
    18  mkdir -p "$snap_tmp_dir/root"
    19  
    20  echo "copying snapshot $SNAPSHOT_FILEPATH to $snap_tmp_dir ..."
    21  cp -L $SNAPSHOT_FILEPATH $snap_tmp_dir
    22  
    23  echo "building Docker image with ghwc ..."
    24  
    25  ${CONTAINER_RUNTIME} build -f $root_dir/Dockerfile -t $ghwc_image_name:$IMAGE_VERSION $root_dir
    26  
    27  echo "running ghwc Docker image with volume mount to snapshot dir ..."
    28  
    29  # note the trailing ":z" on the "-v" option. We use :z on the host volume mount below to ensure
    30  # the container runtime has the ability to read the contents contained in the host volume.
    31  # podman is especially picky about this.
    32  ${CONTAINER_RUNTIME} run -it -v $snap_tmp_dir:/host:z \
    33  	-e GHW_SNAPSHOT_PATH="/host/$( basename $SNAPSHOT_FILEPATH )" \
    34  	-e GHW_SNAPSHOT_PRESERVE=1 \
    35  	-e GHW_SNAPSHOT_EXCLUSIVE=1 \
    36  	-e GHW_SNAPSHOT_ROOT="/host/root" \
    37  	$ghwc_image_name:$IMAGE_VERSION