forked from containerbuildsystem/koji-containerbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·161 lines (139 loc) · 4.95 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
154
155
156
157
158
159
160
161
#!/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"
if [[ $ACTION == "markdownlint" ]]; then
IMAGE="ruby"
CONTAINER_NAME="koji-containerbuild-$ACTION-$IMAGE"
fi
RUN="$ENGINE exec -ti $CONTAINER_NAME"
# 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() {
# Pull fedora images from registry.fedoraproject.org
if [[ $OS == "fedora" ]]; then
IMAGE="registry.fedoraproject.org/$IMAGE"
fi
if [[ $OS == "fedora" ]]; then
PIP_PKG="python$PYTHON_VERSION-pip"
PIP="pip$PYTHON_VERSION"
PKG="dnf"
PKG_EXTRA="dnf-plugins-core git-core
python$PYTHON_VERSION-koji python$PYTHON_VERSION-koji-hub"
BUILDDEP="dnf builddep"
PYTHON="python$PYTHON_VERSION"
else
PIP_PKG="python-pip"
PIP="pip"
PKG="yum"
PKG_EXTRA="yum-utils git-core koji koji-hub"
BUILDDEP="yum-builddep"
PYTHON="python"
fi
# Create container if needed
if [[ $($ENGINE ps -q -f name="$CONTAINER_NAME" | wc -l) -eq 0 ]]; then
$ENGINE run --name "$CONTAINER_NAME" -d -v "$PWD":"$PWD":z -w "$PWD" -ti "$IMAGE" sleep infinity
fi
# Install dependencies
if [[ $OS != "fedora" ]]; then $RUN $PKG install -y epel-release; fi
$RUN $PKG install -y $PKG_EXTRA
$RUN $BUILDDEP -y koji-containerbuild.spec
# Install pip 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
RUN="$ENGINE exec -ti $CONTAINER_NAME"
# Install other dependencies for tests
if [[ $PYTHON_VERSION == 3 ]]; then
OSBS_CLIENT_DEPS="python3-PyYAML"
else
OSBS_CLIENT_DEPS="PyYAML"
fi
$RUN $PKG install -y $OSBS_CLIENT_DEPS
# 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
[[ ${PYTHON_VERSION} == '3' ]] && WITH_PY3=1 || WITH_PY3=0
$RUN $BUILDDEP --define "with_python3 ${WITH_PY3}" -y /tmp/osbs-client/osbs-client.spec
if [[ ${OS} == "centos" && ${PYTHON_VERSION} == 2 ]]; 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 install 'more-itertools==5.*'
fi
$RUN $PIP install --upgrade --no-deps --force-reinstall git+https://github.com/projectatomic/osbs-client
# Install the latest dockerfile-parse from git
$RUN $PIP install --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 != "fedora" ]]; then
$RUN $PIP install -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
# https://github.com/jaraco/zipp/issues/28
if [[ $PYTHON_VERSION == 2 ]]; then
$RUN $PIP install zipp==1.0.0
fi
# configparser no longer supports python 2
if [[ $PYTHON_VERSION == 2 ]]; then
$RUN $PIP install configparser==4.0.2
fi
# Install koji-containerbuild
$RUN $PYTHON setup.py install
# Install packages for tests
$RUN $PIP install -r tests/requirements.txt
}
case ${ACTION} in
"test")
setup_kojic
TEST_CMD="pytest -vv tests --cov koji_containerbuild"
;;
"bandit")
setup_kojic
$RUN $PIP install bandit
TEST_CMD="bandit-baseline -r koji_containerbuild -ll -ii"
;;
"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}"
;;
"markdownlint")
$RUN gem install mdl
TEST_CMD="mdl -g ."
;;
*)
echo "Unknown action: ${ACTION}"
exit 2
;;
esac
# Run tests
$RUN ${TEST_CMD} "$@"
echo "To run tests again:"
echo "$RUN ${TEST_CMD}"