Skip to content

Commit 83b8759

Browse files
authored
Merge pull request #221 from splunk/port-to-python3
Python3 support
2 parents 7a28b42 + 0570ed7 commit 83b8759

File tree

7 files changed

+194
-8
lines changed

7 files changed

+194
-8
lines changed

.circleci/config.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ jobs:
66
steps:
77
- checkout
88
- run:
9-
name: Build Container
9+
name: Setup python3
1010
command: |
11-
make all
11+
pyenv global 2.7.12 3.5.2
12+
python --version
13+
pip --version
14+
python3 --version
15+
pip3 --version
1216
- run:
1317
name: Setup Tests / Scanner Requirements
1418
command: |
1519
make test_setup
20+
- run:
21+
name: Build Container
22+
command: |
23+
make all
1624
- run:
1725
name: Export Build Images for Artifacts
1826
command: |
@@ -26,7 +34,16 @@ jobs:
2634
path: clair-scanner-logs
2735
destintation: clair-scanner-logs
2836
- run:
29-
name: Running CI Tests
37+
name: Test Python3 installation
38+
command: make test_python3_all
39+
- run:
40+
name: Test Python2 as the default
41+
command: make test_python2_all
42+
- run:
43+
name: Test if image size increase
44+
command: make test_debian9_image_size
45+
- run:
46+
name: Running debian9 CI Tests
3047
command: make run_tests_debian9
3148
no_output_timeout: 20m
3249
- store_artifacts:

Makefile

Lines changed: 146 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ SCANNER_DATE := `date +%Y-%m-%d`
3131
SCANNER_DATE_YEST := `TZ=GMT+24 +%Y:%m:%d`
3232
SCANNER_VERSION := v8
3333
SCANNER_LOCALIP := $(shell ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | awk '{print $1}' | head -n 1)
34-
SCANNER_IMAGES_TO_SCAN := splunk-debian-9 splunk-debian-10 splunk-centos-7 splunk-redhat-8 uf-debian-9 uf-debian-10 uf-centos-7 uf-redhat-8
35-
CONTAINERS_TO_SAVE := splunk-debian-9 splunk-debian-10 splunk-centos-7 splunk-redhat-8 uf-debian-9 uf-debian-10 uf-centos-7 uf-redhat-8
34+
SCANNER_IMAGES_TO_SCAN := splunk-debian-9 splunk-debian-10 splunk-centos-7 splunk-redhat-8 uf-debian-9 uf-debian-10 uf-centos-7 uf-redhat-8 splunk-py23-debian-9 splunk-py23-debian-10 splunk-py23-centos-7 splunk-py23-redhat-8 uf-py23-debian-9 uf-py23-debian-10 uf-py23-centos-7 uf-py23-redhat-8
35+
CONTAINERS_TO_SAVE := splunk-debian-9 splunk-debian-10 splunk-centos-7 splunk-redhat-8 uf-debian-9 uf-debian-10 uf-centos-7 uf-redhat-8 splunk-py23-debian-9 splunk-py23-debian-10 splunk-py23-centos-7 splunk-py23-redhat-8 uf-py23-debian-9 uf-py23-debian-10 uf-py23-centos-7 uf-py23-redhat-8
3636
ifeq ($(shell uname), Linux)
3737
SCANNER_FILE = clair-scanner_linux_amd64
3838
else ifeq ($(shell uname), Darwin)
@@ -44,7 +44,7 @@ endif
4444

4545
.PHONY: tests interactive_tutorials
4646

47-
all: splunk uf
47+
all: splunk uf splunk-py23 uf-py23
4848

4949
ansible:
5050
@if [ -d "splunk-ansible" ]; then \
@@ -225,6 +225,61 @@ uf-windows-2016: base-windows-2016 ansible
225225
--build-arg SPLUNK_BUILD_URL=${UF_WIN_BUILD_URL} \
226226
-t uf-windows-2016:${IMAGE_VERSION} .
227227

