-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-prod
executable file
·132 lines (119 loc) · 2.94 KB
/
docker-prod
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
check_argument () {
if [ -z $2 ]; then
echo "No value specified for argument $1"
exit
fi
}
help () {
echo "usage: $0 -q -p -o output.txt <some command>"
echo "Arguments:"
echo " -q|--quiet Quiet, reduce logs"
echo " -p|--pull Pull last version"
echo " -o|--output <output> Outputs the stdout of the command to <output>"
echo " -h|--help Print this message"
echo
echo "Positional arguments:"
echo " <some command> Command to be executed in the image"
exit
}
parse_arguments () {
POSITIONAL=()
PULL=0
QUIET=0
HELP=0
TAG=master
while [[ $# -gt 0 ]]
do
key="$1"
if [ -z $POSITIONAL ]; then
case $key in
-q|--quiet)
QUIET=1
shift # past argument
;;
-p|--pull)
PULL=1
shift # past argument
;;
-t|--tag)
check_argument $@
TAG=$2
shift # past argument
;;
-h|--help)
HELP=1
shift # past argument
;;
-o|--output)
check_argument $@
OUTPUT=$2
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
else
# After the first positional argument, all are positional
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
fi
done
set -- "${POSITIONAL[@]}" # restore positional parameters
}
print_message () {
if [ $QUIET = 0 ]; then
echo $@
fi
}
authenticate () {
print_message "----- Authentication -----"
docker login registry.gitlab.com
if [ $? != 0 ]; then
echo "Cannot authenticate"
exit
fi
print_message "----------"
print_message
}
pull () {
print_message "----- Pull last version -----"
echo $TAG
docker pull registry.gitlab.com/i3-market/code/wp3/t3.1-self-sovereign-identity-and-access-management/node-oidc-provider
docker tag registry.gitlab.com/i3-market/code/wp3/t3.1-self-sovereign-identity-and-access-management/node-oidc-provider i3market/oidc-provider-app
print_message "----------"
print_message
}
execute () {
print_message "----- Execute -----"
COMMAND=$@
if [ -z $1 ]; then
print_message "Using default command (bash)"
print_message "You can use the command 'template [env/docker-compose]' to get deployment information"
print_message "You may also want to init the default volumes using 'init-volumes UID:GID'"
COMMAND="bash"
else
print_message "Execute command: $COMMAND"
fi
FULL_COMMAND="docker run --rm --name oidc-provider-installer -v $(pwd)/volumes:/volumes -it i3market/oidc-provider-app $COMMAND"
if [ -z $OUTPUT ]; then
$FULL_COMMAND
else
$FULL_COMMAND 1> $OUTPUT
fi
}
main () {
parse_arguments $@
if [ $HELP = 1 ]; then
help
fi
if [ $PULL = 1 ]; then
authenticate
pull
fi
execute ${POSITIONAL[@]}
}
main $@