diff --git a/bufstream/docker-compose/.gitignore b/bufstream/docker-compose/.gitignore new file mode 100644 index 0000000..177afaf --- /dev/null +++ b/bufstream/docker-compose/.gitignore @@ -0,0 +1,2 @@ +minio +postgres diff --git a/bufstream/docker-compose/README.md b/bufstream/docker-compose/README.md new file mode 100644 index 0000000..3a3c3fb --- /dev/null +++ b/bufstream/docker-compose/README.md @@ -0,0 +1,40 @@ +![The Buf logo](https://raw.githubusercontent.com/bufbuild/buf-examples/main/.github/buf-logo.svg) + +# Docker Compose for Bufstream + +This directory contains an example `docker-compose.yml` file that sets up all required infrastructure for a [Bufstream][bufstream] environment suitable for local testing and development. + +To get started, just run: + +``` +$ docker compose up +``` + +## Services + +This Compose project will start the following services: + +- MinIO (https://min.io/) for S3 compatible storage. + * Its API endpoint is available at http://localhost:9000. + * Its admin endpoint is available at http://localhost:9001. +- A MinIO Client (mc - https://min.io/docs/minio/linux/reference/minio-mc.html) to bootstrap an initial bucket. +- PostgreSQL (https://www.postgresql.org/) for metadata storage. + * It is available on the standard Postgres port (5432). +- A Bufstream broker. + * Its Kafka endpoint is available at localhost:9092. + * Its admin endpoint listens on its default port (9089), allowing you to run [`bufstream admin`](https://buf.build/docs/bufstream/reference/cli/admin/) commands against the broker. + +## Volumes + +When this Compose project starts, it will create two directories: + +1. `minio`: A volume used by the `minio` service for object storage. +2. `postgres`: A volume used by the `postgres` service for its database storage. + +Before committing this `docker-compose.yml` file to your own repository, add these to your `.gitignore`. + +## Networks + +This example uses host networking. You may encounter issues if there are port conflicts. If you need to use port mappings, see [Docker's documentation](https://docs.docker.com/compose/how-tos/networking/). + +[bufstream]: https://buf.build/product/bufstream diff --git a/bufstream/docker-compose/bufstream.yaml b/bufstream/docker-compose/bufstream.yaml new file mode 100644 index 0000000..1e30931 --- /dev/null +++ b/bufstream/docker-compose/bufstream.yaml @@ -0,0 +1,18 @@ +storage: + # Using a local MinIO instance requires the S3 provider, a region, and for + # force_path_style to be true. + provider: S3 + region: example_region + force_path_style: true + # The included docker-compose.yml creates a bucket named "bufstream" after + # deploying MinIO to localhost:9000 with the following credentials. + bucket: bufstream + endpoint: http://localhost:9000 + access_key_id: + string: minioadmin + secret_access_key: + string: minioadmin +# The included docker-compose.yml creates a database with these credentials. +postgres: + dsn: + string: postgres://root:password@localhost:5432/bufstream diff --git a/bufstream/docker-compose/docker-compose.yml b/bufstream/docker-compose/docker-compose.yml new file mode 100644 index 0000000..e9a9771 --- /dev/null +++ b/bufstream/docker-compose/docker-compose.yml @@ -0,0 +1,47 @@ +services: + # Bufstream uses PostgreSQL 14+ (https://www.postgresql.org/) for storing cluster metadata. + postgres: + image: postgres:14 + environment: ["POSTGRES_USER=root", "POSTGRES_PASSWORD=password", "POSTGRES_DB=bufstream"] + network_mode: host + volumes: ["./postgres:/var/lib/postgresql/data"] + healthcheck: + test: ["CMD", "pg_isready", "-d", "bufstream"] + interval: 2s + retries: 30 + + # MinIO provides local S3-compatible object storage. + minio: + image: minio/minio:RELEASE.2025-05-24T17-08-30Z + network_mode: host + volumes: ["./minio:/data"] + healthcheck: + test: ["CMD", "curl", "--silent", "--fail", "--output", "/dev/null", "http://localhost:9000/minio/health/live"] + interval: 2s + retries: 30 + command: ["server", "/data", "--console-address", ":9001"] + + # Minio Client (https://min.io/docs/minio/linux/reference/minio-mc.html) bootstraps a MinIO bucket. + mc: + image: minio/mc:RELEASE.2025-05-21T01-59-54Z + depends_on: + minio: { "condition": "service_healthy" } + network_mode: host + entrypoint: > + /bin/sh -c " + until (/usr/bin/mc alias set minio http://localhost:9000 minioadmin minioadmin) do echo '...waiting...' && sleep 1; done; + /usr/bin/mc mb minio/bufstream; /usr/bin/mc anonymous set public minio/bufstream; + " + + # The Bufstream broker, available at localhost:9092. + bufstream: + image: bufbuild/bufstream:0.3.29 + depends_on: + postgres: { "condition": "service_healthy" } + mc: { "condition": "service_completed_successfully" } + network_mode: host + hostname: bufstream + volumes: ["./bufstream.yaml:/bufstream.yaml"] + healthcheck: + test: ["CMD", "/usr/local/bin/bufstream", "admin", "status", "--exit-code", "--url", "http://127.0.0.1:9089"] + command: ["serve", "--config", "/bufstream.yaml"]