-
Notifications
You must be signed in to change notification settings - Fork 2
/
actions.sh
executable file
·114 lines (99 loc) · 2.72 KB
/
actions.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
# ------------------------------------------------------------------------------
# GENERAL FUNCTIONS
# ------------------------------------------------------------------------------
display_version() {
printf "dockerfiles version %s\n" "$1"
}
display_help() {
cat <<-EOF
usage:
[options] [command] [args]
commands:
./actions.sh build <image> build a docker image
./actions.sh compile <image> <tag> build, tag and push an image to DockerHub
./actions.sh pull <image> pull a new docker image from DockerHub
./actions.sh push <image> push a docker image to DockerHub
./actions.sh run <image> run a docker image
./actions.sh tag <image> <tag> add a tag to a docker image
options:
-V, --version Output current version of actions.sh
-h, --help Display this help information
EOF
}
# ------------------------------------------------------------------------------
# VALIDATION FUNCTIONS
# ------------------------------------------------------------------------------
validate() {
if [ $# != $1 ]; then
printf "ERROR: Incorrect usage\n"
display_help
exit 0
fi
}
# ------------------------------------------------------------------------------
# DOCKER FUNCTIONS
# ------------------------------------------------------------------------------
build() {
docker build -t $1 -f src/$2.Dockerfile .
}
pull() {
docker pull $1
}
push() {
docker push $1
}
run() {
docker run -it $1 /bin/bash
}
tag() {
docker tag $1 $2
}
controller() {
VERSION="1.0.0"
DOCKER_USER="suddi"
case "$1" in
-V|--version)
display_version $VERSION
;;
-h|--help)
display_help
;;
build)
validate 3 $@
docker_image=$DOCKER_USER/$2
build $docker_image $2
;;
compile)
validate 4 $@
docker_image=$DOCKER_USER/$2
build $docker_image $2
tag $docker_image $3
push $1
;;
pull)
validate 3 $@
docker_image=$DOCKER_USER/$2
pull $docker_image
;;
push)
validate 3 $@
docker_image=$DOCKER_USER/$2
push $docker_image
;;
run)
validate 3 $@
docker_image=$DOCKER_USER/$2
run $docker_image
;;
tag)
validate 4 $@
docker_image=$DOCKER_USER/$2
validate $3
tag $docker_image $3
;;
*)
validate 2 $@
esac
}
controller "$@"