-
Notifications
You must be signed in to change notification settings - Fork 643
/
build_test_env.sh
executable file
·111 lines (96 loc) · 2.67 KB
/
build_test_env.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
#!/bin/bash
# Copyright (C) 2016 Gauvain Pocentek <gauvain@pocentek.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
pecho() { printf %s\\n "$*"; }
log() {
[ "$#" -eq 0 ] || { pecho "$@"; return 0; }
while IFS= read -r log_line || [ -n "${log_line}" ]; do
log "${log_line}"
done
}
error() { log "ERROR: $@" >&2; }
fatal() { error "$@"; exit 1; }
try() { "$@" || fatal "'$@' failed"; }
PY_VER=2
while getopts :p: opt "$@"; do
case $opt in
p) PY_VER=$OPTARG;;
*) fatal "Unknown option: $opt";;
esac
done
case $PY_VER in
2) VENV_CMD=virtualenv;;
3) VENV_CMD=pyvenv;;
*) fatal "Wrong python version (2 or 3)";;
esac
for req in \
curl \
docker \
"${VENV_CMD}" \
;
do
command -v "${req}" >/dev/null 2>&1 || fatal "${req} is required"
done
VENV=$(pwd)/.venv
cleanup() {
rm -f /tmp/python-gitlab.cfg
docker kill gitlab-test >/dev/null 2>&1
docker rm gitlab-test >/dev/null 2>&1
deactivate || true
rm -rf $VENV
}
[ -z "${BUILD_TEST_ENV_AUTO_CLEANUP+set}" ] || {
trap cleanup EXIT
}
docker run --name gitlab-test --detach --publish 8080:80 \
--publish 2222:22 gpocentek/test-python-gitlab:latest >/dev/null 2>&1
LOGIN='root'
PASSWORD='5iveL!fe'
CONFIG=/tmp/python-gitlab.cfg
GITLAB="gitlab --config-file $CONFIG"
GREEN='\033[0;32m'
NC='\033[0m'
OK="echo -e ${GREEN}OK${NC}"
log "Waiting for gitlab to come online... "
I=0
while :; do
sleep 5
curl -s http://localhost:8080/users/sign_in 2>/dev/null \
| grep -q "GitLab Community Edition" && break
let I=I+5
[ $I -eq 120 ] && exit 1
done
sleep 5
# Get the token
TOKEN=$(curl -s http://localhost:8080/api/v3/session \
-X POST \
--data "login=$LOGIN&password=$PASSWORD" \
| python -c \
'import sys, json; print(json.load(sys.stdin)["private_token"])')
cat > $CONFIG << EOF
[global]
default = local
timeout = 10
[local]
url = http://localhost:8080
private_token = $TOKEN
EOF
log "Config file content ($CONFIG):"
log <$CONFIG
$VENV_CMD $VENV
. $VENV/bin/activate
pip install -rrequirements.txt
pip install -e .
sleep 20