Skip to content

Commit a97580c

Browse files
committed
build(Jenkins): add Jenkinsfile
1 parent e3720f7 commit a97580c

2 files changed

Lines changed: 195 additions & 0 deletions

File tree

Dockerfile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
ARG PYTHON_VERSION="3.10"
2+
3+
FROM python:${PYTHON_VERSION}
4+
5+
SHELL ["/bin/bash", "-c"]
6+
7+
# set timezone
8+
9+
ARG TIMEZONE="Europe/Warsaw"
10+
11+
RUN set -Eeuxo pipefail && \
12+
apt-get update && \
13+
apt-get install --no-install-recommends -y \
14+
tzdata && \
15+
echo "${TIMEZONE}" > /etc/timezone && \
16+
cp "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime && \
17+
apt-get -qy autoremove && \
18+
apt-get clean && \
19+
rm -rf /var/lib/apt/lists/*
20+
21+
# add a non-root user
22+
23+
ARG USER_ID=1000
24+
ARG GROUP_ID=1000
25+
ARG AUX_GROUP_IDS=""
26+
27+
RUN set -Eeuxo pipefail && \
28+
addgroup --gid "${GROUP_ID}" user && \
29+
adduser --disabled-password --gecos "User" --uid "${USER_ID}" --gid "${GROUP_ID}" user && \
30+
echo ${AUX_GROUP_IDS} | xargs -n1 echo | xargs -I% addgroup --gid % group% && \
31+
echo ${AUX_GROUP_IDS} | xargs -n1 echo | xargs -I% usermod --append --groups group% user
32+
33+
# install dependencies
34+
35+
RUN set -Eeuxo pipefail && \
36+
apt-get update && \
37+
apt-get install --no-install-recommends -y \
38+
git && \
39+
apt-get -qy autoremove && \
40+
apt-get clean && \
41+
rm -rf /var/lib/apt/lists/*
42+
43+
# prepare version_query for testing
44+
45+
WORKDIR /home/user/version-query
46+
47+
COPY --chown=${USER_ID}:${GROUP_ID} requirements*.txt ./
48+
49+
RUN set -Eeuxo pipefail && \
50+
pip3 install -r requirements_ci.txt
51+
52+
USER user
53+
54+
WORKDIR /home/user
55+
56+
VOLUME ["/home/user/version-query"]
57+
58+
ENV EXAMPLE_PROJECTS_PATH="/home/user"
59+
60+
RUN set -Eeuxo pipefail && \
61+
git clone https://github.com/PyCQA/pycodestyle ../pycodestyle && \
62+
cd ../pycodestyle && \
63+
python setup.py build && \
64+
cd - && \
65+
git clone https://github.com/mbdevpl/argunparse ../argunparse && \
66+
cd ../argunparse && \
67+
pip install -r test_requirements.txt && \
68+
python setup.py build && \
69+
cd - && \
70+
git clone https://github.com/python-semver/python-semver ../semver && \
71+
cd ../semver && \
72+
python setup.py build && \
73+
cd - && \
74+
pip install jupyter
75+
76+
WORKDIR /home/user/version-query

Jenkinsfile

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env groovy
2+
3+
library 'jenkins-mbdev-pl-libs'
4+
5+
pipeline {
6+
7+
options {
8+
ansiColor('xterm')
9+
}
10+
11+
environment {
12+
PYTHON_MODULES = 'ingit test *.py'
13+
}
14+
15+
agent any
16+
17+
stages {
18+
stage('Matrix') {
19+
matrix {
20+
21+
axes {
22+
axis {
23+
name 'PYTHON_VERSION'
24+
values '3.8', '3.9', '3.10'
25+
}
26+
}
27+
28+
agent {
29+
dockerfile {
30+
additionalBuildArgs '--build-arg USER_ID=${USER_ID} --build-arg GROUP_ID=${GROUP_ID}' \
31+
+ ' --build-arg AUX_GROUP_IDS="${AUX_GROUP_IDS}" --build-arg TIMEZONE=${TIMEZONE}' \
32+
+ ' --build-arg PYTHON_VERSION=${PYTHON_VERSION}'
33+
label 'docker'
34+
}
35+
}
36+
37+
stages {
38+
39+
stage('Lint') {
40+
when {
41+
environment name: 'PYTHON_VERSION', value: '3.10'
42+
}
43+
steps {
44+
sh """#!/usr/bin/env bash
45+
set -Eeux pipefail
46+
python -m pylint ${PYTHON_MODULES} |& tee pylint.log
47+
echo "\${PIPESTATUS[0]}" | tee pylint_status.log
48+
python -m mypy ${PYTHON_MODULES} |& tee mypy.log
49+
echo "\${PIPESTATUS[0]}" | tee mypy_status.log
50+
python -m pycodestyle ${PYTHON_MODULES} |& tee pycodestyle.log
51+
echo "\${PIPESTATUS[0]}" | tee pycodestyle_status.log
52+
python -m pydocstyle ${PYTHON_MODULES} |& tee pydocstyle.log
53+
echo "\${PIPESTATUS[0]}" | tee pydocstyle_status.log
54+
"""
55+
}
56+
}
57+
58+
stage('Test') {
59+
steps {
60+
sh '''#!/usr/bin/env bash
61+
set -Eeuxo pipefail
62+
TEST_PACKAGING=1 python -m coverage run --branch --source . -m unittest -v
63+
'''
64+
}
65+
}
66+
67+
stage('Coverage') {
68+
when {
69+
environment name: 'PYTHON_VERSION', value: '3.10'
70+
}
71+
steps {
72+
sh '''#!/usr/bin/env bash
73+
set -Eeux
74+
python -m coverage report --show-missing |& tee coverage.log
75+
echo "${PIPESTATUS[0]}" | tee coverage_status.log
76+
'''
77+
script {
78+
defaultHandlers.afterPythonBuild()
79+
}
80+
}
81+
}
82+
83+
stage('Codecov') {
84+
environment {
85+
CODECOV_TOKEN = credentials('codecov-token-mbdevpl-version-query')
86+
}
87+
steps {
88+
sh '''#!/usr/bin/env bash
89+
set -Eeuxo pipefail
90+
python -m codecov --token ${CODECOV_TOKEN}
91+
'''
92+
}
93+
}
94+
95+
}
96+
97+
}
98+
}
99+
}
100+
101+
post {
102+
unsuccessful {
103+
script {
104+
defaultHandlers.afterBuildFailed()
105+
}
106+
}
107+
regression {
108+
script {
109+
defaultHandlers.afterBuildBroken()
110+
}
111+
}
112+
fixed {
113+
script {
114+
defaultHandlers.afterBuildFixed()
115+
}
116+
}
117+
}
118+
119+
}

0 commit comments

Comments
 (0)