Specification

Resources

Provisioner

Dapr Subscription


score.yaml (view on GitHub) :

apiVersion: score.dev/v1b1
metadata:
  name: my-workload
  annotations:
    dapr.io/enabled: "true"
    dapr.io/app-id: "my-workload"
    dapr.io/app-port: "3000"
containers:
  my-container:
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo $TOPIC_NAME; echo '\n'; sleep 5; done"]
    variables:
      TOPIC_NAME: "${resources.subscription.topic}"
service:
  ports:
    tcp:
      port: 3000
      targetPort: 3000
resources:
  subscription:
    type: dapr-subscription
    params:
      topic: "notifications"
      pubsub: "pubsub"


10-dapr-subscription.provisioners.yaml (view on GitHub) :

- uri: template://community-provisioners/dapr-subscription
  type: dapr-subscription
  description: Generates a Dapr Subscription on a given Topic and PubSub.
  supported_params:
    - topic
    - pubsub
  init: |
    subscriptionName: {{ .Params.topic }}-subscription-{{ randAlphaNum 6 }}    
  state: |
    subscriptionName: {{ dig "subscriptionName" .Init.subscriptionName .State | quote }}    
  outputs: |
    name: {{ .State.subscriptionName }}
    topic: {{ .Params.topic }}    
  expected_outputs:
    - name
    - topic
  files: |
    components/{{ .State.subscriptionName }}.yaml: |
      apiVersion: dapr.io/v2alpha1
      kind: Subscription
      metadata:
        name: {{ .State.subscriptionName }}
      spec:
        topic: {{ .Params.topic }}
        routes:
          default: /{{ .Params.topic }}
        pubsubname: {{ .Params.pubsub }}
      scopes:
        - {{ .SourceWorkload }}    

Initialize your local workspace, by importing a specific community provisioner:

score-commpose 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-commpose generate score.yaml

See the resource outputs:

score-commpose resources list

You can run the following command on each resource listed with the previous command to get their outputs:

score-commpose resources get-outputs

Deploy the generated manifests:

docker compose up -d

See the running containers:

docker ps


10-dapr-subscription.provisioners.yaml (view on GitHub) :

- uri: template://community-provisioners/dapr-subscription
  type: dapr-subscription
  description: Generates a Dapr Subscription on a given Topic and PubSub.
  supported_params:
    - topic
    - pubsub
  state: |
    name: {{ .Params.topic }}-subscription-{{ substr 0 8 .Guid | lower }}    
  outputs: |
    name: {{ .State.name }}
    topic: {{ .Params.topic }}    
  expected_outputs:
    - name
    - topic
  manifests: |
    - apiVersion: dapr.io/v2alpha1
      kind: Subscription
      metadata:
        name: {{ .State.name }}
        {{ if ne .Namespace "" }}
        namespace: {{ .Namespace }}
        {{ end }}
      spec:
        topic: {{ .Params.topic }}
        routes:
          default: /{{ .Params.topic }}
        pubsubname: {{ .Params.pubsub }}
      scopes:
        - {{ .SourceWorkload }}    

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