Skip to content
bidirektPublic

cli

CI Coverage Release License Go

bidirekt is the command line for the Bidirekt broker. In Bidirekt, each side of an integration declares in a contract file what it provides and what it consumes. The CLI publishes these contracts to the broker, asks it with can-i-deploy whether a version can be deployed to an environment without breaking a consumer or a provider deployed there, and records each deployment. The broker compares the contracts, so no service has to be running for the check.

Install

curl -sSfL https://raw.githubusercontent.com/bidirekt/cli/main/install.sh | sh

Each release is also on https://github.com/bidirekt/cli/releases, as one archive per system.

The CLI also ships as the Docker image ghcr.io/bidirekt/cli.

All install options: https://bidirekt.com/docs/start/install/

Quickstart

Sign in to your broker with an API key, then create the environment and the participant once:

bidirekt login
bidirekt create-environment production
bidirekt create-participant petstore_web

For every version, publish its contract files, ask whether it can be deployed, deploy it, and record the deployment. A contract file is YAML (.yaml, .yml) or the schema of a GraphQL provider (.graphql, .graphqls, .gql). With no file given, bidirekt publish and bidirekt validate send every contract file in the contracts/ folder here, subfolders included. A folder passed by name must also be named contracts, like api/contracts, and files can be passed by name beside it, like bidirekt publish contracts/ src/schema.graphql:

bidirekt publish --participant petstore_web --version 2.3.0
bidirekt can-i-deploy petstore_web --version 2.3.0 --environment production
# deploy petstore_web 2.3.0 to production
bidirekt record-deployment petstore_web --version 2.3.0 --environment production

Development

Read CONTRIBUTING.md before opening an issue or a pull request.

Setup

git config core.hooksPath .githooks

The pre-push hook runs the Go gates of CI (gofmt, go vet, golangci-lint, go-arch-lint, go test, govulncheck) before every push.

E2E tests

The end-to-end suite in tests/e2e runs the CLI against the broker pinned in tests/e2e/compose.yaml. It needs Docker, bats, bats-support, bats-assert and gettext (for envsubst).

On macOS, Homebrew installs bats and gettext but has no bats-support or bats-assert, so clone those at the versions CI uses into one folder and point BATS_LIB_PATH at it:

brew install bats-core gettext
git clone --depth 1 -b v0.3.0 https://github.com/bats-core/bats-support "$HOME/.local/lib/bats/bats-support"
git clone --depth 1 -b v2.1.0 https://github.com/bats-core/bats-assert "$HOME/.local/lib/bats/bats-assert"
export BATS_LIB_PATH="$HOME/.local/lib/bats"

The suite runs the bidirekt it finds on PATH and never builds it. Build the working tree into the repository root, where /bidirekt is gitignored, and put the root first on PATH:

go build -o bidirekt ./cmd/bidirekt
export PATH="$PWD:$PATH"

Start the broker and its Postgres, then run the suite:

docker compose -f tests/e2e/compose.yaml up -d --wait
BIDIREKT_BROKER_URL=http://localhost:8080 bats tests/e2e

Before the first test, the suite checks that the broker at BIDIREKT_BROKER_URL is the version pinned in tests/e2e/compose.yaml, and runs no test if it isn't.

Each run uses its own participant and environment names, so running the suite again against the same broker passes. docker compose -f tests/e2e/compose.yaml down stops both containers and throws the data away (Postgres keeps it on tmpfs).

License

Apache License 2.0 — use it, ship it, embed it in your pipelines freely.

The broker it talks to is source-available under BSL 1.1; see https://github.com/bidirekt/broker for its terms.

Releases

Packages

Contributors

Languages