Skip to content

Commit 10697b6

Browse files
committed
feat: add camel-run 0.1
1 parent 255f9d3 commit 10697b6

File tree

6 files changed

+520
-0
lines changed

6 files changed

+520
-0
lines changed

task/camel-run/0.1/README.md

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

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

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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-cli-image
22+
description: The Camel image to use.
23+
default: docker.io/apache/camel-jbang:4.18.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: ""
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-cli-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 -eo pipefail
118+
119+
CAMEL_RUN_ARGS=()
120+
121+
# Add files to run
122+
if [[ -n "$PARAM_FILENAME" ]]; then
123+
read -ra _files <<< "$PARAM_FILENAME"
124+
CAMEL_RUN_ARGS+=("${_files[@]}")
125+
fi
126+
127+
# Add runtime
128+
[[ ! "$PARAM_RUNTIME" == "camel-main" ]] && CAMEL_RUN_ARGS+=(--runtime "$PARAM_RUNTIME")
129+
130+
# Add dependencies
131+
[[ ! "$PARAM_DEPENDENCIES" == "" ]] && CAMEL_RUN_ARGS+=(--dep "$PARAM_DEPENDENCIES")
132+
133+
# Add properties files
134+
[[ ! "$PARAM_PROPERTIES" == "" ]] && CAMEL_RUN_ARGS+=(--properties "$PARAM_PROPERTIES")
135+
136+
# Add individual properties
137+
if [[ ! "$PARAM_PROPERTY" == "" ]]; then
138+
for prop in $PARAM_PROPERTY; do
139+
CAMEL_RUN_ARGS+=(--prop "$prop")
140+
done
141+
fi
142+
143+
# Add port
144+
[[ ! "$PARAM_PORT" == "-1" ]] && CAMEL_RUN_ARGS+=(--port "$PARAM_PORT")
145+
146+
# Add max-seconds
147+
[[ ! "$PARAM_MAX_SECONDS" == "0" ]] && CAMEL_RUN_ARGS+=(--max-seconds "$PARAM_MAX_SECONDS")
148+
149+
# Add logging level
150+
CAMEL_RUN_ARGS+=(--logging-level "$PARAM_LOGGING_LEVEL")
151+
152+
# Add dev mode
153+
[[ "$PARAM_DEV" == "true" ]] && CAMEL_RUN_ARGS+=(--dev)
154+
155+
# Add console
156+
[[ "$PARAM_CONSOLE" == "true" ]] && CAMEL_RUN_ARGS+=(--console)
157+
158+
# Add observe
159+
[[ "$PARAM_OBSERVE" == "true" ]] && CAMEL_RUN_ARGS+=(--observe)
160+
161+
# Add extra args
162+
if [[ -n "$PARAM_EXTRA_ARGS" ]]; then
163+
read -ra _extra <<< "$PARAM_EXTRA_ARGS"
164+
CAMEL_RUN_ARGS+=("${_extra[@]}")
165+
fi
166+
167+
echo "Running: camel run" "${CAMEL_RUN_ARGS[@]}"
168+
169+
# Execute camel run and conditionally capture output
170+
if [[ ! "$PARAM_OUTPUT_LOG" == "" ]]; then
171+
echo "Logging output to $PARAM_OUTPUT_LOG"
172+
camel run "${CAMEL_RUN_ARGS[@]}" 2>&1 | tee "$PARAM_OUTPUT_LOG"
173+
exit_code=$?
174+
else
175+
camel run "${CAMEL_RUN_ARGS[@]}"
176+
exit_code=$?
177+
fi
178+
179+
echo "$exit_code" | tr -d '\n' | tee "$(results.exit-code.path)"
180+
exit $exit_code

0 commit comments

Comments
 (0)