Skip to content

Commit 02f7b72

Browse files
committed
feature: new task to run camel routes via camel jbang
1 parent 656d451 commit 02f7b72

File tree

6 files changed

+509
-0
lines changed

6 files changed

+509
-0
lines changed

task/camel-run/0.1/README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Camel run
2+
3+
This Task runs [Apache Camel](https://camel.apache.org/) integrations using [Camel JBang](https://camel.apache.org/manual/camel-jbang.html).
4+
5+
Camel JBang is a lightweight tool for running Camel routes without requiring complex setup or operators. It supports multiple runtimes (Camel Main, Spring Boot, Quarkus) and provides features like live reload, developer console, and observability.
6+
7+
## Install the Task
8+
9+
```shell
10+
kubectl apply -f https://github.com/tektoncd/catalog/raw/main/task/camel-run/0.1/camel-run.yaml
11+
```
12+
13+
## Prerequisites
14+
15+
When using this task in a pipeline with `git-clone` task (as shown in the samples), you need to install the git-clone task first, if it is not already available:
16+
17+
```shell
18+
kubectl apply -f https://github.com/tektoncd/catalog/raw/main/task/git-clone/0.10/git-clone.yaml
19+
```
20+
21+
## Parameters
22+
23+
- **camel-jbang-image**: The name of the image containing the Camel JBang CLI (_default:_ docker.io/apache/camel-jbang:4.17.0). For production use, consider using a digest reference like `docker.io/apache/camel-jbang@sha256:7979e8c9e25d6ff136372f60ad7be74af3e1cee2e279d95b666bdae40d3b64e4`
24+
- **filename**: The Camel file(s) to run. Multiple files separated by space (_default:_ empty, will use application.properties). _Format:_ `"file1.yaml file2.yaml"` or `"route.yaml"`
25+
- **runtime**: Runtime to use. Valid values: `camel-main`, `spring-boot`, `quarkus` (_default:_ camel-main).
26+
- **dependencies**: Additional dependencies to add. Comma-separated list (_default:_ empty). _Format:_ `"org.apache.camel:camel-http,org.apache.camel:camel-jackson"`
27+
- **properties**: Comma separated list of properties files (_default:_ empty). _Format:_ `"application.properties,custom.properties"`
28+
- **property**: Additional properties in key=value format. Multiple properties separated by space (_default:_ empty). _Format:_ `"key1=value1 key2=value2"`
29+
- **port**: Port for embedded HTTP server. Use 0 for dynamic port, -1 to disable (_default:_ "-1").
30+
- **max-seconds**: Maximum seconds to run before stopping. Use 0 for unlimited (_default:_ "0").
31+
- **logging-level**: Logging level: ERROR, WARN, INFO, DEBUG, or TRACE (_default:_ info).
32+
- **dev**: Enable dev mode with live reload when source files are updated (_default:_ "false").
33+
- **console**: Enable developer console at /q/dev (_default:_ "false").
34+
- **observe**: Enable observability services including health and metrics endpoints (_default:_ "false").
35+
- **extra-args**: Additional arguments to pass to camel run command (_default:_ empty).
36+
- **output-log**: Path to save camel run output log. If empty, no log file will be generated (_default:_ "$(workspaces.source.path)/camel-run.log").
37+
38+
## Workspaces
39+
40+
* **source**: A [Workspace](https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md) containing the Camel source files to run.
41+
42+
## Results
43+
44+
- **exit-code**: The exit code from the camel run command.
45+
46+
## Platforms
47+
48+
The Task can be run on `linux/amd64` platform.
49+
50+
## Security
51+
52+
This task runs as a non-root user (UID 1000) for security. The task uses environment variables to pass parameters to the script, preventing script injection vulnerabilities.
53+
54+
## Usage
55+
56+
### Basic Usage
57+
58+
Run a simple Camel route:
59+
60+
```yaml
61+
apiVersion: tekton.dev/v1beta1
62+
kind: TaskRun
63+
metadata:
64+
name: camel-run-example
65+
spec:
66+
taskRef:
67+
name: camel-run
68+
params:
69+
- name: filename
70+
value: route.yaml
71+
workspaces:
72+
- name: source
73+
persistentVolumeClaim:
74+
claimName: camel-source-pvc
75+
```
76+
77+
### With Properties and Dependencies
78+
79+
Run a Camel route with external dependencies and properties:
80+
81+
```yaml
82+
apiVersion: tekton.dev/v1beta1
83+
kind: TaskRun
84+
metadata:
85+
name: camel-run-advanced
86+
spec:
87+
taskRef:
88+
name: camel-run
89+
params:
90+
- name: filename
91+
value: route.yaml
92+
- name: dependencies
93+
value: "org.apache.camel:camel-http,org.apache.camel:camel-opentelemetry2"
94+
- name: properties
95+
value: "application.properties"
96+
- name: property
97+
value: "camel.component.http.timeout=5000"
98+
- name: port
99+
value: "8080"
100+
- name: logging-level
101+
value: "DEBUG"
102+
workspaces:
103+
- name: source
104+
persistentVolumeClaim:
105+
claimName: camel-source-pvc
106+
```
107+
108+
### Dev Mode with Console
109+
110+
Run in development mode with live reload and developer console:
111+
112+
```yaml
113+
apiVersion: tekton.dev/v1beta1
114+
kind: TaskRun
115+
metadata:
116+
name: camel-run-dev
117+
spec:
118+
taskRef:
119+
name: camel-run
120+
params:
121+
- name: filename
122+
value: route.yaml
123+
- name: dev
124+
value: "true"
125+
- name: console
126+
value: "true"
127+
- name: port
128+
value: "8080"
129+
workspaces:
130+
- name: source
131+
persistentVolumeClaim:
132+
claimName: camel-source-pvc
133+
```
134+
135+
### Using Different Runtime
136+
137+
Run with Quarkus runtime:
138+
139+
```yaml
140+
apiVersion: tekton.dev/v1beta1
141+
kind: TaskRun
142+
metadata:
143+
name: camel-run-quarkus
144+
spec:
145+
taskRef:
146+
name: camel-run
147+
params:
148+
- name: filename
149+
value: route.yaml
150+
- name: runtime
151+
value: "quarkus"
152+
workspaces:
153+
- name: source
154+
persistentVolumeClaim:
155+
claimName: camel-source-pvc
156+
```
157+
158+
## Integration with Pipelines
159+
160+
Use the [sample pipeline](../0.1/samples/run-basic.yaml) as a reference for integrating camel-run into a complete CI/CD pipeline that fetches code from Git and runs the Camel integration.
161+
162+
### Circuit Breaker Example
163+
164+
The sample pipeline demonstrates running the [circuit-breaker example](https://github.com/apache/camel-jbang-examples/tree/main/circuit-breaker) from the Apache Camel JBang examples repository. This example shows how to use the Circuit Breaker Enterprise Integration Pattern (EIP) with Camel JBang. The pipeline:
165+
166+
1. Fetches the camel-jbang-examples repository using the git-clone task
167+
2. Runs the circuit-breaker route for 30 seconds
168+
3. Demonstrates how the circuit breaker state changes from closed to open when failures occur
169+
170+
The circuit-breaker example is ideal for demonstrating Camel's resilience patterns and can be monitored to observe state transitions during execution.
171+
172+
To run the sample pipeline:
173+
174+
```shell
175+
# Install required tasks
176+
kubectl apply -f https://github.com/tektoncd/catalog/raw/main/task/git-clone/0.10/git-clone.yaml
177+
kubectl apply -f https://github.com/tektoncd/catalog/raw/main/task/camel-run/0.1/camel-run.yaml
178+
179+
# Run the sample pipeline
180+
kubectl apply -f https://github.com/tektoncd/catalog/raw/main/task/camel-run/0.1/samples/run-basic.yaml
181+
```

task/camel-run/0.1/camel-run.yaml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: camel-run
5+
labels:
6+
app.kubernetes.io/version: "0.1"
7+
annotations:
8+
tekton.dev/categories: Deployment
9+
tekton.dev/pipelines.minVersion: "0.17.0"
10+
tekton.dev/tags: cli
11+
tekton.dev/platforms: "linux/amd64"
12+
tekton.dev/displayName: "camel run"
13+
spec:
14+
description: >-
15+
Run a Camel Integration using Camel JBang
16+
17+
Camel-run task executes Camel routes using Camel JBang, which provides a lightweight way to run Camel integrations
18+
without requiring any operator installation. This task supports running Camel routes with various runtimes
19+
(camel-main, spring-boot, quarkus) and configuration options.
20+
params:
21+
- name: camel-jbang-image
22+
description: The location of Camel JBang image.
23+
default: docker.io/apache/camel-jbang:4.17.0
24+
- name: filename
25+
description: |
26+
The Camel file(s) to run. Can be multiple files separated by space.
27+
Format: "file1.yaml file2.yaml" or "route.yaml"
28+
default: ""
29+
- name: runtime
30+
description: |
31+
Runtime to use. Valid values: camel-main, spring-boot, quarkus
32+
default: camel-main
33+
- name: dependencies
34+
description: |
35+
Additional dependencies to add. Comma-separated list.
36+
Format: "org.apache.camel:camel-http,org.apache.camel:camel-jackson"
37+
default: ""
38+
- name: properties
39+
description: |
40+
Comma separated list of properties files.
41+
Format: "application.properties,custom.properties"
42+
default: ""
43+
- name: property
44+
description: |
45+
Additional properties in key=value format. Multiple properties separated by space.
46+
Format: "key1=value1 key2=value2"
47+
default: ""
48+
- name: port
49+
description: Embeds a local HTTP server on this port (0 to dynamic assign, -1 to disable)
50+
default: "-1"
51+
- name: max-seconds
52+
description: Max seconds to run before stopping (0 for unlimited)
53+
default: "0"
54+
- name: logging-level
55+
description: Logging level (ERROR, WARN, INFO, DEBUG, TRACE)
56+
default: info
57+
- name: dev
58+
description: Enables dev mode (live reload when source files are updated)
59+
default: "false"
60+
- name: console
61+
description: Enable developer console at /q/dev
62+
default: "false"
63+
- name: observe
64+
description: Enable observability services (health, metrics)
65+
default: "false"
66+
- name: extra-args
67+
description: |
68+
Additional camel run arguments. Space-separated list.
69+
Format: "--flag1 value1 --flag2"
70+
default: ""
71+
- name: output-log
72+
description: |
73+
Path to save camel run output log. If empty, no log file will be generated.
74+
Format: Absolute or workspace-relative path
75+
default: "$(workspaces.source.path)/camel-run.log"
76+
results:
77+
- name: exit-code
78+
description: The exit code of the camel run command
79+
workspaces:
80+
- name: source
81+
steps:
82+
- name: execute
83+
image: $(params.camel-jbang-image)
84+
workingDir: $(workspaces.source.path)
85+
securityContext:
86+
runAsNonRoot: true
87+
runAsUser: 1000
88+
env:
89+
- name: PARAM_FILENAME
90+
value: $(params.filename)
91+
- name: PARAM_RUNTIME
92+
value: $(params.runtime)
93+
- name: PARAM_DEPENDENCIES
94+
value: $(params.dependencies)
95+
- name: PARAM_PROPERTIES
96+
value: $(params.properties)
97+
- name: PARAM_PROPERTY
98+
value: $(params.property)
99+
- name: PARAM_PORT
100+
value: $(params.port)
101+
- name: PARAM_MAX_SECONDS
102+
value: $(params.max-seconds)
103+
- name: PARAM_LOGGING_LEVEL
104+
value: $(params.logging-level)
105+
- name: PARAM_DEV
106+
value: $(params.dev)
107+
- name: PARAM_CONSOLE
108+
value: $(params.console)
109+
- name: PARAM_OBSERVE
110+
value: $(params.observe)
111+
- name: PARAM_EXTRA_ARGS
112+
value: $(params.extra-args)
113+
- name: PARAM_OUTPUT_LOG
114+
value: $(params.output-log)
115+
script: |
116+
#!/usr/bin/env bash
117+
set -e
118+
119+
CAMEL_RUN_ARGS=()
120+
121+
# Add files to run
122+
[[ ! "$PARAM_FILENAME" == "" ]] && CAMEL_RUN_ARGS+=("$PARAM_FILENAME")
123+
124+
# Add runtime
125+
[[ ! "$PARAM_RUNTIME" == "camel-main" ]] && CAMEL_RUN_ARGS+=(--runtime "$PARAM_RUNTIME")
126+
127+
# Add dependencies
128+
[[ ! "$PARAM_DEPENDENCIES" == "" ]] && CAMEL_RUN_ARGS+=(--dep "$PARAM_DEPENDENCIES")
129+
130+
# Add properties files
131+
[[ ! "$PARAM_PROPERTIES" == "" ]] && CAMEL_RUN_ARGS+=(--properties "$PARAM_PROPERTIES")
132+
133+
# Add individual properties
134+
if [[ ! "$PARAM_PROPERTY" == "" ]]; then
135+
for prop in $PARAM_PROPERTY; do
136+
CAMEL_RUN_ARGS+=(--prop "$prop")
137+
done
138+
fi
139+
140+
# Add port
141+
[[ ! "$PARAM_PORT" == "-1" ]] && CAMEL_RUN_ARGS+=(--port "$PARAM_PORT")
142+
143+
# Add max-seconds
144+
[[ ! "$PARAM_MAX_SECONDS" == "0" ]] && CAMEL_RUN_ARGS+=(--max-seconds "$PARAM_MAX_SECONDS")
145+
146+
# Add logging level
147+
CAMEL_RUN_ARGS+=(--logging-level "$PARAM_LOGGING_LEVEL")
148+
149+
# Add dev mode
150+
[[ "$PARAM_DEV" == "true" ]] && CAMEL_RUN_ARGS+=(--dev)
151+
152+
# Add console
153+
[[ "$PARAM_CONSOLE" == "true" ]] && CAMEL_RUN_ARGS+=(--console)
154+
155+
# Add observe
156+
[[ "$PARAM_OBSERVE" == "true" ]] && CAMEL_RUN_ARGS+=(--observe)
157+
158+
# Add extra args
159+
[[ ! "$PARAM_EXTRA_ARGS" == "" ]] && CAMEL_RUN_ARGS+=("$PARAM_EXTRA_ARGS")
160+
161+
echo "Running: camel run" "${CAMEL_RUN_ARGS[@]}"
162+
163+
# Execute camel run and conditionally capture output
164+
if [[ ! "$PARAM_OUTPUT_LOG" == "" ]]; then
165+
echo "Logging output to: $PARAM_OUTPUT_LOG"
166+
camel run "${CAMEL_RUN_ARGS[@]}" 2>&1 | tee "$PARAM_OUTPUT_LOG"
167+
exit_code=$?
168+
else
169+
camel run "${CAMEL_RUN_ARGS[@]}"
170+
exit_code=$?
171+
fi
172+
173+
echo "$exit_code" | tr -d '\n' | tee "$(results.exit-code.path)"
174+
exit $exit_code

0 commit comments

Comments
 (0)