From fa2dcd8814e1cc8bb8fa5e3284af1441944bdb12 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 25 Nov 2026 19:23:27 +1000 Subject: [PATCH 1/5] feat(cumulocity): attach a c8y-tenant-sync bundle to each release Add cumulocity/tenant-sync.yaml, a c8y-tenant-sync manifest with the DTM parameter sets and the Smart Functions, and a release job which bundles it with its files as tiny-edge-tenant-sync_.tar.gz. A tenant's manifest can include the bundle from the release, or run it as it is. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-please.yml | 28 ++++++++++++++++++++++++++++ cumulocity/README.md | 27 +++++++++++++++++++++++++++ cumulocity/tenant-sync.yaml | 18 ++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 cumulocity/tenant-sync.yaml diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index f2f281c..d7fe79e 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -85,6 +85,34 @@ jobs: cumulocity/smart-functions/package.sh dist gh release upload "$TAG" dist/*.tar.gz --clobber + # The tenant setup (DTM parameter sets and Smart Functions) as one + # c8y-tenant-sync bundle, which a tenant's manifest includes from the + # release or which "c8y tenant-sync run" applies as it is. + tenant-sync-bundle: + name: tenant-sync bundle + needs: release-please + if: needs.release-please.outputs.released == 'true' + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.release-please.outputs.tag }} + - uses: reubenmiller/setup-go-c8y-cli@main + with: + showVersion: false + showTenant: false + extensions: reubenmiller/c8y-tenant-sync@v0.11.1 + - name: Bundle and attach + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ needs.release-please.outputs.tag }} + run: | + bundle="tiny-edge-tenant-sync_${TAG#v}.tar.gz" + c8y tenant-sync bundle cumulocity/tenant-sync.yaml -o "$bundle" + gh release upload "$TAG" "$bundle" --clobber + # One checksums file for all of tedge-onboard's archives, which # "c8y extensions install" uses to verify the download. It runs after # every build has attached its archives. diff --git a/cumulocity/README.md b/cumulocity/README.md index adba4a5..c107909 100644 --- a/cumulocity/README.md +++ b/cumulocity/README.md @@ -56,6 +56,33 @@ Measurements recover on their own because the device keeps sending them. `--no-smart-functions` and `--no-dtm` skip steps 2 and 3 (`--dtm-dir` sets are still registered). `--help` lists every option. +### With c8y-tenant-sync + +[c8y-tenant-sync](https://github.com/reubenmiller/c8y-tenant-sync) applies +steps 2 and 3 from `tenant-sync.yaml`. Each GitHub release (after 0.10.2) carries it as a +bundle, `tiny-edge-tenant-sync_.tar.gz`, which holds the manifest +with the DTM sets and the Smart Functions it deploys. Apply it as it is: + +```sh +c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/download/v/tiny-edge-tenant-sync_.tar.gz --dry +``` + +or include it in the tenant's own manifest, pinned to the release its +devices run: + +```yaml +include: + - github: + repo: thin-edge/tiny-edge + release: v # or latest + assets: ["tiny-edge-tenant-sync_*.tar.gz"] +``` + +The `assets` pattern is needed: the release carries other `.tar.gz` files. +The bundle does not enable the tenant features of step 1; declare them in +the tenant's manifest (`features`). From a checkout, +`c8y tenant-sync run -f cumulocity/tenant-sync.yaml --dry` applies the same. + ## Smart Functions Each directory is a Data Preparation rule package: `data-prep.yaml` (the diff --git a/cumulocity/tenant-sync.yaml b/cumulocity/tenant-sync.yaml new file mode 100644 index 0000000..eba1e35 --- /dev/null +++ b/cumulocity/tenant-sync.yaml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# What a Cumulocity tenant needs for tiny-edge devices, as a c8y-tenant-sync +# manifest (https://github.com/reubenmiller/c8y-tenant-sync): the DTM +# parameter sets and the Smart Functions. Each release carries it as a +# bundle, tiny-edge-tenant-sync_.tar.gz, with the files it uses. +# The tenant features it needs (mqtt-service.smartrest, +# certificate-authority) are left to the tenant's own manifest; see +# cumulocity/README.md. + +digitalTwin: + propertyDefinitions: + - source: + path: ./dtm + +smartFunctions: + - source: + path: ./smart-functions From 039d2ba03a76330c3362b6760f18ea346c935e42 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 25 Nov 2026 19:28:37 +1000 Subject: [PATCH 2/5] docs(cumulocity): set up a tenant with c8y-tenant-sync Lead the tenant setup with a tenant manifest which enables the features and includes the release bundle. setup-tenant.sh and dtm/register.sh stay as the way without the extension. Co-Authored-By: Claude Opus 5.5 --- cumulocity/README.md | 124 ++++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 50 deletions(-) diff --git a/cumulocity/README.md b/cumulocity/README.md index c107909..205f546 100644 --- a/cumulocity/README.md +++ b/cumulocity/README.md @@ -17,33 +17,68 @@ parameters, shell) need no mapping. ## Set up a tenant -With a go-c8y-cli session for the tenant (`set-session`), one command does -everything below: +[c8y-tenant-sync](https://github.com/reubenmiller/c8y-tenant-sync), a +go-c8y-cli extension, sets up a tenant from a manifest. tiny-edge's part is +`tenant-sync.yaml`: the DTM parameter sets and every Smart Function. Each +GitHub release (after 0.10.2) carries it as a bundle, +`tiny-edge-tenant-sync_.tar.gz`, with the files it uses. + +Install the extension once: ```sh -cumulocity/setup-tenant.sh --dry-run # what it would change; changes nothing -cumulocity/setup-tenant.sh +c8y extensions install reubenmiller/c8y-tenant-sync ``` -It prints the host it is about to change, then: +Then write the tenant's own manifest. It enables the tenant features the +devices need and includes the bundle of the release the devices run: -1. Checks that the tenant features `mqtt-service.smartrest` and - `certificate-authority` are active, and stops if one is not, naming the - command that enables it (`c8y features enable --key `). - `--enable-features` enables them instead. Without - `mqtt-service.smartrest` the MQTT Service drops a device as soon as it - subscribes to `devicecontrol/notifications`; the device logs -113. -2. Deploys every Smart Function under `smart-functions/`, and reports each - rule's HTTP status. Any status other than 200 fails the script. -3. Registers the DTM parameter sets with `dtm/register.sh`. A set that is - already there is left alone; `--replace` re-registers it. +```yaml +# tenant.yaml +features: + # Without it the MQTT Service drops a device as soon as it subscribes to + # devicecontrol/notifications; the device logs -113. + - key: mqtt-service.smartrest + - key: certificate-authority -An application registers its own parameter sets with `--dtm-dir`, alone or -with the rest: +include: + - github: + repo: thin-edge/tiny-edge + release: v # the tiny-edge release; or latest + assets: ["tiny-edge-tenant-sync_*.tar.gz"] +``` + +The `assets` pattern is needed: the release also carries the per-rule +`.tar.gz` packages. With a go-c8y-cli session for the tenant +(`set-session`), apply it: + +```sh +c8y tenant-sync run -f tenant.yaml --dry # what it would change; changes nothing +c8y tenant-sync run -f tenant.yaml +``` + +It enables a feature that is not active, deploys a Smart Function whose code, +configuration or tests differ from the deployed rule, and creates or updates a +DTM definition that differs from its file. Anything already in place is left +alone, so the run can be repeated, and it fails when an item fails. + +To apply only tiny-edge's part, without the features, run the bundle as it is: ```sh -path/to/tiny-edge/cumulocity/setup-tenant.sh --dtm-dir cumulocity/dtm -path/to/tiny-edge/cumulocity/dtm/register.sh --dir cumulocity/dtm # only the application's sets +c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/download/v/tiny-edge-tenant-sync_.tar.gz --dry +``` + +From a checkout, include the manifest instead of the bundle +(`- path: path/to/tiny-edge/cumulocity/tenant-sync.yaml`), or run it with +`c8y tenant-sync run -f cumulocity/tenant-sync.yaml`. `--only smartFunctions` +or `--only digitalTwin` applies one part. + +An application adds its own parameter sets to the same manifest: + +```yaml +digitalTwin: + propertyDefinitions: + - source: + path: ./cumulocity/dtm # every *.json in it ``` Set up the tenant before devices connect, or reconnect them afterwards @@ -53,46 +88,31 @@ connection. Without the twin Smart Function those messages are dropped, so a device that connected first shows no Parameters tab until it reconnects. Measurements recover on their own because the device keeps sending them. -`--no-smart-functions` and `--no-dtm` skip steps 2 and 3 (`--dtm-dir` sets -are still registered). `--help` lists every option. - -### With c8y-tenant-sync +### Without c8y-tenant-sync -[c8y-tenant-sync](https://github.com/reubenmiller/c8y-tenant-sync) applies -steps 2 and 3 from `tenant-sync.yaml`. Each GitHub release (after 0.10.2) carries it as a -bundle, `tiny-edge-tenant-sync_.tar.gz`, which holds the manifest -with the DTM sets and the Smart Functions it deploys. Apply it as it is: +`setup-tenant.sh` does the same with go-c8y-cli, curl and python3: ```sh -c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/download/v/tiny-edge-tenant-sync_.tar.gz --dry -``` - -or include it in the tenant's own manifest, pinned to the release its -devices run: - -```yaml -include: - - github: - repo: thin-edge/tiny-edge - release: v # or latest - assets: ["tiny-edge-tenant-sync_*.tar.gz"] +cumulocity/setup-tenant.sh --dry-run # what it would change; changes nothing +cumulocity/setup-tenant.sh ``` -The `assets` pattern is needed: the release carries other `.tar.gz` files. -The bundle does not enable the tenant features of step 1; declare them in -the tenant's manifest (`features`). From a checkout, -`c8y tenant-sync run -f cumulocity/tenant-sync.yaml --dry` applies the same. +It checks the tenant features and stops when one is not active +(`--enable-features` enables it instead), deploys every Smart Function, and +registers the DTM sets with `dtm/register.sh`. A set that is already there is +left alone; `--replace` re-registers it. An application registers its own +sets with `--dtm-dir cumulocity/dtm`. `--help` lists every option. ## Smart Functions Each directory is a Data Preparation rule package: `data-prep.yaml` (the -topic pattern), the JavaScript, and `tests/*.yaml`. `setup-tenant.sh` -deploys all of them. Each GitHub release also carries one -`.tar.gz` per Smart Function, which you can import in the Data -Preparation UI or deploy as it is. `smart-functions/package.sh ` -builds the same archives from a checkout. +topic pattern), the JavaScript, and `tests/*.yaml`. The manifest deploys all +of them. Each GitHub release also carries one `.tar.gz` per Smart +Function, which you can import in the Data Preparation UI. +`smart-functions/package.sh ` builds the same archives from a +checkout. -To deploy one package by hand, send it as the raw request body: +To deploy a package without either tool, send it as the raw request body: ```sh cumulocity/smart-functions/package.sh /tmp/rules @@ -158,6 +178,10 @@ client writes both fragments itself. The tenant needs the `dtm` and `device-parameter` microservices, and the user registering needs `ROLE_DIGITAL_TWIN_DEFINITIONS_CREATE` and `_ADMIN`. +The manifest registers the sets in `dtm/`, and updates a definition when its +file changes, so after a declaration changed, regenerate the file and run it +again. Without c8y-tenant-sync, `dtm/register.sh` registers them: + ```sh cumulocity/dtm/register.sh # registers every set not yet there cumulocity/dtm/register.sh --replace zephyr_modbus_telemetry # after a declaration changed @@ -231,7 +255,7 @@ them needs these changes once its devices run a newer release: `tedge-zephyr-*` ones. They take the same topics, so with both deployed every message is stored twice. - **Parameters tab:** register `tiny_edge` and `tiny_edge_remote_access` - (`cumulocity/dtm/register.sh`). Keep the `zephyr_tedge` definitions while + (the manifest does, see "Set up a tenant"). Keep the `zephyr_tedge` definitions while devices on older releases remain. - **Old fragments:** an updated device writes `tiny_edge` and `tiny_edge_remote_access`, and leaves the old `zephyr_tedge` fragments on From 6a24a2f0c92f90d75bbffbcd5cb16d58f5e08cc8 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 25 Nov 2026 19:32:42 +1000 Subject: [PATCH 3/5] refactor(cumulocity): drop setup-tenant.sh and dtm/register.sh c8y-tenant-sync now sets up a tenant from cumulocity/tenant-sync.yaml, so the scripts which did the same are no longer needed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-please.yml | 2 +- cumulocity/README.md | 27 +---- cumulocity/dtm/register.sh | 86 ---------------- cumulocity/setup-tenant.sh | 145 --------------------------- 4 files changed, 4 insertions(+), 256 deletions(-) delete mode 100755 cumulocity/dtm/register.sh delete mode 100755 cumulocity/setup-tenant.sh diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index d7fe79e..140b9fb 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -65,7 +65,7 @@ jobs: gh release upload "$TAG" tools/onboard/dist/* --clobber # One Data Preparation package per Smart Function, which the Data - # Preparation UI imports and cumulocity/setup-tenant.sh deploys. + # Preparation UI imports. smart-functions: name: Smart Function packages needs: release-please diff --git a/cumulocity/README.md b/cumulocity/README.md index 205f546..9166c7d 100644 --- a/cumulocity/README.md +++ b/cumulocity/README.md @@ -88,21 +88,6 @@ connection. Without the twin Smart Function those messages are dropped, so a device that connected first shows no Parameters tab until it reconnects. Measurements recover on their own because the device keeps sending them. -### Without c8y-tenant-sync - -`setup-tenant.sh` does the same with go-c8y-cli, curl and python3: - -```sh -cumulocity/setup-tenant.sh --dry-run # what it would change; changes nothing -cumulocity/setup-tenant.sh -``` - -It checks the tenant features and stops when one is not active -(`--enable-features` enables it instead), deploys every Smart Function, and -registers the DTM sets with `dtm/register.sh`. A set that is already there is -left alone; `--replace` re-registers it. An application registers its own -sets with `--dtm-dir cumulocity/dtm`. `--help` lists every option. - ## Smart Functions Each directory is a Data Preparation rule package: `data-prep.yaml` (the @@ -112,7 +97,7 @@ Function, which you can import in the Data Preparation UI. `smart-functions/package.sh ` builds the same archives from a checkout. -To deploy a package without either tool, send it as the raw request body: +To deploy a package without c8y-tenant-sync, send it as the raw request body: ```sh cumulocity/smart-functions/package.sh /tmp/rules @@ -179,14 +164,8 @@ The tenant needs the `dtm` and `device-parameter` microservices, and the user registering needs `ROLE_DIGITAL_TWIN_DEFINITIONS_CREATE` and `_ADMIN`. The manifest registers the sets in `dtm/`, and updates a definition when its -file changes, so after a declaration changed, regenerate the file and run it -again. Without c8y-tenant-sync, `dtm/register.sh` registers them: - -```sh -cumulocity/dtm/register.sh # registers every set not yet there -cumulocity/dtm/register.sh --replace zephyr_modbus_telemetry # after a declaration changed -cumulocity/dtm/register.sh --dry-run # what it would register; changes nothing -``` +file changes: after a declaration changed, regenerate the file and run the +manifest again. | Identifier | Declared by | Parameters | |---|---|---| diff --git a/cumulocity/dtm/register.sh b/cumulocity/dtm/register.sh deleted file mode 100755 index 7c09ae4..0000000 --- a/cumulocity/dtm/register.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: Apache-2.0 -# -# Register the client's own parameter sets in a tenant's Digital Twin -# Manager, so the device's Parameters tab can show and edit them. -# -# cumulocity/dtm/register.sh [--replace] [--dry-run] [--dir ] [set...] -# -# Without sets it registers every *.json in (default: this directory), -# so an application can register its own sets with this script: -# path/to/tiny-edge/cumulocity/dtm/register.sh --dir cumulocity/dtm -# -# Needs a go-c8y-cli session, the dtm and device-parameter microservices, and -# ROLE_DIGITAL_TWIN_DEFINITIONS_CREATE/_ADMIN. An identifier that already -# exists is left alone; --replace deletes and re-registers it (DTM cannot -# update one in place). --dry-run only reads the tenant and says what it -# would do. The files were printed by the firmware itself -# (`tedge params schema `, CONFIG_TEDGE_PARAMETERS_SCHEMA), so they match -# what the devices validate against; regenerate them when a declaration changes. -set -euo pipefail -dir=$(dirname "$0") -replace=0 -dry=0 -failed=0 -while [[ $# -gt 0 ]]; do - case $1 in - --replace) replace=1 ;; - --dry-run) dry=1 ;; - --dir) dir=${2:?--dir needs a directory}; shift ;; - -h | --help) sed -n '3,19s/^# \{0,1\}//p' "$0"; exit 0 ;; - -*) echo "unknown option: $1" >&2; exit 2 ;; - *) break ;; - esac - shift -done -cd "$dir" -sets=("$@") -if [[ ${#sets[@]} -eq 0 ]]; then - for f in *.json; do - [[ -f $f ]] && sets+=("${f%.json}") - done -fi -if [[ ${#sets[@]} -eq 0 ]]; then - echo "no *.json definitions in $(pwd)" >&2 - exit 1 -fi -# The listing is paged whatever pageSize asks for (a tenant with ~20 -# definitions returned them over several pages), so read every page: a check -# that saw only the first made --replace skip the delete and the POST fail. -exists() { - local page=1 found - while :; do - found=$(c8y api GET "/service/dtm/definitions/properties?pageSize=100¤tPage=$page" --raw < /dev/null | - python3 -c 'import json,sys; d=json.load(sys.stdin); d=d.get("definitions", []) if isinstance(d, dict) else d; print("yes" if any(i.get("identifier")==sys.argv[1] for i in d) else ("end" if not d else "no"))' "$1") - case $found in - yes) return 0 ;; - end) return 1 ;; - esac - page=$((page + 1)) - done -} -for s in "${sets[@]}"; do - if exists "$s"; then - if [[ $replace -eq 0 ]]; then - echo "exists: $s (use --replace to re-register)" - continue - fi - if [[ $dry -eq 1 ]]; then - echo "would replace: $s" - continue - fi - c8y api DELETE "/service/dtm/definitions/properties/$s?contexts=asset,event,operation" --force < /dev/null >/dev/null - echo "deleted: $s" - elif [[ $dry -eq 1 ]]; then - echo "would register: $s" - continue - fi - if out=$(c8y api POST /service/dtm/definitions/properties --data "$(cat "$s.json")" --force --raw < /dev/null 2>&1); then - echo "registered: $s" - else - # DTM refuses a duplicate identifier *or* title (HTTP 409). - echo "failed: $s: $out" >&2 - failed=1 - fi -done -exit $failed diff --git a/cumulocity/setup-tenant.sh b/cumulocity/setup-tenant.sh deleted file mode 100755 index f68fc31..0000000 --- a/cumulocity/setup-tenant.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: Apache-2.0 -# -# Set up the Cumulocity tenant of the active go-c8y-cli session for tiny-edge -# devices, in one go: -# -# 1. check the tenant features the devices need (mqtt-service.smartrest, -# certificate-authority); -# 2. deploy every Smart Function under cumulocity/smart-functions/; -# 3. register the DTM parameter sets (cumulocity/dtm/register.sh). -# -# cumulocity/setup-tenant.sh [options] -# -# Options: -# --dry-run read the tenant and say what would change; change nothing -# --enable-features enable a missing tenant feature instead of stopping -# --replace re-register DTM sets that already exist -# --dtm-dir also register the *.json sets in (repeatable), -# e.g. an application's own cumulocity/dtm -# --no-smart-functions skip step 2 -# --no-dtm skip tiny-edge's own DTM sets (--dtm-dir still runs) -# -# Start a session first (set-session), which sets C8Y_HOST and C8Y_HEADER. -set -euo pipefail -here=$(cd "$(dirname "$0")" && pwd) - -dry=0 -enable=0 -replace=() -deploy_rules=1 -own_dtm=1 -dtm_dirs=() -while [[ $# -gt 0 ]]; do - case $1 in - --dry-run) dry=1 ;; - --enable-features) enable=1 ;; - --replace) replace=(--replace) ;; - --dtm-dir) dtm_dirs+=("$(cd "${2:?--dtm-dir needs a directory}" && pwd)"); shift ;; - --no-smart-functions) deploy_rules=0 ;; - --no-dtm) own_dtm=0 ;; - -h | --help) sed -n '3,24s/^# \{0,1\}//p' "$0"; exit 0 ;; - *) echo "unknown option: $1 (see --help)" >&2; exit 2 ;; - esac - shift -done -[[ $own_dtm -eq 1 ]] && dtm_dirs=("$here/dtm" "${dtm_dirs[@]+"${dtm_dirs[@]}"}") -[[ $dry -eq 1 ]] && dtm_flags=(--dry-run) || dtm_flags=() - -# --- session -------------------------------------------------------------- -# c8y reads stdin when it is not a terminal, so every call gets < /dev/null -# or a script hangs. -if [[ -z ${C8Y_HOST:-} || -z ${C8Y_HEADER:-} ]]; then - echo "No go-c8y-cli session: run set-session (it sets C8Y_HOST and C8Y_HEADER), then run this again." >&2 - exit 1 -fi -host=${C8Y_HOST%/} -[[ $host == *://* ]] || host="https://$host" -tenant=$(c8y currenttenant get --select name --output csv < /dev/null) || { - echo "The go-c8y-cli session for $host does not work (c8y currenttenant get failed)." >&2 - exit 1 -} -if [[ $dry -eq 1 ]]; then - echo "Dry run against $host (tenant $tenant): nothing will be changed." -else - echo "Setting up $host (tenant $tenant) for tiny-edge." -fi - -# --- 1. tenant features ----------------------------------------------------- -# Without mqtt-service.smartrest the MQTT Service drops a device as soon as -# it subscribes to devicecontrol/notifications (the device logs -113). -feature_active() { - c8y features get --key "$1" --raw < /dev/null 2>/dev/null | - python3 -c 'import json,sys; print("yes" if json.load(sys.stdin).get("active") else "no")' 2>/dev/null || - echo no -} -missing=0 -for f in mqtt-service.smartrest certificate-authority; do - if [[ $(feature_active "$f") == yes ]]; then - echo "feature $f: active" - elif [[ $enable -eq 1 && $dry -eq 0 ]]; then - if c8y features enable --key "$f" --force < /dev/null >/dev/null; then - echo "feature $f: enabled" - else - echo "feature $f: could not enable it; ask whoever manages the tenant to enable it." >&2 - missing=1 - fi - elif [[ $enable -eq 1 ]]; then - echo "feature $f: not active, would enable it" - else - echo "feature $f: not active. Enable it with: c8y features enable --key $f" >&2 - missing=1 - fi -done -if [[ $missing -eq 1 ]]; then - if [[ $dry -eq 1 ]]; then - echo "(a real run stops here; pass --enable-features to have the script enable them)" >&2 - else - echo "Stopping: enable the features above, or run again with --enable-features." >&2 - exit 1 - fi -fi - -failed=0 - -# --- 2. Smart Functions ----------------------------------------------------- -# The package has to be the raw request body: `c8y api --file` always sends -# multipart, which the service answers with 400 "Failed to read request -# body". So curl it, with C8Y_HEADER (the whole "Authorization: ..." line). -if [[ $deploy_rules -eq 1 ]]; then - work=$(mktemp -d) - trap 'rm -rf "$work"' EXIT - pkgs=$("$here/smart-functions/package.sh" "$work") - while read -r pkg; do - name=$(basename "$pkg" .tar.gz) - url="$host/service/dataprep/v1/rules/$name/deployed" - if [[ $dry -eq 1 ]]; then - echo "smart function $name: would PUT $(wc -c < "$pkg" | tr -d ' ') bytes to $url" - continue - fi - status=$(curl -sS -o "$work/$name.out" -w '%{http_code}' -X PUT \ - -H "$C8Y_HEADER" -H "Content-Type: application/gzip" \ - --data-binary "@$pkg" "$url") || status=000 # curl printed why - if [[ $status == 200 ]]; then - echo "smart function $name: deployed (HTTP 200)" - else - echo "smart function $name: HTTP $status: $(head -c 500 "$work/$name.out" 2>/dev/null)" >&2 - failed=1 - fi - done <<< "$pkgs" -fi - -# --- 3. DTM parameter sets ---------------------------------------------------- -for d in "${dtm_dirs[@]+"${dtm_dirs[@]}"}"; do - echo "DTM sets in $d:" - "$here/dtm/register.sh" "${replace[@]+"${replace[@]}"}" "${dtm_flags[@]+"${dtm_flags[@]}"}" --dir "$d" || failed=1 -done - -if [[ $failed -eq 1 ]]; then - echo "Done, with failures (see above)." >&2 - exit 1 -fi -echo "Done." -if [[ $deploy_rules -eq 1 && $dry -eq 0 ]]; then - echo "Devices that were already connected send their twin fragments again only when they reconnect: restart them to get the Parameters tab." -fi From 32f16b9164b1db7e8000c2e81c0afe0f6cbbb6eb Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 25 Nov 2026 19:36:46 +1000 Subject: [PATCH 4/5] feat(cumulocity): attach a standalone tenant manifest to each release cumulocity/tenant.yaml enables the tenant features and includes the tenant-sync bundle of its own release. release-please pins that release in each release PR, and the release job attaches the file as tiny-edge-tenant.yaml, so one URL sets up a tenant: c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-please.yml | 16 ++++-- cumulocity/README.md | 79 ++++++++++++---------------- cumulocity/tenant.yaml | 24 +++++++++ release-please-config.json | 3 +- 4 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 cumulocity/tenant.yaml diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 140b9fb..0cc25c6 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -85,9 +85,10 @@ jobs: cumulocity/smart-functions/package.sh dist gh release upload "$TAG" dist/*.tar.gz --clobber - # The tenant setup (DTM parameter sets and Smart Functions) as one - # c8y-tenant-sync bundle, which a tenant's manifest includes from the - # release or which "c8y tenant-sync run" applies as it is. + # The tenant setup for c8y-tenant-sync: a bundle with the DTM parameter + # sets and Smart Functions, and tiny-edge-tenant.yaml, which enables the + # tenant features and includes that bundle. "c8y tenant-sync run" applies + # either from the release, or a tenant's manifest includes it. tenant-sync-bundle: name: tenant-sync bundle needs: release-please @@ -111,7 +112,14 @@ jobs: run: | bundle="tiny-edge-tenant-sync_${TAG#v}.tar.gz" c8y tenant-sync bundle cumulocity/tenant-sync.yaml -o "$bundle" - gh release upload "$TAG" "$bundle" --clobber + # The standalone manifest includes the bundle of its own release; + # release-please pins it in the release PR. + grep -q "release: $TAG " cumulocity/tenant.yaml || { + echo "cumulocity/tenant.yaml does not include the bundle of $TAG" >&2 + exit 1 + } + cp cumulocity/tenant.yaml tiny-edge-tenant.yaml + gh release upload "$TAG" "$bundle" tiny-edge-tenant.yaml --clobber # One checksums file for all of tedge-onboard's archives, which # "c8y extensions install" uses to verify the download. It runs after diff --git a/cumulocity/README.md b/cumulocity/README.md index 9166c7d..94fedfb 100644 --- a/cumulocity/README.md +++ b/cumulocity/README.md @@ -18,68 +18,55 @@ parameters, shell) need no mapping. ## Set up a tenant [c8y-tenant-sync](https://github.com/reubenmiller/c8y-tenant-sync), a -go-c8y-cli extension, sets up a tenant from a manifest. tiny-edge's part is -`tenant-sync.yaml`: the DTM parameter sets and every Smart Function. Each -GitHub release (after 0.10.2) carries it as a bundle, -`tiny-edge-tenant-sync_.tar.gz`, with the files it uses. +go-c8y-cli extension, sets up a tenant from a manifest. Each GitHub release +(after 0.10.2) carries two: -Install the extension once: +| Asset | What it is | +|---|---| +| `tiny-edge-tenant.yaml` | The whole setup: enables the tenant features `mqtt-service.smartrest` and `certificate-authority`, and includes the bundle of the same release ([tenant.yaml](tenant.yaml)) | +| `tiny-edge-tenant-sync_.tar.gz` | The bundle: the DTM parameter sets and every Smart Function ([tenant-sync.yaml](tenant-sync.yaml) with the files it uses) | + +Install the extension once, then, with a go-c8y-cli session for the tenant +(`set-session`), apply the latest release: ```sh c8y extensions install reubenmiller/c8y-tenant-sync +c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml --dry # what it would change; changes nothing +c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml ``` -Then write the tenant's own manifest. It enables the tenant features the -devices need and includes the bundle of the release the devices run: +Without `mqtt-service.smartrest` the MQTT Service drops a device as soon as +it subscribes to `devicecontrol/notifications`; the device logs -113. + +The run enables a feature that is not active, deploys a Smart Function whose +code, configuration or tests differ from the deployed rule, and creates or +updates a DTM definition that differs from its file. Anything already in +place is left alone, so the run can be repeated, and it fails when an item +fails. `--only smartFunctions` or `--only digitalTwin` applies one part. + +To keep the tenant on the release its devices run, include that release's +manifest from the tenant's own manifest. An application adds its own +parameter sets there too: ```yaml # tenant.yaml -features: - # Without it the MQTT Service drops a device as soon as it subscribes to - # devicecontrol/notifications; the device logs -113. - - key: mqtt-service.smartrest - - key: certificate-authority - include: - - github: - repo: thin-edge/tiny-edge - release: v # the tiny-edge release; or latest - assets: ["tiny-edge-tenant-sync_*.tar.gz"] -``` - -The `assets` pattern is needed: the release also carries the per-rule -`.tar.gz` packages. With a go-c8y-cli session for the tenant -(`set-session`), apply it: + - https://github.com/thin-edge/tiny-edge/releases/download/v/tiny-edge-tenant.yaml -```sh -c8y tenant-sync run -f tenant.yaml --dry # what it would change; changes nothing -c8y tenant-sync run -f tenant.yaml +digitalTwin: + propertyDefinitions: + - source: + path: ./cumulocity/dtm # the application's sets: every *.json in it ``` -It enables a feature that is not active, deploys a Smart Function whose code, -configuration or tests differ from the deployed rule, and creates or updates a -DTM definition that differs from its file. Anything already in place is left -alone, so the run can be repeated, and it fails when an item fails. - -To apply only tiny-edge's part, without the features, run the bundle as it is: - ```sh -c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/download/v/tiny-edge-tenant-sync_.tar.gz --dry +c8y tenant-sync run -f tenant.yaml --dry ``` -From a checkout, include the manifest instead of the bundle -(`- path: path/to/tiny-edge/cumulocity/tenant-sync.yaml`), or run it with -`c8y tenant-sync run -f cumulocity/tenant-sync.yaml`. `--only smartFunctions` -or `--only digitalTwin` applies one part. - -An application adds its own parameter sets to the same manifest: - -```yaml -digitalTwin: - propertyDefinitions: - - source: - path: ./cumulocity/dtm # every *.json in it -``` +To leave the features to whoever manages the tenant, include or run only the +bundle (`tiny-edge-tenant-sync_.tar.gz`) instead. From a checkout, +`c8y tenant-sync run -f cumulocity/tenant-sync.yaml` applies the DTM sets and +Smart Functions of the checkout. Set up the tenant before devices connect, or reconnect them afterwards (a restart is enough). A device sends its twin fragments (`c8y_Agent`, diff --git a/cumulocity/tenant.yaml b/cumulocity/tenant.yaml new file mode 100644 index 0000000..e32213b --- /dev/null +++ b/cumulocity/tenant.yaml @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Everything a Cumulocity tenant needs for tiny-edge devices, as one +# c8y-tenant-sync manifest (https://github.com/reubenmiller/c8y-tenant-sync): +# the tenant features, plus the bundle of this release with the DTM +# parameter sets and the Smart Functions (tenant-sync.yaml). Each release +# carries it as tiny-edge-tenant.yaml: +# +# c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml --dry +# +# release-please updates the version below in every release PR, so the file +# always includes the bundle of the release it belongs to. + +features: + # Without it the MQTT Service drops a device as soon as it subscribes to + # devicecontrol/notifications; the device logs -113. + - key: mqtt-service.smartrest + - key: certificate-authority + +include: + - github: + repo: thin-edge/tiny-edge + release: v0.10.2 # x-release-please-version + assets: ["tiny-edge-tenant-sync_*.tar.gz"] diff --git a/release-please-config.json b/release-please-config.json index c7e81b0..c7e3ca5 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -19,7 +19,8 @@ ], "packages": { ".": { - "version-file": "VERSION" + "version-file": "VERSION", + "extra-files": ["cumulocity/tenant.yaml"] } } } From 4b789f6f25699bfd686937ca4bbf122e41d1047c Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Wed, 25 Nov 2026 19:49:59 +1000 Subject: [PATCH 5/5] feat(cumulocity): one tenant manifest with its dependencies Merge tenant-sync.yaml into cumulocity/tenant.yaml, which now also declares the dependencies: the data-prep.ui-visibility feature, the mqtt-service, data-prep-ctrl, dtm and device-parameter microservices, and the Data Preparation and Digital Twin Manager applications. Each release carries it as tiny-edge-tenant.tar.gz, with no version in the name, so releases/latest/download/tiny-edge-tenant.tar.gz always works. The standalone tiny-edge-tenant.yaml and its release-please pin are no longer needed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-please.yml | 24 ++++------- cumulocity/README.md | 59 ++++++++++++++++------------ cumulocity/tenant-sync.yaml | 18 --------- cumulocity/tenant.yaml | 45 +++++++++++++++------ release-please-config.json | 3 +- 5 files changed, 75 insertions(+), 74 deletions(-) delete mode 100644 cumulocity/tenant-sync.yaml diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 0cc25c6..a728113 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -85,12 +85,12 @@ jobs: cumulocity/smart-functions/package.sh dist gh release upload "$TAG" dist/*.tar.gz --clobber - # The tenant setup for c8y-tenant-sync: a bundle with the DTM parameter - # sets and Smart Functions, and tiny-edge-tenant.yaml, which enables the - # tenant features and includes that bundle. "c8y tenant-sync run" applies - # either from the release, or a tenant's manifest includes it. - tenant-sync-bundle: - name: tenant-sync bundle + # The tenant setup as a c8y-tenant-sync bundle: cumulocity/tenant.yaml with + # the DTM parameter sets and Smart Functions it deploys. It has no version + # in its name, so releases/latest/download/tiny-edge-tenant.tar.gz always + # gives the latest. + tenant-bundle: + name: Tenant bundle needs: release-please if: needs.release-please.outputs.released == 'true' runs-on: ubuntu-24.04 @@ -110,16 +110,8 @@ jobs: GH_TOKEN: ${{ github.token }} TAG: ${{ needs.release-please.outputs.tag }} run: | - bundle="tiny-edge-tenant-sync_${TAG#v}.tar.gz" - c8y tenant-sync bundle cumulocity/tenant-sync.yaml -o "$bundle" - # The standalone manifest includes the bundle of its own release; - # release-please pins it in the release PR. - grep -q "release: $TAG " cumulocity/tenant.yaml || { - echo "cumulocity/tenant.yaml does not include the bundle of $TAG" >&2 - exit 1 - } - cp cumulocity/tenant.yaml tiny-edge-tenant.yaml - gh release upload "$TAG" "$bundle" tiny-edge-tenant.yaml --clobber + c8y tenant-sync bundle cumulocity/tenant.yaml -o tiny-edge-tenant.tar.gz + gh release upload "$TAG" tiny-edge-tenant.tar.gz --clobber # One checksums file for all of tedge-onboard's archives, which # "c8y extensions install" uses to verify the download. It runs after diff --git a/cumulocity/README.md b/cumulocity/README.md index 94fedfb..1a9da6c 100644 --- a/cumulocity/README.md +++ b/cumulocity/README.md @@ -18,40 +18,54 @@ parameters, shell) need no mapping. ## Set up a tenant [c8y-tenant-sync](https://github.com/reubenmiller/c8y-tenant-sync), a -go-c8y-cli extension, sets up a tenant from a manifest. Each GitHub release -(after 0.10.2) carries two: +go-c8y-cli extension, sets up a tenant from [tenant.yaml](tenant.yaml). It +declares everything the devices need: -| Asset | What it is | +| Section | What it sets up | |---|---| -| `tiny-edge-tenant.yaml` | The whole setup: enables the tenant features `mqtt-service.smartrest` and `certificate-authority`, and includes the bundle of the same release ([tenant.yaml](tenant.yaml)) | -| `tiny-edge-tenant-sync_.tar.gz` | The bundle: the DTM parameter sets and every Smart Function ([tenant-sync.yaml](tenant-sync.yaml) with the files it uses) | +| `features` | `mqtt-service.smartrest`, `certificate-authority`, and `data-prep.ui-visibility`, which shows the Data Preparation application | +| `microservices` | `mqtt-service`, `data-prep-ctrl` (Smart Functions), `dtm` and `device-parameter` (Parameters tab) | +| `applications` | Data Preparation and Digital Twin Manager | +| `digitalTwin` | the DTM parameter sets in `dtm/` | +| `smartFunctions` | every Smart Function in `smart-functions/` | -Install the extension once, then, with a go-c8y-cli session for the tenant -(`set-session`), apply the latest release: +Without `mqtt-service.smartrest` the MQTT Service drops a device as soon as +it subscribes to `devicecontrol/notifications`; the device logs -113. + +Each GitHub release (after 0.10.2) carries the manifest and its files as a +bundle, `tiny-edge-tenant.tar.gz`. Install the extension once, then, with a +go-c8y-cli session for the tenant (`set-session`), apply the latest release: ```sh c8y extensions install reubenmiller/c8y-tenant-sync -c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml --dry # what it would change; changes nothing -c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml +c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.tar.gz --dry # what it would change; changes nothing +c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.tar.gz ``` -Without `mqtt-service.smartrest` the MQTT Service drops a device as soon as -it subscribes to `devicecontrol/notifications`; the device logs -113. +From a checkout, `c8y tenant-sync run --dry` in this directory applies the +checkout's `tenant.yaml`. -The run enables a feature that is not active, deploys a Smart Function whose -code, configuration or tests differ from the deployed rule, and creates or -updates a DTM definition that differs from its file. Anything already in -place is left alone, so the run can be repeated, and it fails when an item -fails. `--only smartFunctions` or `--only digitalTwin` applies one part. +The run enables a feature that is not active, subscribes a missing +application, deploys a Smart Function whose code, configuration or tests +differ from the deployed rule, and creates or updates a DTM definition that +differs from its file. Anything already in place is left alone, so the run +can be repeated, and it fails when an item fails. The applications are owned +by the `management` tenant: a tenant which may not subscribe them itself +reports them as skipped, and its parent tenant (or the Cumulocity provider) +subscribes them. `--only digitalTwin,smartFunctions` applies only the DTM +sets and the Smart Functions. To keep the tenant on the release its devices run, include that release's -manifest from the tenant's own manifest. An application adds its own +bundle from the tenant's own manifest. An application adds its own parameter sets there too: ```yaml # tenant.yaml include: - - https://github.com/thin-edge/tiny-edge/releases/download/v/tiny-edge-tenant.yaml + - github: + repo: thin-edge/tiny-edge + release: v # or latest + assets: ["tiny-edge-tenant.tar.gz"] digitalTwin: propertyDefinitions: @@ -63,11 +77,6 @@ digitalTwin: c8y tenant-sync run -f tenant.yaml --dry ``` -To leave the features to whoever manages the tenant, include or run only the -bundle (`tiny-edge-tenant-sync_.tar.gz`) instead. From a checkout, -`c8y tenant-sync run -f cumulocity/tenant-sync.yaml` applies the DTM sets and -Smart Functions of the checkout. - Set up the tenant before devices connect, or reconnect them afterwards (a restart is enough). A device sends its twin fragments (`c8y_Agent`, `c8y_Hardware`, `remoteAccess` and every parameter set) once per @@ -147,8 +156,8 @@ client writes both fragments itself. ## Parameters tab (DTM) -The tenant needs the `dtm` and `device-parameter` microservices, and the -user registering needs `ROLE_DIGITAL_TWIN_DEFINITIONS_CREATE` and `_ADMIN`. +The tenant needs the `dtm` and `device-parameter` microservices (the +manifest subscribes them), and the user registering needs `ROLE_DIGITAL_TWIN_DEFINITIONS_CREATE` and `_ADMIN`. The manifest registers the sets in `dtm/`, and updates a definition when its file changes: after a declaration changed, regenerate the file and run the diff --git a/cumulocity/tenant-sync.yaml b/cumulocity/tenant-sync.yaml deleted file mode 100644 index eba1e35..0000000 --- a/cumulocity/tenant-sync.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# -# What a Cumulocity tenant needs for tiny-edge devices, as a c8y-tenant-sync -# manifest (https://github.com/reubenmiller/c8y-tenant-sync): the DTM -# parameter sets and the Smart Functions. Each release carries it as a -# bundle, tiny-edge-tenant-sync_.tar.gz, with the files it uses. -# The tenant features it needs (mqtt-service.smartrest, -# certificate-authority) are left to the tenant's own manifest; see -# cumulocity/README.md. - -digitalTwin: - propertyDefinitions: - - source: - path: ./dtm - -smartFunctions: - - source: - path: ./smart-functions diff --git a/cumulocity/tenant.yaml b/cumulocity/tenant.yaml index e32213b..fbb384e 100644 --- a/cumulocity/tenant.yaml +++ b/cumulocity/tenant.yaml @@ -1,24 +1,43 @@ # SPDX-License-Identifier: Apache-2.0 # -# Everything a Cumulocity tenant needs for tiny-edge devices, as one -# c8y-tenant-sync manifest (https://github.com/reubenmiller/c8y-tenant-sync): -# the tenant features, plus the bundle of this release with the DTM -# parameter sets and the Smart Functions (tenant-sync.yaml). Each release -# carries it as tiny-edge-tenant.yaml: +# Everything a Cumulocity tenant needs for tiny-edge devices, as a +# c8y-tenant-sync manifest (https://github.com/reubenmiller/c8y-tenant-sync). +# Each release carries it, with the files it uses, as the bundle +# tiny-edge-tenant.tar.gz: # -# c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.yaml --dry +# c8y tenant-sync run https://github.com/thin-edge/tiny-edge/releases/latest/download/tiny-edge-tenant.tar.gz --dry # -# release-please updates the version below in every release PR, so the file -# always includes the bundle of the release it belongs to. +# The applications are owned by the management tenant. A tenant which may not +# subscribe them itself reports them as skipped; its parent tenant (or the +# Cumulocity provider) subscribes them. features: # Without it the MQTT Service drops a device as soon as it subscribes to # devicecontrol/notifications; the device logs -113. - key: mqtt-service.smartrest + # Devices get their certificate from the tenant's CA. - key: certificate-authority + # Shows the Data Preparation application. + - key: data-prep.ui-visibility -include: - - github: - repo: thin-edge/tiny-edge - release: v0.10.2 # x-release-please-version - assets: ["tiny-edge-tenant-sync_*.tar.gz"] +microservices: + - name: mqtt-service # the devices' connection + - name: data-prep-ctrl # runs the Smart Functions + - name: dtm # Digital Twin Manager definitions + - name: device-parameter # the Parameters tab + +applications: + - name: Data Preparation + - name: digital-twin-manager + +# The client's own parameter sets, for the Parameters tab +digitalTwin: + propertyDefinitions: + - source: + path: ./dtm + +# The Smart Functions which map the te/ topics to measurements, events and +# managed-object fragments +smartFunctions: + - source: + path: ./smart-functions diff --git a/release-please-config.json b/release-please-config.json index c7e3ca5..c7e81b0 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -19,8 +19,7 @@ ], "packages": { ".": { - "version-file": "VERSION", - "extra-files": ["cumulocity/tenant.yaml"] + "version-file": "VERSION" } } }