Skip to content

Commit

Permalink
Add .tekton
Browse files Browse the repository at this point in the history
Signed-off-by: Ferenc Géczi <ferenc.geczi@ibm.com>
  • Loading branch information
Ferenc- committed Feb 16, 2024
1 parent a8aad4d commit 3059838
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 4 deletions.
48 changes: 48 additions & 0 deletions .tekton/listener.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: tekton.dev/v1
kind: TriggerTemplate
metadata:
name: template
spec:
params:
- name: revision
description: The branch for the git repo
resourcetemplates:
- apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: python-tracer-ci-pipeline-run-$(uid)
spec:
pipelineRef:
name: python-tracer-ci-pipeline
workspaces:
- name: python-tracer-ci-pipeline-pvc
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
params:
- name: revision
value: $(params.revision)
---
apiVersion: tekton.dev/v1
kind: TriggerBinding
metadata:
name: binding
spec:
params:
- name: revision
value: "tekton"
---
apiVersion: tekton.dev/v1beta1
kind: EventListener
metadata:
name: listener
spec:
triggers:
- binding:
name: binding
template:
name: template
77 changes: 77 additions & 0 deletions .tekton/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: python-tracer-ci-pipeline
spec:
params:
- name: revision
type: string
workspaces:
- name: python-tracer-ci-pipeline-pvc
tasks:
- name: clone
params:
- name: revision
value: $(params.revision)
taskRef:
name: python-tracer-clone-task
workspaces:
- name: task-pvc
workspace: python-tracer-ci-pipeline-pvc
- name: unittest-default
runAfter:
- clone
matrix:
params:
- name: imageTag
value:
- "3.7.17"
- "3.8.18"
- "3.9.18"
- "3.10.13"
- "3.11.8"
- "3.12.2"
taskRef:
name: python-tracer-unittest-default-task
workspaces:
- name: task-pvc
workspace: python-tracer-ci-pipeline-pvc
- name: unittest-cassandra
runAfter:
- clone
matrix:
params:
- name: imageTag
value:
- "3.9.18"
taskRef:
name: python-tracer-unittest-cassandra-task
workspaces:
- name: task-pvc
workspace: python-tracer-ci-pipeline-pvc
- name: unittest-couchbase
runAfter:
- clone
matrix:
params:
- name: imageTag
value:
- "3.9.18"
taskRef:
name: python-tracer-unittest-couchbase-task
workspaces:
- name: task-pvc
workspace: python-tracer-ci-pipeline-pvc
- name: unittest-gevent
runAfter:
- clone
matrix:
params:
- name: imageTag
value:
- "3.9.18"
taskRef:
name: python-tracer-unittest-gevent-task
workspaces:
- name: task-pvc
workspace: python-tracer-ci-pipeline-pvc
19 changes: 19 additions & 0 deletions .tekton/pipelinerun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: python-tracer-ci-pipeline-run
spec:
pipelineRef:
name: python-tracer-ci-pipeline
workspaces:
- name: python-tracer-ci-pipeline-pvc
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
params:
- name: revision
value: "tekton"
76 changes: 76 additions & 0 deletions .tekton/run_unittests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
set -e

if [[ -z "${TEST_CONFIGURATION}" ]]; then
echo "The TEST_CONFIGURATION environment variable is missing." >&2
echo "This should have been provided by the Tekton Task or the developer" >&2
exit 1
fi

if [[ -z "${PYTHON_VERSION}" ]]; then
echo "The PYTHON_VERSION environment variable is missing." >&2
echo "This is a built-in variable in the official python container images" >&2
exit 2
fi

PYTHON_MINOR_VERSION="$(echo "${PYTHON_VERSION}" | cut -d'.' -f 2)"

case "${TEST_CONFIGURATION}" in
default)
case "${PYTHON_MINOR_VERSION}" in
7)
export REQUIREMENTS='requirements-307.txt' ;;
10 | 11)
export REQUIREMENTS='requirements-310.txt' ;;
12)
export REQUIREMENTS='requirements-312.txt' ;;
*)
export REQUIREMENTS='requirements.txt' ;;
esac
export TESTS='tests' ;;
cassandra)
export REQUIREMENTS='requirements-cassandra.txt'
export TESTS='tests/clients/test_cassandra-driver.py'
export CASSANDRA_TEST='true' ;;
couchbase)
export REQUIREMENTS='requirements-couchbase.txt'
export TESTS='tests/clients/test_couchbase.py'
export COUCHBASE_TEST='true' ;;
gevent)
export REQUIREMENTS='requirements-gevent.txt'
export TESTS='tests/frameworks/test_gevent.py'
export GEVENT_TEST='true' ;;
*)
echo "ERROR \$TEST_CONFIGURATION='${TEST_CONFIGURATION}' is unsupported " \
"not in (default|cassandra|couchbase|gevent)" >&2
exit 3 ;;
esac

