From 37284e651c4795f098ac9ca8f4825c7e08a6cbfe Mon Sep 17 00:00:00 2001 From: ss Date: Wed, 11 Jun 2025 18:22:23 +0100 Subject: [PATCH] Added docker-composer.yaml --- .env.sample | 2 ++ .gitignore | 3 ++- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 56 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .env.sample create mode 100644 docker-compose.yml diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..cbe7a5d --- /dev/null +++ b/.env.sample @@ -0,0 +1,2 @@ +PROJECT_ID=your-project-id +SYMBOL=your-topic \ No newline at end of file diff --git a/.gitignore b/.gitignore index 48791ce..7ebf7df 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.kpt-pipeline \ No newline at end of file +.kpt-pipeline +.env \ No newline at end of file diff --git a/README.md b/README.md index 6dd7736..c2d6da3 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,64 @@ The `gke-pubsub-websocket-adapter` uses [Workload Identity](https://cloud.google For the default deployment, these variables are set for you in the `kubernetes-manifests/setters.yaml` file. Please modify these, and these will be rended as a part of the Skaffold pipeline. +## Using Docker Compose + +For local development and testing, you can use Docker Compose to run the `gke-pubsub-websocket-adapter`. This provides a simpler setup without requiring GKE or other cloud infrastructure. + +### Prerequisites + +- Docker +- Docker Compose +- Google Cloud credentials configured locally + +### Setup + +1. Create a `.env` file in your project root: + +``` +PROJECT_ID=your-project-id +SYMBOL=your-topic +``` + +2. The `docker-compose.yml` file is already configured with the following services: + - `init-perms`: Initializes the shared volume with correct permissions + - `cron`: Handles periodic tasks + - `pulltop`: Manages Pub/Sub subscription + - `websocketd`: Serves WebSocket connections + +### Running + +Start all services: + +```bash +docker-compose up +``` + +The WebSocket server will be available at `ws://localhost:8080`. + +### Testing + +You can test the WebSocket connection using a tool like `websocat`: + +```bash +websocat ws://localhost:8080 +``` + +Or use the built-in diagnostic page by visiting `http://localhost:8080` in your browser. + +### Cleanup + +Stop all services: + +```bash +docker-compose down +``` + +To remove the shared volume data: + +```bash +docker-compose down -v +``` ## Known issues and enhancements diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c67aaf8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,56 @@ +version: '3.8' + +services: + init-perms: + image: busybox + volumes: + - data:/data + entrypoint: ["sh", "-c", "mkdir -p /data && chown -R 1000:1000 /data"] + restart: "no" + + cron: + build: + context: ./cron + container_name: cron + depends_on: + - init-perms + user: "1000:1000" + environment: + - PROJECT_ID=${PROJECT_ID} + - SYMBOL=${SYMBOL} + - STREAM=/data/file + volumes: + - data:/data + + pulltop: + build: + context: ./pulltop + container_name: pulltop + depends_on: + - init-perms + user: "1000:1000" + environment: + - PROJECT_ID=${PROJECT_ID} + - SYMBOL=${SYMBOL} + - STREAM=/data/file + volumes: + - data:/data + + websocketd: + build: + context: ./websocketd + container_name: websocketd + depends_on: + - init-perms + user: "1000:1000" + environment: + - PROJECT_ID=${PROJECT_ID} + - SYMBOL=${SYMBOL} + - STREAM=/data/file + ports: + - "8080:8080" + volumes: + - data:/data + +volumes: + data: \ No newline at end of file