The demo runs the petstore example on your machine. A provider, petstore_api, changes its contract in a way that breaks petstore_web, the consumer deployed in production. can-i-deploy catches the break, the contract is fixed, and the next version can be deployed. It needs Docker with Docker Compose, nothing else:
$ curl -sL bidirekt.com/demo | shThe script checks for docker and docker compose, asks where to put the example (./petstore-example by default; without a terminal it takes the default), downloads the current version of https://github.com/bidirekt/petstore-example β there and runs its demo.sh. A folder that already holds the example is replaced by the current version. Any other folder that exists stops it with <folder> exists and is not the petstore example; pick another folder., and nothing in it changes.
The six steps#
Each step starts with a title, Step N of 6 β <what happens>, and each command is typed before it runs. The example's ./bidirekt runs the CLI in a container next to the broker, so every command it runs first prints Broker: http://broker:8080 (from BIDIREKT_BROKER_URL).
- Start the broker: removes what an earlier run left, starts Postgres and the broker with
docker compose up -d --wait, and pulls the CLI image. - Set up what is in production: creates the
productionenvironment and the participantspetstore_apiandpetstore_web, publishes version1.0.0of each fromdeployed/, and records both as deployed toproduction. - Publish the proposed change: publishes
contracts/petstore_api.yamlaspetstore_api2.0.0. ItsPetschema no longer hasstatus. - Check it:
can-i-deploysays2.0.0cannot be deployed, becausepetstore_webreadsPet.status. - Fix the contract: adds
statusback toPet, publishes3.0.0and checks it again, and this time it can be deployed. - Clean up:
docker compose down -vremoves the containers and the data, andcontracts/petstore_api.yamlgoes back to the proposed change, so the demo can run again.
The break#
Step 4 checks 2.0.0 against what is deployed in production:
$ ./bidirekt can-i-deploy petstore_api --version 2.0.0 --environment production Broker: http://broker:8080 (from BIDIREKT_BROKER_URL) petstore_api 2.0.0 cannot be deployed to production petstore_web (1.0.0, deployed): Pet.status β petstore_api doesn't provide it, but petstore_web reads it β petstore_api: provide it β petstore_web: stop reading it, or handle its absence in the code and mark it optional there Β· GET /pets/* response 200 at "$.status" (petstore_web: Pet.status) The proposed change breaks petstore_web, which is deployed in production.
The report names the counterpart it breaks, petstore_web with the version deployed in production, the property, the fix on each side, and where petstore_web reads it. can-i-deploy explains every line of it.
The fix#
Step 5 draws the edit on the screen, so you don't need vim, and writes the two lines of status under Pet:
$ vim contracts/petstore_api.yaml 13 schemas: 14 Pet: 15 type: object 16 properties: 17 petId: 18 type: integer 19 name: 20 type: string 21 status: 22 type: string 23 weight: 24 type: float :wq
Then it publishes the fixed contract as 3.0.0 and checks it:
$ ./bidirekt publish contracts/petstore_api.yaml --participant petstore_api --version 3.0.0 Broker: http://broker:8080 (from BIDIREKT_BROKER_URL) petstore_api contract publish successful $ ./bidirekt can-i-deploy petstore_api --version 3.0.0 --environment production Broker: http://broker:8080 (from BIDIREKT_BROKER_URL) petstore_api 3.0.0 can be deployed to production compared with: petstore_web
The demo ends with docker compose down -v.
From a clone#
The same demo runs from a clone of the example:
$ git clone https://github.com/bidirekt/petstore-example $ cd petstore-example && ./demo.sh
Next#
To set up Bidirekt in your own project, run Try on your project:
$ curl -sL bidirekt.com/try | sh