echo -n "Configuration is '${TEST_CONFIGURATION}' on ${PYTHON_VERSION} "
echo "with dependencies in '${REQUIREMENTS}'"
export INSTANA_TEST='true'
ls -lah .
if [[ -n "${COUCHBASE_TEST}" ]]; then
echo "Install Couchbase Dependencies"
# Even if we use bookworm for running this, we need to add the bionic repo
# See: https://forums.couchbase.com/
# t/installing-libcouchbase-dev-on-ubuntu-20-focal-fossa/25955/3
wget -O - http://packages.couchbase.com/ubuntu/couchbase.key | apt-key add -
echo "deb http://packages.couchbase.com/ubuntu bionic bionic/main" \
> /etc/apt/sources.list.d/couchbase.list
apt update
apt install libcouchbase-dev -y
fi
python -m venv /tmp/venv
# shellcheck disable=SC1091
source /tmp/venv/bin/activate
pip install --upgrade pip "$([[ -n ${COUCHBASE_TEST} ]] && echo wheel || echo pip)"
pip install -e .
pip install -r "tests/${REQUIREMENTS}"

coverage run \
--source=instana \
--data-file=".coverage-${PYTHON_VERSION}-${TEST_CONFIGURATION}" \
--module \
pytest \
--verbose --junitxml=test-results "${TESTS}" # pytest options (not coverage options anymore)
157 changes: 157 additions & 0 deletions .tekton/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: python-tracer-clone-task
spec:
params:
- name: revision
type: string
workspaces:
- name: task-pvc
mountPath: /workspace
steps:
- name: clone
image: alpine/git
script: |
#!/bin/sh
echo "Cloning repo"
cd /workspace && git clone --depth 1 -b $(params.revision) https://github.com/instana/python-sensor
ls -lah /workspace
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: python-tracer-unittest-cassandra-task
spec:
sidecars:
- name: cassandra
image: cassandra:3.11
env:
- name: MAX_HEAP_SIZE
value: 2048m
- name: HEAP_NEWSIZE
value: 512m
params:
- name: imageTag
type: string
workspaces:
- name: task-pvc
mountPath: /workspace
steps:
- name: unittest
image: python:$(params.imageTag)
env:
- name: TEST_CONFIGURATION
value: cassandra
workingDir: /workspace/python-sensor/
command:
- /workspace/python-sensor/.tekton/run_unittests.sh
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: python-tracer-unittest-couchbase-task
spec:
sidecars:
- name: couchbase
image: couchbase/server-sandbox:5.5.0
params:
- name: imageTag
type: string
workspaces:
- name: task-pvc
mountPath: /workspace
steps:
- name: unittest
image: python:$(params.imageTag)
env:
- name: TEST_CONFIGURATION
value: couchbase
workingDir: /workspace/python-sensor/
command:
- /workspace/python-sensor/.tekton/run_unittests.sh
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: python-tracer-unittest-gevent-task
spec:
params:
- name: imageTag
type: string
workspaces:
- name: task-pvc
mountPath: /workspace
steps:
- name: unittest
image: python:$(params.imageTag)
env:
- name: TEST_CONFIGURATION
value: gevent
workingDir: /workspace/python-sensor/
command:
- /workspace/python-sensor/.tekton/run_unittests.sh
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: python-tracer-unittest-default-task
spec:
sidecars:
- name: couchbase
image: couchbase/server-sandbox:5.5.0
- name: google-cloud-pubsub
image: egymgmbh/pubsub-emulator
command:
- /init.sh
- test-project
- test-topic
- test-subscription
- name: mariadb
image: mariadb:11.2.3
env:
- name: MYSQL_ROOT_PASSWORD # or MARIADB_ROOT_PASSWORD
value: passw0rd
- name: MYSQL_DATABASE # or MARIADB_DATABASE
value: circle_test
- name: mongo
image: mongo:4.2.3
- name: postgres
image: postgres:9.6.24
env:
- name: POSTGRES_USER
value: root
- name: POSTGRES_PASSWORD
value: passw0rd
# TODO: Change this once Circle CI is gone
- name: POSTGRES_DB
value: circle_test
readinessProbe:
exec:
command:
- sh
- -c
- pg_isready --host 127.0.0.1 --port 5432 --dbname=${POSTGRES_DB}
timeoutSeconds: 10
- name: redis
image: redis:7.2.4
- name: rabbitmq
image: rabbitmq:3.12.12
params:
- name: imageTag
type: string
workspaces:
- name: task-pvc
mountPath: /workspace
steps:
# Change if https://github.com/tektoncd/pipeline/issues/7669 resolved
# - name: unittest-$(params.python-runtime-configuration-object.dnsLabelName)'
- name: unittest
image: python:$(params.imageTag)
env:
- name: TEST_CONFIGURATION
value: default
workingDir: /workspace/python-sensor/
command:
- /workspace/python-sensor/.tekton/run_unittests.sh
6 changes: 2 additions & 4 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
"""
if 'MYSQL_HOST' in os.environ:
testenv['mysql_host'] = os.environ['MYSQL_HOST']
elif 'TRAVIS_MYSQL_HOST' in os.environ:
testenv['mysql_host'] = os.environ['TRAVIS_MYSQL_HOST']
else:
testenv['mysql_host'] = '127.0.0.1'

testenv['mysql_port'] = int(os.environ.get('MYSQL_PORT', '3306'))
testenv['mysql_db'] = os.environ.get('MYSQL_DB', 'circle_test')
testenv['mysql_db'] = os.environ.get('MYSQL_DATABASE', 'circle_test')
testenv['mysql_user'] = os.environ.get('MYSQL_USER', 'root')
testenv['mysql_pw'] = os.environ.get('MYSQL_PW', '')
testenv['mysql_pw'] = os.environ.get('MYSQL_PW', 'passw0rd')

"""
PostgreSQL Environment
Expand Down

0 comments on commit 3059838

Please sign in to comment.