forked from containerbuildsystem/atomic-reactor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·114 lines (98 loc) · 3.96 KB
/
test.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
#!/bin/bash
set -eux
# Prepare env vars
OS=${OS:="centos"}
OS_VERSION=${OS_VERSION:="7"}
PYTHON_VERSION=${PYTHON_VERSION:="2"}
IMAGE="$OS:$OS_VERSION"
# Pull fedora images from registry.fedoraproject.org
if [[ $OS == "fedora" ]]; then
IMAGE="registry.fedoraproject.org/$IMAGE"
fi
docker_mounts="-v $PWD:$PWD:z"
for dir in ${EXTRA_MOUNT:-}; do
docker_mounts="${docker_mounts} -v $dir:$dir:z"
done
CONTAINER_NAME="atomic-reactor-$OS-$OS_VERSION-py$PYTHON_VERSION"
RUN="docker exec -ti $CONTAINER_NAME"
if [[ $OS == "fedora" ]]; then
PIP_PKG="python$PYTHON_VERSION-pip"
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA="dnf-plugins-core desktop-file-utils flatpak libmodulemd ostree python$PYTHON_VERSION-gobject-base"
BUILDDEP="dnf builddep"
PYTHON="python$PYTHON_VERSION"
else
PIP_PKG="python-pip"
PIP="pip"
PKG="yum"
PKG_EXTRA="yum-utils epel-release git-core desktop-file-utils"
BUILDDEP="yum-builddep"
PYTHON="python"
fi
# Create or resurrect container if needed
if [[ $(docker ps -qa -f name=$CONTAINER_NAME | wc -l) -eq 0 ]]; then
docker run --name $CONTAINER_NAME -d $docker_mounts -w $PWD -ti $IMAGE sleep infinity
elif [[ $(docker ps -q -f name=$CONTAINER_NAME | wc -l) -eq 0 ]]; then
echo found stopped existing container, restarting. volume mounts cannot be updated.
docker container start $CONTAINER_NAME
fi
if [[ $OS == "centos" ]]; then
# Don't let builddep enable *-source repos since they give 404 errors
$RUN rm -f /etc/yum.repos.d/CentOS-Sources.repo
fi
# Install dependencies
$RUN $PKG install -y $PKG_EXTRA
$RUN $BUILDDEP -y atomic-reactor.spec
if [[ $OS == "fedora" ]]; then
# Remove python-docker-py because docker-squash will pull
# in the latest version from PyPI. Don't remove the dependencies
# that it pulled in, to avoid having to rebuild them.
$RUN $PKG remove -y --noautoremove python{,3}-docker{,-py}
else
# Install dependecies for test, as check is disabled for rhel
$RUN yum install -y python-flexmock python-six \
python-backports-lzma \
python-backports-ssl_match_hostname \
python-responses \
PyYAML \
python-requests python-requests-kerberos # OSBS dependencies
fi
# Install package
$RUN $PKG install -y $PIP_PKG
if [[ $PYTHON_VERSION == 3 && $OS_VERSION == rawhide ]]; then
# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
$RUN mkdir -p /usr/local/lib/python3.6/site-packages/
fi
if [[ $OS == centos && $OS_VERSION == 7 ]]; then
# Older versions of setuptools don't understand the environment
# markers used by docker-squash's requirements
$RUN $PIP install -U setuptools
fi
# Install other dependencies for tests
# Install latest osbs-client by installing dependencies from the master branch
# and running pip install with '--no-deps' to avoid compilation
# This would also ensure all the deps are specified in the spec
$RUN rm -rf /tmp/osbs-client
$RUN git clone https://github.com/projectatomic/osbs-client /tmp/osbs-client
$RUN $BUILDDEP -y /tmp/osbs-client/osbs-client.spec
$RUN $PIP install --upgrade --no-deps --force-reinstall git+https://github.com/projectatomic/osbs-client
$RUN $PIP install --upgrade --no-deps --force-reinstall git+https://github.com/DBuildService/dockerfile-parse
if [[ $PYTHON_VERSION == 2* ]]; then
$RUN $PIP install git+https://github.com/release-engineering/dockpulp
$RUN $PIP install -r requirements-py2.txt
fi
# Install flatpak dependencies only on fedora
if [[ $OS == "fedora" ]]; then
$RUN $PIP install -r requirements-flatpak.txt
fi
$RUN $PIP install docker-squash
$RUN $PYTHON setup.py install
# Install packages for tests
$RUN $PIP install -r tests/requirements.txt
# CentOS needs to have setuptools updates to make pytest-cov work
if [[ $OS != "fedora" ]]; then $RUN $PIP install -U setuptools; fi
# Run tests
$RUN pytest -vv tests --cov atomic_reactor --cov-report html "$@"
echo "To run tests again:"
echo "$RUN pytest -vv tests --cov atomic_reactor --cov-report html"