forked from containerbuildsystem/koji-containerbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·153 lines (130 loc) · 4.79 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
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
#!/bin/bash
set -eux
# Prepare env vars
ENGINE=${ENGINE:="podman"}
OS=${OS:="centos"}
OS_VERSION=${OS_VERSION:="7"}
PYTHON_VERSION=${PYTHON_VERSION:="2"}
ACTION=${ACTION:="test"}
IMAGE="$OS:$OS_VERSION"
CONTAINER_NAME="koji-containerbuild-$OS-$OS_VERSION-py$PYTHON_VERSION"
# Use arrays to prevent globbing and word splitting
engine_mounts=(-v "$PWD":"$PWD":z)
for dir in ${EXTRA_MOUNT:-}; do
engine_mounts=("${engine_mounts[@]}" -v "$dir":"$dir":z)
done
# Create or resurrect container if needed
if [[ $($ENGINE ps -qa -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
$ENGINE run --name "$CONTAINER_NAME" -d "${engine_mounts[@]}" -w "$PWD" -ti "$IMAGE" sleep infinity
elif [[ $($ENGINE ps -q -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
echo found stopped existing container, restarting. volume mounts cannot be updated.
$ENGINE container start "$CONTAINER_NAME"
fi
function setup_kojic() {
RUN="$ENGINE exec -i $CONTAINER_NAME"
if [[ $OS == "centos" ]]; then
PYTHON="python"
PIP_PKG="$PYTHON-pip"
PIP="pip"
PKG="yum"
PKG_EXTRA=(yum-utils git-core koji koji-hub)
BUILDDEP="yum-builddep"
else
PYTHON="python$PYTHON_VERSION"
PIP_PKG="$PYTHON-pip"
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA=(dnf-plugins-core git-core "$PYTHON"-koji "$PYTHON"-koji-hub)
BUILDDEP=(dnf builddep)
fi
PIP_INST=("$PIP" install --index-url "${PYPI_INDEX:-https://pypi.org/simple}")
if [[ $OS == "centos" ]]; then
$RUN $PKG install -y epel-release;
fi
$RUN $PKG install -y "${PKG_EXTRA[@]}"
[[ ${PYTHON_VERSION} == '3' ]] && WITH_PY3=1 || WITH_PY3=0
$RUN "${BUILDDEP[@]}" -y koji-containerbuild.spec
# Install pip package
$RUN $PKG install -y $PIP_PKG
if [[ ${WITH_PY3} && $OS_VERSION == rawhide ]]; then
# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
$RUN mkdir -p /usr/local/lib/python3.6/site-packages/
fi
# Install other dependencies for unit tests
if [[ ${WITH_PY3} == 1 ]]; then
OSBS_CLIENT_DEPS="python3-PyYAML"
else
OSBS_CLIENT_DEPS="PyYAML"
fi
$RUN $PKG install -y $OSBS_CLIENT_DEPS
# Install osbs-client dependencies based on specfile
# from specified git source (default: upstream master)
$RUN rm -rf /tmp/osbs-client
$RUN git clone --depth 1 --single-branch \
https://github.com/projectatomic/osbs-client --branch master /tmp/osbs-client
# RPM install build dependencies for osbs-client
$RUN "${BUILDDEP[@]}" --define "with_python3 ${WITH_PY3}" -y /tmp/osbs-client/osbs-client.spec
if [[ ${OS} == "centos" && ${WITH_PY3} == 0 ]]; then
# there is no package that could provide more-itertools module on centos7
# latest version with py2 support in PyPI is 5.0.0, never version causes
# failures with py2
$RUN "${PIP_INST[@]}" 'more-itertools==5.*'
fi
# Run pip install with '--no-deps' to avoid compilation.
# This will also ensure all the deps are specified in the spec
# Pip install osbs-client from git master
$RUN "${PIP_INST[@]}" --upgrade --no-deps --force-reinstall \
git+https://github.com/projectatomic/osbs-client
# Pip install dockerfile-parse from git master
$RUN "${PIP_INST[@]}" --upgrade --force-reinstall \
git+https://github.com/containerbuildsystem/dockerfile-parse
# CentOS needs to have setuptools updates to make pytest-cov work
# setuptools will no longer support python2 starting on version 45
if [[ $OS == "centos" ]]; then
$RUN "${PIP_INST[@]}" -U 'setuptools<45'
# Watch out for https://github.com/pypa/setuptools/issues/937
$RUN curl -O https://bootstrap.pypa.io/2.6/get-pip.py
$RUN $PYTHON get-pip.py
fi
if [[ $PYTHON_VERSION == 2 ]]; then
# https://github.com/jaraco/zipp/issues/28
$RUN "${PIP_INST[@]}" zipp==1.0.0
# configparser no longer supports python 2
$RUN "${PIP_INST[@]}" configparser==4.0.2
# pyrsistent >= 0.17 no longer supports python 2
# pyrsistent is a dependency of jsonschema
$RUN "${PIP_INST[@]}" 'pyrsistent==0.16.*'
fi
# Setuptools install koji-c from source
$RUN $PYTHON setup.py install
# Pip install packages for unit tests
$RUN "${PIP_INST[@]}" -r tests/requirements.txt
}
case ${ACTION} in
"test")
setup_kojic
TEST_CMD="coverage run --source=koji_containerbuild -m pytest tests"
;;
"pylint")
setup_kojic
# This can run only at fedora because pylint is not packaged in centos
# use distro pylint to not get too new pylint version
$RUN $PKG install -y "${PYTHON}-pylint"
PACKAGES='koji_containerbuild tests'
TEST_CMD="${PYTHON} -m pylint ${PACKAGES}"
;;
"bandit")
setup_kojic
$RUN "${PIP_INST[@]}" "bandit<1.6.2"
TEST_CMD="bandit-baseline -r koji_containerbuild -ll -ii"
;;
*)
echo "Unknown action: ${ACTION}"
exit 2
;;
esac
# Run tests
# shellcheck disable=SC2086
$RUN ${TEST_CMD} "$@"
echo "To run tests again:"
echo "$RUN ${TEST_CMD}"