test.sh 1.88 KB
Newer Older
1
2
#!/bin/bash

3
4
5
export REGISTRY=eudat-docker-public.artie.ia.surfsara.nl
REGISTRY_USER=eudat-artie-readonly

Robert Verkerk's avatar
Robert Verkerk committed
6
_VERSION=centos7_4_2_8
7
CLEANUP="yes"
8
RUNTESTS="yes"
9
BUILD=0
10
GIT_BRANCH=""
Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
11
SECRET_DIR=""
12
13
14
15
16
17
18
19
20

while [[ $# -gt 0 ]]
do
    key="$1"
    case $key in
        "--nocleanup")
            CLEANUP="no"
            shift
            ;;
21
22
        "--notests")
            RUNTESTS="no"
23
24
            shift
            ;;
25

26
27
28
29
30
        "--branch")
            shift
            GIT_BRANCH=$1
            shift
            ;;
Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
31
        "--secret")
32
            shift
Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
33
            SECRET_DIR=$1
34
35
            shift
            ;;
36
        *)
37
            _VERSION=$1
38
39
40
41
42
43
44
45
            shift
            ;;
    esac
done

set -x
set -e

46
export VERSION=$_VERSION
47
48
source $(cd `dirname "${BASH_SOURCE[0]}"` && pwd)/version.sh
IMAGE_NAME_VERSION=`image_name  $VERSION`
49
50
51

cleanup () {
    exit_code=$?
52
53
54
55
56
57
58
59
60
61
62
63
    echo "shuting down"
    docker-compose -f ci/docker-compose.yml down -v
    exit $exit_code
}

is_logged_in() {
  cat ~/.docker/config.json | jq -r --arg url "${REGISTRY}" '.auths | has($url)'
}

if [[ "$(is_logged_in)" == "false" ]]; then
    docker login -u $REGISTRY_USER $REGISTRY;
fi
64

65
66
67
68
if [ "$CLEANUP" = "yes" ]
then
    trap cleanup EXIT ERR INT TERM
fi
69

70
if [ -z "$CI_COMMIT_TAG" ]
Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
71
then
72
73
74
75
76
77
    if [ -z "${GIT_BRANCH}" ]
    then
        GIT_BRANCH=${CI_COMMIT_REF_NAME}
    fi
else
    GIT_BRANCH=release
Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
78
fi
79

80
81
export DOCKER_IMAGE=${IMAGE_NAME_VERSION}
IMAGE_NAME=${REGISTRY}/${IMAGE_NAME_VERSION}
82

Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
83
if [ -z "${SECRET_DIR}" ]
84
then
Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
85
86
87
88
89
90
91
92
93
94
    if [ -e secret ]
    then
        SECRET_DIR=$( pwd )/ci/secret
    else
        SECRET_DIR=$( realpath ~/secret )
    fi
fi
echo "export SECRET_DIR=$SECRET_DIR" >> .variables
export VOLUME=$( dirname $( pwd ) )
export SECRET_DIR=${SECRET_DIR}
95

Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
96
97
# start container
docker pull ${IMAGE_NAME}
98

Stefan Wolfsheimer's avatar
Stefan Wolfsheimer committed
99
100
docker-compose -f ci/docker-compose.yml run --rm icat \
               /app/b2safe_entry_point.sh sudo -u irods /app/run_b2safe_tests.sh