From 4a0b7323c2417c9bb445df6f71ad3ca059d48ab2 Mon Sep 17 00:00:00 2001 From: Pavan Date: Thu, 20 Mar 2025 10:49:16 +0000 Subject: [PATCH] add docker compose setup and readme --- .gitignore | 4 ++++ README.md | 48 +++++++++++++++++++++++++++++++++++++++++----- docker-compose.yml | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index a6cd62a0..03dc8db8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,14 @@ .idea *.iml +# OSX +.DS_Store + # NodeJS node_modules dist package-lock.json +yarn.lock # Java .gradle diff --git a/README.md b/README.md index 6cffbc9b..27aa26f2 100644 --- a/README.md +++ b/README.md @@ -115,13 +115,51 @@ This is also the perfect place for sharing your feedback with us, learning more ## Running the examples -Some examples are just illustrations of code, but many are runnable. Their READMEs explain -how to get them running. Here are the general steps: +### Using docker compose -### (1) Starting the Restate Server +Easiest way to bring up and test an endpoint is using the docker compose setup. + +- First install docker engine from [here](https://docs.docker.com/engine/install/). +- Next, from the root of the repo, run + +``` +docker compose up -d +``` +This will bring up +- restate server +- [typescript example-0](typescript/basics/src/0_durable_execution.ts) +- register the endpoint /service with restate + +You can test the endpoint by calling + +``` +curl --request POST \ + --url http://127.0.0.1:8080/SubscriptionService/add \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json' \ + --header 'idempotency-key: some-key-for-idempotentcy' \ + --data '{ + "userId": "Sam Beckett", + "creditCard": "1234-5678-9012-3456", + "subscriptions" : ["Netflix", "Disney+", "HBO Max"] +}' + +``` + +You can check that it succeeded by visiting http://localhost:9070/ui/invocations?service=SubscriptionService + +Now you can register additional endpoints onto restate. + +Some examples are just illustrations of code, but many are runnable. Their READMEs explain how to get them running. Here are the general steps: + +### + +### (1) Optional - Starting the Restate Server + +To run an example locally, you need a running Restate Server instance. + +You can skip this step if you have the docker compose setup, shown above, having started the restate server. -To run an example locally, you need a running Restate Server instance. -Some examples can be run with Docker Compose. Those already bring their own Restate server instance. To install the Restate Server and CLI, have a look at the [installation instructions in the documentation](https://docs.restate.dev/develop/local_dev#running-restate-server--cli-locally). diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..5a0325f5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +services: + endpoint: + image: node:22.14 + working_dir: /endpoint + ports: + - "9080:9080" + volumes: + - ./:/endpoint/examples + command: + - /bin/bash + - -c + - | + cd examples/typescript/basics + npm install + npm run example-0 # or 2, 3 + healthcheck: + test: curl --http2-prior-knowledge http://localhost:9080 || exit 1 + interval: 5s + retries: 10 + start_period: 5s + timeout: 10s + restate: + image: docker.io/restatedev/restate:latest + pull_policy: always + ports: + - 8080:8080 + - 9070:9070 + - 9071:9071 + register_endpoint: + image: docker.io/curlimages/curl:8.8.0 + depends_on: + endpoint: + condition: service_healthy + restate: + condition: service_started + command: + - /bin/sh + - -c + - | + curl --retry 10 http://restate:9070/deployments -H 'content-type: application/json' -d '{"uri": "http://endpoint:9080"}' + echo "Endpoint successfully registered" \ No newline at end of file