Skip to content

Instantly share code, notes, and snippets.

@islander
Created August 2, 2019 05:27
Show Gist options
  • Save islander/1b60d9af570739adff462391acf8f030 to your computer and use it in GitHub Desktop.
Save islander/1b60d9af570739adff462391acf8f030 to your computer and use it in GitHub Desktop.
Docker wrapper script to deploy CLI applications
#!/bin/sh
# docker-wrapper script.
# A wrapper script for invoking cli tools with docker.
#
# For example we'll use it for Bash Automated Testing System.
# Put this script in $PATH as `bats`.
PROGNAME="$(basename $0)"
IMAGE="bats/bats"
VERSION="latest"
WORKDIR="/app"
# Helper functions for guards
error(){
error_code=$1
echo "ERROR: $2" >&2
echo "($PROGNAME wrapper version: $VERSION, error code: $error_code )" &>2
exit $1
}
check_cmd_in_path(){
cmd=$1
which $cmd > /dev/null 2>&1 || error 1 "$cmd not found!"
}
# Guards (checks for dependencies)
check_cmd_in_path docker
# Set up mounted volumes, environment, and run our containerized command
exec docker run \
--interactive --tty --rm \
--volume "$(pwd)":"${WORKDIR}" \
--workdir "${WORKDIR}" \
"${IMAGE}:${VERSION}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment