|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (C) 2016 Gauvain Pocentek <gauvain@pocentek.net> |
| 3 | +# |
| 4 | +# This program is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU Lesser General Public License as published by |
| 6 | +# the Free Software Foundation, either version 3 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU Lesser General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU Lesser General Public License |
| 15 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +PY_VER=2 |
| 18 | +while getopts :p: opt "$@"; do |
| 19 | + case $opt in |
| 20 | + p) |
| 21 | + PY_VER=$OPTARG;; |
| 22 | + *) |
| 23 | + echo "Unknown option: $opt" |
| 24 | + exit 1;; |
| 25 | + esac |
| 26 | +done |
| 27 | + |
| 28 | +case $PY_VER in |
| 29 | + 2) VENV_CMD=virtualenv;; |
| 30 | + 3) VENV_CMD=pyvenv;; |
| 31 | + *) |
| 32 | + echo "Wrong python version (2 or 3)" |
| 33 | + exit 1;; |
| 34 | +esac |
| 35 | + |
| 36 | +docker run --name gitlab-test --detach --publish 8080:80 --publish 2222:22 genezys/gitlab:latest >/dev/null 2>&1 |
| 37 | + |
| 38 | +LOGIN='root' |
| 39 | +PASSWORD='5iveL!fe' |
| 40 | +CONFIG=/tmp/python-gitlab.cfg |
| 41 | +GREEN='\033[0;32m' |
| 42 | +NC='\033[0m' |
| 43 | +OK="echo -e ${GREEN}OK${NC}" |
| 44 | + |
| 45 | +echo -n "Waiting for gitlab to come online... " |
| 46 | +I=0 |
| 47 | +while :; do |
| 48 | + sleep 5 |
| 49 | + curl -s http://localhost:8080/users/sign_in 2>/dev/null | grep -q "GitLab Community Edition" && break |
| 50 | + let I=I+5 |
| 51 | + [ $I -eq 120 ] && exit 1 |
| 52 | +done |
| 53 | +sleep 5 |
| 54 | +$OK |
| 55 | + |
| 56 | +# Get the token |
| 57 | +TOKEN=$(curl -s http://localhost:8080/api/v3/session \ |
| 58 | + -X POST \ |
| 59 | + --data "login=$LOGIN&password=$PASSWORD" \ |
| 60 | + | python -c 'import sys, json; print(json.load(sys.stdin)["private_token"])') |
| 61 | + |
| 62 | +cat > $CONFIG << EOF |
| 63 | +[global] |
| 64 | +default = local |
| 65 | +timeout = 2 |
| 66 | +
|
| 67 | +[local] |
| 68 | +url = http://localhost:8080 |
| 69 | +private_token = $TOKEN |
| 70 | +EOF |
| 71 | + |
| 72 | +echo "Config file content ($CONFIG):" |
| 73 | +cat $CONFIG |
0 commit comments