Gcp Pubsub Emulator
score.yaml
(view on GitHub)
:
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_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
10-gcp-pubsub-emulator.provisioners.yaml
(view on GitHub)
:
# GCP Pub/Sub Emulator provisioner
# 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.
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 }}"
Initialize your local workspace, by importing a specific community provisioner:
score-compose init --provisioners REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml
Note: you need to replace REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml by the actual provisioner file you want to use and import. More information here.
Get the provisioners definition:
score-compose provisioners list
Generate the platform specific manifests:
score-compose generate score.yaml
See the resource outputs:
score-compose resources list
You can run the following command on each resource listed with the previous command to get their outputs:
score-compose resources get-outputs
Deploy the generated manifests:
docker compose up -d
See the running containers:
docker ps
Initialize your local workspace, by importing a specific community provisioner:
score-k8s init --provisioners REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml
Note: you need to replace REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml by the actual provisioner file you want to use and import. More information here.
Get the provisioners definition:
score-k8s provisioners list
Generate the platform specific manifests:
score-k8s generate score.yaml
See the resource outputs:
score-k8s resources list
You can run the following command on each resource listed with the previous command to get their outputs:
score-k8s resources get-outputs
Deploy the generated manifests:
kubectl apply -f manifests.yaml
See the running containers:
kubectl get all