-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a docker wrapper and explanations
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/sh | ||
|
||
# A wrapper script for invoking a docker container | ||
# Based on https://spin.atomicobject.com/2015/11/30/command-line-tools-docker/ | ||
|
||
DOCKER_IMAGE="thibdct/amazon2csv" | ||
|
||
error(){ | ||
error_code=$1 | ||
echo "ERROR: $2" >&2 | ||
exit $1 | ||
} | ||
check_cmd_in_path(){ | ||
cmd=$1 | ||
which $cmd > /dev/null 2>&1 || error 1 "$cmd not found!" | ||
} | ||
upgrade(){ | ||
docker pull $DOCKER_IMAGE | ||
exit 1 | ||
} | ||
uninstall(){ | ||
read -p "Are you sure to uninstall (y/n)? " -n 1 -r | ||
echo | ||
if [[ $REPLY =~ ^[Yy]$ ]] | ||
then | ||
echo "docker rmi $DOCKER_IMAGE" | ||
echo "rm $0" | ||
fi | ||
exit 1 | ||
} | ||
|
||
# Checks for dependencies | ||
check_cmd_in_path docker | ||
check_cmd_in_path docker-machine | ||
docker-machine active > /dev/null 2>&1 || error 2 "docker-machine needs to be running." | ||
|
||
case $1 in | ||
--uninstall) | ||
uninstall | ||
;; | ||
--upgrade) | ||
upgrade | ||
;; | ||
esac | ||
|
||
# Run our containerized command | ||
exec docker run -it --rm $DOCKER_IMAGE "$@" |