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 19, 2024
1 parent ca4e60e commit 56f9a9e
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .tekton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Tekton CI for Instana Python Tracer

## Get a cluster

What you will need:
* Full administrator access
* Enough RAM and CPU on a cluster node to run all the pods of a single Pipelinerun on a single node.
Multiple nodes increase the number of parallel `PipelineRun` instances.
Currently one `PipelineRun` instance is capable of saturating a 8vCPU - 16GB RAM worker node.

## Setup Tekton on your cluster

1. Install tatest stable Tekton Pipeline release
```bash
kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
```

2. Install Tekton Dashboard Full (the normal is read only, and doesn't allow for example to re-run).

````bash
kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/latest/release-full.yaml
````

3. Access the dashboard

```bash
kubectl proxy
```

Once the proxy is active, navigate your browser to the [dashboard url](
http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/)

## Setup the python-tracer-ci-pipeline

````bash
kubectl apply --filename ./task.yaml && kubectl apply --filename ./pipeline.yaml
````

## Run the pipeline

````bash
kubectl apply --filename ./pipelinerun.yaml
````
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:
params:
- name: revision
value: "master"
pipelineRef:
name: python-tracer-ci-pipeline
workspaces:
- name: python-tracer-ci-pipeline-pvc
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
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)
162 changes: 162 additions & 0 deletions .tekton/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
---
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
readinessProbe:
exec:
command:
- cqlsh
- -e
- 'describe cluster'
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
readinessProbe:
httpGet:
path: /ui/index.html
port: 8091
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: 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: instana_test_db
- 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
- name: POSTGRES_DB
value: instana_test_db
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:
- name: unittest
image: python:$(params.imageTag)
env:
- name: TEST_CONFIGURATION
value: default
workingDir: /workspace/python-sensor/
command:
- /workspace/python-sensor/.tekton/run_unittests.sh

0 comments on commit 56f9a9e

Please sign in to comment.