diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1a60add --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.DS_Store +/.git/ +/Dockerfile +/LICENSE +/README.md +/docker-compose.yaml +/integration/data/reference/ diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e69193c..8413d33 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -33,5 +33,5 @@ jobs: docker compose build --build-arg TENZIR_VERSION=${{ matrix.version }} - name: Test run: | - docker compose run tests + docker compose run --build tests git diff --exit-code diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/example/CMakeLists.txt b/CMakeLists.txt similarity index 100% rename from example/CMakeLists.txt rename to CMakeLists.txt diff --git a/Dockerfile b/Dockerfile index 9c40725..7cf4778 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ ARG TENZIR_VERSION=main -FROM ghcr.io/tenzir/tenzir-dev:${TENZIR_VERSION} AS example-builder-untested +FROM ghcr.io/tenzir/tenzir-dev:${TENZIR_VERSION} AS example-builder -COPY example /plugins/example +COPY . /plugins/example/ RUN cmake -S /plugins/example -B build-example -G Ninja -D CMAKE_INSTALL_PREFIX:STRING="$PREFIX" RUN cmake --build build-example --parallel RUN cmake --install build-example --strip --component Runtime --prefix /plugin/example -FROM example-builder-untested AS example-test +FROM example-builder AS example-test ENV BATS_LIB_PATH=/tmp/tenzir/tenzir/integration/lib # TODO: Use the update-integration target instead @@ -15,11 +15,6 @@ ENV UPDATE=1 ENTRYPOINT cmake --build build-example --target integration -FROM example-builder-untested AS example-builder - -ENV BATS_LIB_PATH=/tmp/tenzir/tenzir/integration/lib -RUN cmake --build build-example --target integration - FROM ghcr.io/tenzir/tenzir:${TENZIR_VERSION} COPY --from=example-builder --chown=tenzir:tenzir /plugin/example /opt/tenzir diff --git a/README.md b/README.md index f4d2919..553c34c 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,42 @@ # Tenzir Example Plugin -This is an example plugin for Tenzir. Simply run `docker compose up` to build -and start a Tenzir node with your additional plugin. Use `docker compose run -tenzir ''` to interact with the node, or set the following -environment variables and to connect your node to app.tenzir.com: +This is an example plugin for Tenzir. + +## Build and run + +Simply run `docker compose up` to build and start a Tenzir node with your +additional plugin. + +Use `docker compose run tenzir ''` to interact with the node. Set the +following environment variables and to connect your node to app.tenzir.com: ``` export TENZIR_PLUGINS__PLATFORM__API_KEY='' export TENZIR_PLUGINS__PLATFORM__TENANT_ID='' ``` -## Write Tests +## Learn how to write a plugin + +We think that learning how to build a plugin is best done by example. Tenzir +ships with a variety of [plugins][plugins-source] and +[builtins][builtins-source] to get inspired by and to learn from. + +If you have any questions, feel free to reach out in the [#developers channel +on Discord][discord]. + +## Run tests Every plugin defines additional tests using [BATS](https://bats-core.readthedocs.io/en/stable/writing-tests.html). Use -`docker compose run tests` to execute your tests and update the reference files -automatically. +`docker compose run --build tests` to execute your tests and update the +reference files automatically. + +## Contribute your plugin + +If you want to upstream your plugin so that it is bundled with every Tenzir +installation, open a PR that adds it to the [`plugins/` directory in the +`tenzir/tenzir` repository][plugins-source]. + +[plugins-source]: https://github.com/tenzir/tenzir/tree/main/plugins +[builtins-source]: https://github.com/tenzir/tenzir/tree/main/libtenzir/builtins +[discord]: https://docs.tenzir.com/discord diff --git a/docker-compose.yaml b/docker-compose.yaml index a03436c..c4400a6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -47,7 +47,7 @@ services: profiles: - donotstart volumes: - - ./example/integration/data/reference/:/plugins/example/integration/data/reference/ + - ./integration/data/reference/:/plugins/example/integration/data/reference/ volumes: tenzir-node: diff --git a/example/integration/data/reference/tests/test_check_plugin_availability/step_00.ref b/example/integration/data/reference/tests/test_check_plugin_availability/step_00.ref deleted file mode 100644 index 6941e06..0000000 --- a/example/integration/data/reference/tests/test_check_plugin_availability/step_00.ref +++ /dev/null @@ -1 +0,0 @@ -{"name": "example", "version": "bundled", "kind": "dynamic", "types": ["operator"], "dependencies": []} \ No newline at end of file diff --git a/integration/data/reference/tests/test_check_plugin_availability/step_00.ref b/integration/data/reference/tests/test_check_plugin_availability/step_00.ref new file mode 100644 index 0000000..c8bc7a0 --- /dev/null +++ b/integration/data/reference/tests/test_check_plugin_availability/step_00.ref @@ -0,0 +1 @@ +{"name": "example", "types": ["operator"], "dependencies": []} \ No newline at end of file diff --git a/example/integration/tests/setup_suite.bash b/integration/tests/setup_suite.bash similarity index 100% rename from example/integration/tests/setup_suite.bash rename to integration/tests/setup_suite.bash diff --git a/example/integration/tests/tests.bats b/integration/tests/tests.bats similarity index 78% rename from example/integration/tests/tests.bats rename to integration/tests/tests.bats index 1d7c0b2..45469d3 100644 --- a/example/integration/tests/tests.bats +++ b/integration/tests/tests.bats @@ -15,5 +15,5 @@ teardown() { } @test "Check plugin availability" { - check tenzir 'show plugins | where name == "example"' + check tenzir 'show plugins | where name == "example" | drop version, kind' } diff --git a/example/src/plugin.cpp b/src/plugin.cpp similarity index 100% rename from example/src/plugin.cpp rename to src/plugin.cpp