-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
executable file
·169 lines (139 loc) · 4.37 KB
/
entrypoint.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/sh
defaults() {
: ${DEVPI_SERVERDIR="/data/server"}
: ${DEVPI_CLIENTDIR="/data/client"}
: ${DEVPI_HOST="0.0.0.0"}
: ${DEVPI_PORT=3141}
export DEVPI_SERVERDIR \
DEVPI_CLIENTDIR \
DEVPI_HOST \
DEVPI_PORT
}
CLIENT_INSTALLED="false"
KEEP_CLIENT="false"
print(){
echo "$@" >&2
}
usage(){
cat <<EOF
Container Usage:
docker run -it --rm \\
-v "\$PWD/data":/data \\ # for persistance on the host
-e DEVPI_PASSWORD=password \\ # set password for devpi root user
-e DEVPI_PORT=3143 \\ # use custom port (default 3141)
-p "80:3143" \\ # host_port:container_port
mhoush/devpi-server [options...] [args...]
Options:
-w | --web: Enable devpi-web interface
-c | --client: Enable devpi-client
-h | --help: Show this page and devpi-server help page
Args:
Get passed to devpi-server command.
Environment Variable Settings:
DEVPI_PASSWORD: Password for the root devpi user (default '')
DEVPI_PORT: Port the server listens on. (default 3141)
DEVPI_SERVERDIR: Directory to store server information to. (default /data)
DEVPI_CLIENTDIR: Directory to store client information to. (default /data)
Devpi-Server Usage:
EOF
}
initialize() {
if [[ "$CLIENT_INSTALLED" == "false" ]]; then
print ""
print "=> Installing devpi-client to initialize server"
pip install -q --no-cache-dir --ignore-installed --upgrade \
devpi-client
fi
print ""
print "=> Initializing devpi-server"
devpi-server --restrict-modify root --start --host "$DEVPI_HOST" --port "$DEVPI_PORT"
devpi-server --status
devpi use "http://$DEVPI_HOST:$DEVPI_PORT"
devpi login root --password=''
devpi user -m root password="${DEVPI_PASSWORD}"
devpi index -y -c public pypi_whitelist='*'
devpi logoff
devpi-server --stop
devpi-server --status
if [[ "$KEEP_CLIENT" == "false" ]]; then
print ""
print "=> We are done with devpi-client when prompted hit [y] to uninstall"
print -n "Uninstall devpi-client (Y/n)?"
read -t 3 answer
case $answer in
n* | N* )
;;
* )
echo y | pip uninstall -q devpi-client;
echo ""
;;
esac
fi
}
start_devpi_server() {
if ! [[ -f "$DEVPI_SERVERDIR/.serverversion" ]]; then
initialize
fi
print ""
print "=> Starting server..."
if [[ "$@" != "" ]]; then
exec devpi-server --restrict-modify root --host "$DEVPI_HOST" --port "$DEVPI_PORT" "$@"
else
exec devpi-server --restrict-modify root --host "$DEVPI_HOST" --port "$DEVPI_PORT"
fi
}
install_web_components() {
# Requires additional packages
apk add --update --no-cache --no-cache python3-dev libffi-dev musl-dev make gcc
rm -rf /var/cache/apk/*
# Pip install dev packages
pip install --no-cache-dir --upgrade devpi-web
}
main() {
# set-up defaults
defaults
if [[ "$1" == "" ]]; then
# start a server without any args/commands
start_devpi_server
elif [[ "$1" == "sh" ]]; then
print "=> Running non-devpi commands: $@"
exec "$@"
else
if [[ "$1" == "devpi" ]]; then
shift
fi
args=""
while [[ "$1" != "" ]]; do
case $1 in
-w | --web )
print ""
print "=> Installing devpi-web..."
install_web_components
;;
-c | --client )
print ""
print "=> Installing devpi-client..."
pip install --no-cache-dir --upgrade devpi-client
CLIENT_INSTALLED="true"
KEEP_CLIENT="true"
;;
-h | --help )
print ""
print "$(usage)"
print ""
exec devpi-server --help
;;
*)
if [[ "$args" != "" ]]; then
args="$1 $args"
else
args="$1"
fi
;;
esac
shift
done
start_devpi_server "$args"
fi
}
main "$@"