228+
229+
##### Python 3 support #####
230+
splunk-py23: splunk-py23-debian-9 splunk-py23-debian-10 splunk-py23-centos-7 splunk-py23-redhat-8
231+
232+
splunk-py23-debian-9: splunk-debian-9
233+
docker build ${DOCKER_BUILD_FLAGS} \
234+
-f py23-image/debian-9/Dockerfile \
235+
--build-arg SPLUNK_PRODUCT=splunk \
236+
-t splunk-py23-debian-9:${IMAGE_VERSION} .
237+
238+
splunk-py23-debian-10: splunk-debian-10
239+
docker build ${DOCKER_BUILD_FLAGS} \
240+
-f py23-image/debian-10/Dockerfile \
241+
--build-arg SPLUNK_PRODUCT=splunk \
242+
-t splunk-py23-debian-10:${IMAGE_VERSION} .
243+
244+
splunk-py23-centos-7: splunk-centos-7
245+
docker build ${DOCKER_BUILD_FLAGS} \
246+
-f py23-image/centos-7/Dockerfile \
247+
--build-arg SPLUNK_PRODUCT=splunk \
248+
-t splunk-py23-centos-7:${IMAGE_VERSION} .
249+
250+
splunk-py23-redhat-8: splunk-redhat-8
251+
docker build ${DOCKER_BUILD_FLAGS} \
252+
-f py23-image/redhat-8/Dockerfile \
253+
--build-arg SPLUNK_PRODUCT=splunk \
254+
-t splunk-py23-redhat-8:${IMAGE_VERSION} .
255+
256+
uf-py23: uf-py23-debian-9 uf-py23-debian-10 uf-py23-centos-7 uf-py23-redhat-8
257+
258+
uf-py23-debian-9: uf-debian-9
259+
docker build ${DOCKER_BUILD_FLAGS} \
260+
-f py23-image/debian-9/Dockerfile \
261+
--build-arg SPLUNK_PRODUCT=uf \
262+
-t uf-py23-debian-9:${IMAGE_VERSION} .
263+
264+
uf-py23-debian-10: uf-debian-10
265+
docker build ${DOCKER_BUILD_FLAGS} \
266+
-f py23-image/debian-10/Dockerfile \
267+
--build-arg SPLUNK_PRODUCT=uf \
268+
-t uf-py23-debian-10:${IMAGE_VERSION} .
269+
270+
uf-py23-centos-7: uf-centos-7
271+
docker build ${DOCKER_BUILD_FLAGS} \
272+
-f py23-image/centos-7/Dockerfile \
273+
--build-arg SPLUNK_PRODUCT=uf \
274+
-t uf-py23-centos-7:${IMAGE_VERSION} .
275+
276+
uf-py23-redhat-8: uf-redhat-8
277+
docker build ${DOCKER_BUILD_FLAGS} \
278+
-f py23-image/redhat-8/Dockerfile \
279+
--build-arg SPLUNK_PRODUCT=uf \
280+
-t uf-py23-redhat-8:${IMAGE_VERSION} .
281+
282+
228283
##### Tests #####
229284
sample-compose-up: sample-compose-down
230285
docker-compose -f test_scenarios/${SPLUNK_COMPOSE} up -d
@@ -248,14 +303,16 @@ run_tests_centos7:
248303

249304
run_tests_redhat8:
250305
@echo 'Running the super awesome tests; RedHat 8'
251-
pytest -sv tests/test_redhat_8.py --junitxml test-results/redhat8-result/testresults_redhat8.xml
306+
pytest -sv tests/test_docker_splunk.py --platform redhat-8 --junitxml test-results/redhat8-result/testresults_redhat8.xml
252307

253308
test_setup:
254309
@echo 'Install test requirements'
255310
pip install --upgrade pip
256311
pip install -r $(shell pwd)/tests/requirements.txt --upgrade
257312
mkdir test-results/centos7-result || true
258313
mkdir test-results/debian9-result || true
314+
mkdir test-results/debian10-result || true
315+
mkdir test-results/redhat8-result || true
259316

260317
run_tests_debian9:
261318
@echo 'Running the super awesome tests; Debian 9'
@@ -270,6 +327,91 @@ save_containers:
270327
mkdir test-results/saved_images || true
271328
$(foreach image,${CONTAINERS_TO_SAVE}, echo "Currently saving: ${image}"; docker save ${image} --output test-results/saved_images/${image}.tar; echo "Compressing: ${image}.tar"; gzip test-results/saved_images/${image}.tar; )
272329

