|
| 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