-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-do
executable file
·70 lines (64 loc) · 2.24 KB
/
docker-do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# -*- coding: UTF-8 -*-
## Helper script for docker based build machines. The $HOME/workspace is mounted on docker machine under the same path
## (that must have been created first when building the docker image) and the CURRENT directory becomes the WORKING
## directory inside docker.
## usage: docker-do.sh [options]
## options:
## -i, --image <name> The docker image to use
## -b, --build Build and create a debian package (currently same as --command=make)
## -p, --package Create a debian package
## -c, --command <command> Command to execute in docker env
## -s, --src <path> Host volume to be mounted onto docker image [default: `pwd`]
## -d, --dst <path> Docker image mount point [default: `pwd`]
# GENERATED_CODE: start
# Default values
_src=`pwd`
_dst=`pwd`
# No-arguments is not allowed
[ $# -eq 0 ] && sed -ne 's/^## \(.*\)/\1/p' $0 && exit 1
# Converting long-options into short ones
for arg in "$@"; do
shift
case "$arg" in
"--image") set -- "$@" "-i";;
"--build") set -- "$@" "-b";;
"--package") set -- "$@" "-p";;
"--command") set -- "$@" "-c";;
"--src") set -- "$@" "-s";;
"--dst") set -- "$@" "-d";;
*) set -- "$@" "$arg"
esac
done
function print_illegal() {
echo Unexpected flag in command line \"$@\"
}
# Parsing flags and arguments
while getopts 'hbpi:c:s:d:' OPT; do
case $OPT in
h) sed -ne 's/^## \(.*\)/\1/p' $0
exit 1 ;;
b) _build=1 ;;
p) _package=1 ;;
i) _image=$OPTARG ;;
c) _command=$OPTARG ;;
s) _src=$OPTARG ;;
d) _dst=$OPTARG ;;
\?) print_illegal $@ >&2;
echo "---"
sed -ne 's/^## \(.*\)/\1/p' $0
exit 1
;;
esac
done
# GENERATED_CODE: end
if [ -z "$_image" ]; then
cur=`pwd`
_docker=`basename $cur`
echo Looking for [$_docker] as docker image
# TODO check whether the docker image actually exists before going forward
fi
DOCKER_RUN="docker run --rm -v $_src:$_dst -w $_dst -it $_image"
[ ! -z $_command ] && set -x && exec $DOCKER_RUN $_command
[ ! -z $_build ] && set -x && exec $DOCKER_RUN make
[ ! -z $_package ] && set -x && exec $DOCKER_RUN fpm -s dir -t deb -n $_docker ./