#!/bin/sh

lib=$(cd "$(dirname "$0")" && pwd)/../lib/charliecloud
. "${lib}/base.sh"

set -e

# shellcheck disable=SC2034
usage=$( cat << EOF

Pull image from a Docker Hub and flatten into tarball.

Usage:

  $ $(basename "$0") IMAGE DEST

You must have sufficient privilege (via sudo) to run Docker commands.
EOF
)

parse_basic_args "$@"

if [ "$#" -ne 2 ]; then
    usage
fi

image=$1
dest=$2

docker_ pull "$image"
"${ch_bin}/ch-builder2tar" "$image" "$dest"
