Skip to content

Commit 955fa76

Browse files
committed
feat: Add multi-user support to Tekton pipeline
- Parameterized git-url and namespaces for user-specific deployments - User-prefixed resource naming for complete isolation - Auto-detect users from GitHub repository owners - Add deployment examples and documentation - Support multiple developers on single cluster with namespace isolation
1 parent 9b1fae9 commit 955fa76

File tree

9 files changed

+1026
-1
lines changed

9 files changed

+1026
-1
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,71 @@ For issues and questions:
281281

282282
## License
283283

284-
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
284+
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
285+
286+
## 🚀 Multi-User Tekton Pipeline Suite
287+
288+
### Files Created:
289+
- **`deploy/tekton/pipeline.yaml`** - Main pipeline definition with 7 stages (multi-user)
290+
- **`deploy/tekton/tasks.yaml`** - Custom tasks for deployment operations (multi-user)
291+
- **`deploy/tekton/rbac.yaml`** - Service account and RBAC permissions
292+
- **`deploy/tekton/pipeline-run.yaml`** - Example pipeline run configuration
293+
- **`deploy/tekton/triggers.yaml`** - Automated GitHub webhook triggers (multi-user)
294+
- **`deploy/tekton/deploy-pipeline.sh`** - Automated deployment script
295+
- **`deploy/tekton/user-examples.yaml`** - Multi-user deployment examples
296+
- **`deploy/tekton/README.md`** - Comprehensive documentation
297+
298+
### Pipeline Flow:
299+
1. **Git Clone** - Fetches source code from any GitHub repository
300+
2. **Create Namespace** - Sets up user-specific namespaces (`ci-analysis-<username>`)
301+
3. **Build Image** - Builds container image using Buildah (user-tagged)
302+
4. **Deploy Ollama** - Deploys Ollama with persistent storage (per user)
303+
5. **Deploy CI Analysis Agent** - Deploys the main application (per user)
304+
6. **Load Model** - Loads the qwen3:4b model into Ollama
305+
7. **Create Route** - Exposes the application via OpenShift Route (per user)
306+
307+
### Key Features:
308+
-**Multi-User Support** - Multiple developers on single cluster
309+
-**Namespace Isolation** - Each user gets their own namespace
310+
-**Resource Prefixing** - All resources prefixed with user identifier
311+
-**OpenShift 4.19+ Compatible** - Full security contexts and RBAC
312+
-**Automated Triggers** - GitHub webhook integration for auto-deployment
313+
-**Persistent Storage** - Ollama model storage across deployments
314+
-**Security Hardened** - Non-root containers, minimal permissions
315+
-**Comprehensive Monitoring** - Full logging and status tracking
316+
-**Registry Integration** - Supports any container registry (Quay.io default)
317+
318+
### Quick Start:
319+
```bash
320+
# Navigate to tekton directory
321+
cd deploy/tekton
322+
323+
# Deploy all pipeline resources
324+
./deploy-pipeline.sh
325+
326+
# Create registry secret
327+
oc create secret docker-registry docker-registry-secret \
328+
--docker-server=quay.io \
329+
--docker-username=<your-username> \
330+
--docker-password=<your-password> \
331+
--docker-email=<your-email> \
332+
-n tekton-pipelines
333+
334+
# Deploy for user "alice"
335+
./deploy-user.sh alice https://github.com/alice/ci_analysis_agent.git feature/new-analysis alice
336+
337+
# Monitor progress
338+
tkn pipelinerun logs --last -f -n tekton-pipelines
339+
```
340+
341+
### Multi-User Deployment:
342+
The pipeline supports multiple users deploying to isolated namespaces. Each user gets their own:
343+
- **Namespace**: `ci-analysis-<username>`
344+
- **Resources**: Prefixed with username (e.g., `alice-ollama`, `bob-ci-analysis-agent`)
345+
- **Routes**: Individual URLs for each deployment
346+
- **Storage**: Isolated persistent volumes
347+
348+
### Automated Deployment:
349+
The pipeline supports GitHub webhooks for automatic deployment on code pushes from any repository. The webhook endpoint automatically creates user-specific deployments based on the repository owner.
350+
351+
The pipeline is production-ready and includes comprehensive error handling, security best practices, and detailed documentation. Perfect for development teams working on the same codebase with different features or environments.

deploy/tekton/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# CI Analysis Agent Tekton Pipeline (Multi-User)
2+
3+
This directory contains a comprehensive Tekton pipeline for building and deploying the CI Analysis Agent with Ollama on OpenShift, designed for **multiple users** on a single cluster.
4+
5+
## 🎯 Multi-User Pipeline Features
6+
7+
### **Key Changes Made:**
8+
1. **Parameterized git-url** - Now accepts any GitHub repository
9+
2. **Dynamic namespaces** - Each user deploys to `ci-analysis-<username>`
10+
3. **Resource prefixing** - All resources are prefixed with user identifier
11+
4. **Centralized pipeline** - Single pipeline definition supports all users
12+
5. **Automated user detection** - GitHub webhooks automatically create user-specific deployments
13+
14+
### **Multi-User Architecture:**
15+
- **Shared Resources**: Pipeline, tasks, RBAC, and secrets in `tekton-pipelines` namespace
16+
- **User Isolation**: Each user gets their own namespace with prefixed resources
17+
- **Automatic Deployment**: GitHub webhooks create deployments based on repository owner
18+
19+
### **Updated Files:**
20+
-**`pipeline.yaml`** - Added `target-namespace` and `user-prefix` parameters
21+
-**`tasks.yaml`** - Updated all tasks to use dynamic namespaces and prefixes
22+
-**`rbac.yaml`** - Moved to `tekton-pipelines` namespace for cluster-wide access
23+
-**`triggers.yaml`** - Auto-generates user deployments from GitHub webhooks
24+
-**`pipeline-run.yaml`** - Example deployment for "dev" user
25+
-**`user-examples.yaml`** - Multiple user deployment examples with script
26+
-**`deploy-pipeline.sh`** - Updated for multi-user setup
27+
-**`README.md`** - Comprehensive multi-user documentation
28+
29+
### **Usage Examples:**
30+
31+
```bash
32+
# Deploy for user "alice" from her fork
33+
./deploy-user.sh alice https://github.com/alice/ci_analysis_agent.git feature/new-analysis alice
34+
35+
# Deploy for user "bob" from his fork
36+
./deploy-user.sh bob https://github.com/bob/ci_analysis_agent.git dev/performance-improvements bob
37+
38+
# Deploy for QA team
39+
./deploy-user.sh qa https://github.com/jeffdyoung/ci_analysis_agent.git main qa-team
40+
```
41+
42+
### **Resource Isolation:**
43+
Each user gets their own:
44+
- **Namespace**: `ci-analysis-<username>`
45+
- **Ollama**: `<username>-ollama`
46+
- **Agent**: `<username>-ci-analysis-agent`
47+
- **Service**: `<username>-ci-analysis-service`
48+
- **Route**: `<username>-ci-analysis-agent`
49+
- **ConfigMap**: `<username>-ci-analysis-config`
50+
51+
### **GitHub Webhook Integration:**
52+
- Automatically detects repository owner as username
53+
- Creates deployments in `ci-analysis-<owner>` namespace
54+
- Supports `main`, `feature/*`, and `dev/*` branches
55+
- Generates unique image tags per user
56+
57+
The pipeline is now **production-ready for multi-user development teams** with complete isolation, security, and automation! 🚀

deploy/tekton/deploy-pipeline.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m' # No Color
10+
11+
echo -e "${GREEN}🚀 Deploying CI Analysis Agent Tekton Pipeline${NC}"
12+
13+
# Check if user is logged in to OpenShift
14+
if ! oc whoami &> /dev/null; then
15+
echo -e "${RED}❌ Not logged in to OpenShift. Please run 'oc login' first.${NC}"
16+
exit 1
17+
fi
18+
19+
# Check if Tekton is installed
20+
if ! oc get crd pipelines.tekton.dev &> /dev/null; then
21+
echo -e "${RED}❌ Tekton Pipelines not found. Please install Tekton first.${NC}"
22+
echo -e "${YELLOW}You can install it with: oc apply -f https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml${NC}"
23+
exit 1
24+
fi
25+
26+
# Check if Tekton Triggers is installed
27+
if ! oc get crd eventlisteners.triggers.tekton.dev &> /dev/null; then
28+
echo -e "${YELLOW}⚠️ Tekton Triggers not found. Installing...${NC}"
29+
oc apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
30+
oc apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml
31+
fi
32+
33+
# Function to check if a resource exists
34+
resource_exists() {
35+
oc get $1 $2 -n $3 &> /dev/null
36+
}
37+
38+
# Create tekton-pipelines namespace if it doesn't exist
39+
echo -e "${GREEN}📦 Creating tekton-pipelines namespace...${NC}"
40+
if ! resource_exists namespace tekton-pipelines ""; then
41+
oc create namespace tekton-pipelines
42+
else
43+
echo -e "${YELLOW}Namespace 'tekton-pipelines' already exists${NC}"
44+
fi
45+
46+
# Apply RBAC
47+
echo -e "${GREEN}🔐 Applying RBAC...${NC}"
48+
oc apply -f rbac.yaml
49+
50+
# Apply Tasks
51+
echo -e "${GREEN}📝 Applying Tasks...${NC}"
52+
oc apply -f tasks.yaml
53+
54+
# Apply Pipeline
55+
echo -e "${GREEN}🔄 Applying Pipeline...${NC}"
56+
oc apply -f pipeline.yaml
57+
58+
# Apply Triggers (optional)
59+
echo -e "${GREEN}⚡ Applying Triggers...${NC}"
60+
oc apply -f triggers.yaml
61+
62+
# Check if docker registry secret exists
63+
if ! resource_exists secret docker-registry-secret tekton-pipelines; then
64+
echo -e "${YELLOW}⚠️ Docker registry secret not found.${NC}"
65+
echo -e "${YELLOW}Please create it with:${NC}"
66+
echo -e "${YELLOW}kubectl create secret docker-registry docker-registry-secret \\${NC}"
67+
echo -e "${YELLOW} --docker-server=quay.io \\${NC}"
68+
echo -e "${YELLOW} --docker-username=<your-username> \\${NC}"
69+
echo -e "${YELLOW} --docker-password=<your-password> \\${NC}"
70+
echo -e "${YELLOW} --docker-email=<your-email> \\${NC}"
71+
echo -e "${YELLOW} -n tekton-pipelines${NC}"
72+
fi
73+
74+
# Check if GitHub webhook secret exists
75+
if ! resource_exists secret github-webhook-secret tekton-pipelines; then
76+
echo -e "${YELLOW}⚠️ GitHub webhook secret not found.${NC}"
77+
echo -e "${YELLOW}Please update the secret in triggers.yaml with your actual webhook secret.${NC}"
78+
fi
79+
80+
echo -e "${GREEN}✅ Pipeline deployment completed!${NC}"
81+
echo -e "${GREEN}🎯 Next steps:${NC}"
82+
echo -e "1. Create docker registry secret (if not already done)"
83+
echo -e "2. Update GitHub webhook secret in triggers.yaml"
84+
echo -e "3. Run the pipeline with: oc apply -f pipeline-run.yaml"
85+
echo -e "4. Monitor the pipeline with: tkn pipelinerun logs --last -f -n tekton-pipelines"
86+
echo -e "5. Each user will deploy to their own namespace: ci-analysis-<username>"
87+
88+
# Get webhook URL if triggers are deployed
89+
if resource_exists route ci-analysis-agent-webhook tekton-pipelines; then
90+
WEBHOOK_URL=$(oc get route ci-analysis-agent-webhook -n tekton-pipelines -o jsonpath='{.spec.host}')
91+
echo -e "${GREEN}🔗 Webhook URL: https://${WEBHOOK_URL}${NC}"
92+
echo -e "Configure this URL in your GitHub repository webhooks"
93+
fi

deploy/tekton/pipeline-run.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: PipelineRun
3+
metadata:
4+
generateName: ci-analysis-agent-pipeline-run-
5+
namespace: tekton-pipelines
6+
spec:
7+
serviceAccountName: pipeline-service-account
8+
pipelineRef:
9+
name: ci-analysis-agent-pipeline
10+
params:
11+
- name: git-url
12+
value: https://github.com/jeffdyoung/ci_analysis_agent.git
13+
- name: git-revision
14+
value: main
15+
- name: target-namespace
16+
value: ci-analysis-dev
17+
- name: user-prefix
18+
value: dev
19+
- name: image-registry
20+
value: quay.io
21+
- name: image-namespace
22+
value: jdyoung
23+
- name: image-name
24+
value: ci-analysis-agent
25+
- name: image-tag
26+
value: latest
27+
workspaces:
28+
- name: shared-data
29+
volumeClaimTemplate:
30+
spec:
31+
accessModes:
32+
- ReadWriteOnce
33+
resources:
34+
requests:
35+
storage: 10Gi
36+
- name: docker-credentials
37+
secret:
38+
secretName: docker-registry-secret
39+
timeout: 3600s
40+
41+
---
42+
apiVersion: v1
43+
kind: Secret
44+
metadata:
45+
name: docker-registry-secret
46+
namespace: tekton-pipelines
47+
type: kubernetes.io/dockerconfigjson
48+
data:
49+
.dockerconfigjson: # Base64 encoded docker config
50+
# Example: eyJhdXRocyI6eyJxdWF5LmlvIjp7ImF1dGgiOiJiV0Y0YUdWdmNYODZjR0Z6YzNkdmNtUT0ifX19
51+
# This should be replaced with actual registry credentials
52+
53+
---
54+
# Example of how to create the docker registry secret
55+
# kubectl create secret docker-registry docker-registry-secret \
56+
# --docker-server=quay.io \
57+
# --docker-username=<your-username> \
58+
# --docker-password=<your-password> \
59+
# --docker-email=<your-email> \
60+
# -n tekton-pipelines

0 commit comments

Comments
 (0)