From 3862d6039e33ef33bedb13f1c9e3299cb2093744 Mon Sep 17 00:00:00 2001 From: thc1006 <84045975+thc1006@users.noreply.github.com> Date: Wed, 14 Jan 2026 20:07:42 +0000 Subject: [PATCH 1/2] feat: add gcp-pubsub-emulator provisioner for score-compose Add Google Cloud Pub/Sub Emulator provisioner for local development. Resource type: gcp-pubsub-emulator Params: project_id (optional) Outputs: host, port, project_id, emulator_host Image: gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators Closes #53 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com> --- README.md | 1 + .../10-gcp-pubsub-emulator.provisioners.yaml | 40 +++++++++++++++++++ gcp-pubsub-emulator/score.yaml | 14 +++++++ 3 files changed, 55 insertions(+) create mode 100644 gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml create mode 100644 gcp-pubsub-emulator/score.yaml diff --git a/README.md b/README.md index bfd3cf3..8af987f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ score-compose init --provisioners https://raw.githubusercontent.com/score-spec/c | 10-dns-with-url.provisioners.yaml | `dns` | (any) | (none) | `host`, `url` | Outputs a `*.localhost` domain as the hostname and associated URL in http on port `8080`. | 10-endpoint-with-microcks.provisioners.yaml | `endpoint` | (any) | `port`, `openapi_file`, `openapi_title` | `url` | Outputs an endpoint URL for connecting to an other workload (a Microcks mock is generated if not found). | 10-env.provisioners.yaml | `environment` | (any) | (none) | (none) | Loads environment variables from a local `.env` file. +| 10-gcp-pubsub-emulator.provisioners.yaml | `gcp-pubsub-emulator` | (any) | `project_id` | `host`, `port`, `project_id`, `emulator_host` | Generates a Google Cloud Pub/Sub Emulator service for local development. | 10-hpa.provisioners.yaml | `horizontal-pod-autoscaler` | (any) | (none) | (none) | Generates an empty object because HPA is not supported in Docker Compose. | 10-dmr-llm-model-via-curl-cmd.provisioners.yaml | `llm-model` | (any) | `model` | `model`, `url`, `api-key` | Runs `curl` to download the model with the Docker Model Runner (DMR). | 10-dmr-llm-model-via-curl-service.provisioners.yaml | `llm-model` | (any) | `model` | `model`, `url`, `api-key` | Generates a `curl` service downloading the model with the Docker Model Runner (DMR). diff --git a/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml b/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml new file mode 100644 index 0000000..ec30d66 --- /dev/null +++ b/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml @@ -0,0 +1,40 @@ +# GCP Pub/Sub Emulator provisioner +# 用於本地開發測試,不需要連到真正的 GCP +- uri: template://community-provisioners/gcp-pubsub-emulator + type: gcp-pubsub-emulator + description: Generates a Google Cloud Pub/Sub Emulator service for local development. + supported_params: + - project_id + init: | + port: 8085 + randomServiceName: pubsub-emulator-{{ randAlphaNum 6 | lower }} + defaultProjectId: test-project-{{ randAlphaNum 6 | lower }} + state: | + serviceName: {{ dig "serviceName" .Init.randomServiceName .State | quote }} + projectId: {{ dig "projectId" (.Params.project_id | default .Init.defaultProjectId) .State | quote }} + outputs: | + host: {{ .State.serviceName }} + port: {{ .Init.port }} + project_id: {{ .State.projectId }} + emulator_host: {{ .State.serviceName }}:{{ .Init.port }} + expected_outputs: + - host + - port + - project_id + - emulator_host + services: | + {{ .State.serviceName }}: + labels: + dev.score.compose.res.uid: {{ .Uid }} + image: gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators + command: + - gcloud + - beta + - emulators + - pubsub + - start + - --host-port=0.0.0.0:{{ .Init.port }} + - --project={{ .State.projectId }} + restart: always + info_logs: | + - "{{ .Uid }}: Pub/Sub Emulator is running at {{ .State.serviceName }}:{{ .Init.port }}" diff --git a/gcp-pubsub-emulator/score.yaml b/gcp-pubsub-emulator/score.yaml new file mode 100644 index 0000000..48cfafa --- /dev/null +++ b/gcp-pubsub-emulator/score.yaml @@ -0,0 +1,14 @@ +apiVersion: score.dev/v1b1 +metadata: + name: my-workload +containers: + my-container: + image: busybox + command: ["/bin/sh"] + args: ["-c", "while true; do echo $PUBSUB_EMULATOR_HOST; sleep 5; done"] + variables: + PUBSUB_EMULATOR_HOST: "${resources.pubsub.emulator_host}" + PUBSUB_PROJECT_ID: "${resources.pubsub.project_id}" +resources: + pubsub: + type: gcp-pubsub-emulator From b1b5a034f94b70106fea22baf0e45995215523ca Mon Sep 17 00:00:00 2001 From: thc1006 <84045975+thc1006@users.noreply.github.com> Date: Sun, 18 Jan 2026 11:27:26 +0000 Subject: [PATCH 2/2] fix: improve gcp-pubsub-emulator example and documentation - Change Chinese comment to English in provisioner file - Add params section with project_id example in score.yaml - Demonstrate all 4 outputs (host, port, project_id, emulator_host) Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com> --- .../score-compose/10-gcp-pubsub-emulator.provisioners.yaml | 2 +- gcp-pubsub-emulator/score.yaml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml b/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml index ec30d66..457382a 100644 --- a/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml +++ b/gcp-pubsub-emulator/score-compose/10-gcp-pubsub-emulator.provisioners.yaml @@ -1,5 +1,5 @@ # GCP Pub/Sub Emulator provisioner -# 用於本地開發測試,不需要連到真正的 GCP +# For local development and testing without connecting to real GCP - uri: template://community-provisioners/gcp-pubsub-emulator type: gcp-pubsub-emulator description: Generates a Google Cloud Pub/Sub Emulator service for local development. diff --git a/gcp-pubsub-emulator/score.yaml b/gcp-pubsub-emulator/score.yaml index 48cfafa..e9abaa0 100644 --- a/gcp-pubsub-emulator/score.yaml +++ b/gcp-pubsub-emulator/score.yaml @@ -7,8 +7,12 @@ containers: command: ["/bin/sh"] args: ["-c", "while true; do echo $PUBSUB_EMULATOR_HOST; sleep 5; done"] variables: - PUBSUB_EMULATOR_HOST: "${resources.pubsub.emulator_host}" + PUBSUB_HOST: "${resources.pubsub.host}" + PUBSUB_PORT: "${resources.pubsub.port}" PUBSUB_PROJECT_ID: "${resources.pubsub.project_id}" + PUBSUB_EMULATOR_HOST: "${resources.pubsub.emulator_host}" resources: pubsub: type: gcp-pubsub-emulator + params: + project_id: my-test-project