Skip to content

Commit b2e1a8f

Browse files
authored
Merge pull request #15 from jpbochi/all-the-opts
adds lots of extra options
2 parents 4ba7919 + ae3123c commit b2e1a8f

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ If not, clone this repo and do `./install`.
1414

1515
```
1616
alias dr-node='drun -N -P'
17-
alias dr-compose='drun -e HOME="$HOME" -I dduportal/docker-compose'
17+
alias dr-compose='drun -e HOME="$HOME" -I docker/compose:1.9.0'
18+
alias dr-py='drun -I python:2.7'
1819
```
1920

2021
## Examples

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ test:
1919
- ./drun -xNM slim node --version | grep 'v7.7.1' # should read version from package.json node:7.7.1-slim image
2020
- echo '{"test":"passing"}' | ./drun -x stedolan/jq '.test' | grep '"passing"' # should pipe into command inside container
2121
- echo '{"test":"passing"}' > test.json && ./drun -x stedolan/jq '.test' test.json | grep '"passing"' # should mount current directory
22+
- ./drun -?

drun

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@ set -o errexit
33
set -o nounset
44
set -o noglob
55

6-
usage_noexit() {
7-
echo >&2 'Usage: drun [-hkx] [-N [-A] [-P] [-M (alpine|wheezy|slim)]] [-E ENV_REGEX] [-e ENV_SPEC]* [-v VOL_SPEC]* [(-I image)|(image)] [command]'
8-
echo >&2 ' -h Help'
9-
echo >&2 ' -k Keep container after run (i.e. does not user docker run --rm option)'
10-
echo >&2 ' -x Enables bash xtrace so that exact `docker run` command is displayed'
11-
echo >&2 ' -N Uses node:AUTO image, where AUTO is detected from a local package.json if any (also mounts .npmrc, if present)'
12-
echo >&2 ' -M ALT_IMAGE Prefers node ALT_IMAGE (can be either alpine, wheezy or slim) (e.g., with -NM slim, will resolve to node:AUTO-slim)'
13-
echo >&2 ' -A Prefers mhart/alpine-node-auto images (e.g., with -NA, will resolve to mhart/alpine-node-auto:AUTO)'
14-
echo >&2 ' -P Mounts your ~/.npm/ into the container (Only useful with node, obviously)'
15-
echo >&2 ' -v VOL_SPEC Adds a --volume option to `docker run`'
16-
echo >&2 ' -e ENV_SPEC Adds a --env option to `docker run`'
17-
echo >&2 ' -E ENV_REGEX Forwards local env variables whose names match ENV_REGEX to container'
18-
echo >&2 ' -I image Tells which docker image to use'
19-
echo >&2 ' -D Do not mount /var/run/docker.sock into the container'
6+
short_usage() {
7+
echo >&2 'Usage: drun [options] (image|-I image) [--] [command]'
8+
echo >&2 'See `drun -?` for help.'
9+
exit 1
2010
}
2111
usage() {
22-
usage_noexit
23-
exit 1
12+
echo >&2 'Usage: drun [options] (image|-I image) [--] [command]'
13+
echo >&2 ' -? Shows this help'
14+
echo >&2 ' -K Keep container after run (i.e. does not user docker run --rm option)'
15+
echo >&2 ' -x Enables bash xtrace so that exact `docker run` command is displayed'
16+
echo >&2 ' -N Uses node:AUTO image, where AUTO is detected from a local package.json if any (also mounts .npmrc, if present)'
17+
echo >&2 ' -M ALT_IMAGE Prefers node ALT_IMAGE (can be either alpine, wheezy or slim) (e.g., with -NM slim, will resolve to node:AUTO-slim)'
18+
echo >&2 ' -A Prefers mhart/alpine-node-auto images (e.g., with -NA, will resolve to mhart/alpine-node-auto:AUTO)'
19+
echo >&2 ' -P Mounts your ~/.npm/ into the container (Only useful with node, obviously)'
20+
echo >&2 ' -E ENV_REGEX Forwards local env variables whose names match ENV_REGEX to container'
21+
echo >&2 ' -I image Tells which docker image to use, allowing other options to set later'
22+
echo >&2 ' -D Do not mount /var/run/docker.sock into the container'
23+
echo >&2 ' -X SOME_DOCKER_OPTION Passes option directly to docker (e.g. `drun -X --dns=8.8.8.8` results in `docker run --dns=8.8.8.8 ...`)'
24+
echo >&2 ' -a|c|e|h|l|m|p|u|v|w VAL Work exactly like `docker run` options (e.g. `drun -e FOO=bar` results in `docker run -e FOO=bar ...`)'
25+
exit 0
2426
}
2527

2628
node_version_jq() {
@@ -45,17 +47,17 @@ node_version() {
4547

4648
CURRENT_DIR=$(pwd)
4749
CONTAINER_HOME=$CURRENT_DIR
48-
while getopts ':e:E:hI:kNM:APv:xD' OPT; do
50+
while getopts ':a:c:e:h:l:m:p:u:v:w:X:E:I:KNM:APxD' OPT; do
4951
case $OPT in
52+
a|c|e|h|l|m|p|u|v|w)
53+
EXTRA_OPTS="${EXTRA_OPTS:-} -${OPT} ${OPTARG}";;
54+
X)
55+
EXTRA_OPTS="${EXTRA_OPTS:-} ${OPTARG}";;
5056
E)
5157
ENV_REGEX="$OPTARG";;
52-
e)
53-
EXTRA_OPTS="${EXTRA_OPTS:-} -e $OPTARG";;
54-
h)
55-
usage_noexit && exit;;
5658
I)
5759
IMAGE="$OPTARG";;
58-
k)
60+
K)
5961
RM_OPT="";;
6062
N)
6163
IMAGE="node:$(node_version)"
@@ -71,18 +73,19 @@ while getopts ':e:E:hI:kNM:APv:xD' OPT; do
7173
EXTRA_OPTS="${EXTRA_OPTS:-} -v $CONTAINER_HOME/.npm/_git-remotes"
7274
EXTRA_OPTS="${EXTRA_OPTS:-} -v $HOME/.npm:$CONTAINER_HOME/.npm"
7375
;;
74-
v)
75-
EXTRA_OPTS="${EXTRA_OPTS:-} -v $OPTARG";;
7676
x)
7777
XTRACE="y";;
7878
D)
7979
MOUNTDOCKERSOCK="n";;
8080
\?)
81+
if [ "$OPTARG" = '?' ]; then
82+
usage
83+
fi
8184
echo >&2 "Unknown option -$OPTARG"
82-
usage;;
85+
short_usage;;
8386
:)
8487
echo >&2 "Missing argument for option -$OPTARG"
85-
usage;;
88+
short_usage;;
8689
esac
8790
done
8891
shift $((OPTIND-1))

0 commit comments

Comments
 (0)