330+
test_python3_all: test_splunk_python3_all test_uf_python3_all
331+
332+
test_splunk_python3_all: test_splunk_centos7_python3 test_splunk_redhat8_python3 test_splunk_debian9_python3 test_splunk_debian10_python3
333+
334+
test_uf_python3_all: test_uf_centos7_python3 test_uf_redhat8_python3 test_uf_debian9_python3 test_uf_debian10_python3
335+
336+
test_splunk_centos7_python3:
337+
$(call test_python3_installation,splunk-py23-centos-7)
338+
339+
test_splunk_redhat8_python3:
340+
$(call test_python3_installation,splunk-py23-redhat-8)
341+
342+
test_splunk_debian9_python3:
343+
$(call test_python3_installation,splunk-py23-debian-9)
344+
345+
test_splunk_debian10_python3:
346+
$(call test_python3_installation,splunk-py23-debian-10)
347+
348+
test_uf_centos7_python3:
349+
$(call test_python3_installation,uf-py23-centos-7)
350+
351+
test_uf_redhat8_python3:
352+
$(call test_python3_installation,uf-py23-redhat-8)
353+
354+
test_uf_debian9_python3:
355+
$(call test_python3_installation,uf-py23-debian-9)
356+
357+
test_uf_debian10_python3:
358+
$(call test_python3_installation,uf-py23-debian-10)
359+
360+
define test_python3_installation
361+
docker run -d --rm --name $1 -it $1 bash
362+
docker exec -it $1 bash -c 'if [[ $$(python3 -V) =~ "Python 3" ]] ; then echo "$$(python3 -V) installed" ; else echo "No Python3 installation found" ; docker kill $1 ; exit 1 ; fi'
363+
docker kill $1
364+
endef
365+
366+
test_python2_all: test_splunk_python2_all test_uf_python2_all
367+
368+
test_splunk_python2_all: test_splunk_centos7_python2 test_splunk_redhat8_python2 test_splunk_debian9_python2 test_splunk_debian10_python2
369+
370+
test_uf_python2_all: test_uf_centos7_python2 test_uf_redhat8_python2 test_uf_debian9_python2 test_uf_debian10_python2
371+
372+
test_splunk_centos7_python2:
373+
$(call test_python2_installation,splunk-py23-centos-7)
374+
375+
test_splunk_redhat8_python2:
376+
$(call test_python2_installation,splunk-py23-redhat-8)
377+
378+
test_splunk_debian9_python2:
379+
$(call test_python2_installation,splunk-py23-debian-9)
380+
381+
test_splunk_debian10_python2:
382+
$(call test_python2_installation,splunk-py23-debian-10)
383+
384+
test_uf_centos7_python2:
385+
$(call test_python2_installation,uf-py23-centos-7)
386+
387+
test_uf_redhat8_python2:
388+
$(call test_python2_installation,uf-py23-redhat-8)
389+
390+
test_uf_debian9_python2:
391+
$(call test_python2_installation,uf-py23-debian-9)
392+
393+
test_uf_debian10_python2:
394+
$(call test_python2_installation,uf-py23-debian-10)
395+
396+
#python2 version print to stderr, hence the 2>&1
397+
define test_python2_installation
398+
docker run -d --rm --name $1 -it $1 bash
399+
docker exec -it $1 bash -c 'if [[ $$(python -V 2>&1) =~ "Python 2" ]] ; then echo "$$(python -V 2>&1) is the default python" ; else echo "Python is not default to python2" ; docker kill $1 ; exit 1 ; fi'
400+
docker kill $1
401+
endef
402+
403+
test_debian9_image_size:
404+
$(call test_image_size,splunk-debian-9)
405+
406+
define test_image_size
407+
docker pull splunk/splunk:edge
408+
CUR_SIZE=$$(docker image inspect $1:latest --format='{{.Size}}') ; \
409+
EDGE_SIZE=$$(docker image inspect splunk/splunk:edge --format='{{.Size}}') ; \
410+
echo "current $1 image size = "$$CUR_SIZE ; \
411+
echo "edge image size = "$$EDGE_SIZE ; \
412+
if [[ $$CUR_SIZE -gt $$EDGE_SIZE*102/100 ]] ; then echo "current image size is 2% more than edge image" ; exit 1 ; fi
413+
endef
414+
273415
setup_clair_scanner:
274416
mkdir clair-scanner-logs
275417
mkdir test-results/cucumber

py23-image/centos-7/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG SPLUNK_PRODUCT=splunk
2+
FROM ${SPLUNK_PRODUCT}-centos-7:latest
3+
USER root
4+
5+
RUN yum -y update
6+
RUN yum -y install python36 python36-requests
7+
RUN python3 -m ensurepip

py23-image/debian-10/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG SPLUNK_PRODUCT=splunk
2+
FROM ${SPLUNK_PRODUCT}-debian-10:latest
3+
USER root
4+
5+
RUN apt update
6+
RUN apt-get install -y --no-install-recommends python3 python3-pip python3-setuptools python3-requests python3-yaml
7+
RUN pip3 --no-cache-dir install ansible

py23-image/debian-9/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG SPLUNK_PRODUCT=splunk
2+
FROM ${SPLUNK_PRODUCT}-debian-9:latest
3+
USER root
4+
5+
RUN apt-get update
6+
RUN apt-get install -y --no-install-recommends python3 python3-pip python3-requests

py23-image/redhat-8/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG SPLUNK_PRODUCT=splunk
2+
FROM ${SPLUNK_PRODUCT}-redhat-8:latest
3+
USER root
4+
5+
RUN microdnf -y --nodocs install python3
6+
RUN alternatives --set python /usr/bin/python2
7+
RUN pip3 -q --no-cache-dir install requests ansible

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ docker
44
PyYAML
55
docker-compose
66
pyasn1
7-
junit-xml
7+
junit-xml

0 commit comments

Comments
 (0)