Specification

Resources

Provisioner

Redis


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 $REDIS_HOST; sleep 5; done"]
    variables:
      REDIS_HOST: ${resources.my-redis.host}
      REDIS_PORT: ${resources.my-redis.port}
      REDIS_USERNAME: ${resources.my-redis.username}
      REDIS_PASSWORD: ${resources.my-redis.password}
resources:
  my-redis:
    type: redis

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-redis-helm-template.provisioners.yaml (view on GitHub) :

- uri: cmd://bash#helm-template-redis
  type: redis
  description: Generates the manifests of the bitnami/redis Helm chart.
  args:
  - -c
  - |
    STDIN=$(cat)
    SERVICE=$(echo $STDIN | yq eval -p json '.resource_id' | yq '. |= sub("\.", "-")')
    NAMESPACE=$(echo $STDIN | yq eval -p json '.namespace')
    if [ -z "$NAMESPACE" ]; then
      NAMESPACE="default"
    fi
    set -eu -o pipefail
    helm repo add bitnami https://charts.bitnami.com/bitnami >&2
    HELM_TEMPLATE_OUTPUT_TEMP_FILE=$(mktemp)
    helm template ${SERVICE} bitnami/redis --set replica.replicaCount=1 > ${HELM_TEMPLATE_OUTPUT_TEMP_FILE}
    MANIFESTS_IN_JSON=$(yq ea '[.]' -o json -I=0 ${HELM_TEMPLATE_OUTPUT_TEMP_FILE})
    OUTPUTS='{"resource_outputs":{"host":"%s-master", "port":"6379", "username":"", "password":"🔐💬%s_redis-password💬🔐"},"manifests":%s}'
    printf "$OUTPUTS" "$SERVICE" "$SERVICE" "$MANIFESTS_IN_JSON"    
  expected_outputs: 
    - host 
    - port 
    - username 
    - password

10-redis-helm-upgrade.provisioners.yaml (view on GitHub) :

- uri: cmd://bash#helm-upgrade-redis
  type: redis
  description: Deploys the bitnami/redis Helm chart in an existing cluster. 
  args:
  - -c
  - |
    STDIN=$(cat)
    SERVICE=$(echo $STDIN | yq eval -p json '.resource_id' | yq '. |= sub("\.", "-")')
    NAMESPACE=$(echo $STDIN | yq eval -p json '.namespace')
    if [ -z "$NAMESPACE" ]; then
      NAMESPACE="default"
    fi
    set -eu -o pipefail
    helm repo add bitnami https://charts.bitnami.com/bitnami >&2
    helm upgrade -i ${SERVICE} bitnami/redis --set replica.replicaCount=1 -n ${NAMESPACE} --wait >&2
    OUTPUTS='{"resource_outputs":{"host":"%s-master", "port":"6379", "username":"", "password":"🔐💬%s_redis-password💬🔐"},"manifests":[]}'
    printf "$OUTPUTS" "$SERVICE" "$SERVICE"    
  expected_outputs: 
    - host 
    - port 
    - username 
    - password

README.md (view on GitHub) :

## For `10-redis-helm-template.provisioners.yaml`

Prerequisites:
- Have `helm` installed locally, this provisioner renders the manifests from the [Bitnami's Redis Helm chart](https://bitnami.com/stack/redis/helm).
- Have `yq` installed locally.

## For `10-redis-helm-upgrade.provisioners.yaml`

Prerequisites:
- Have `helm` installed locally, this provisioner installs the [Bitnami's Redis Helm chart](https://bitnami.com/stack/redis/helm).
- Have access to a cluster where the Helm chart will be installed.
    - If you don't have one, you can deploy a `Kind` cluster locally by running this script: `.scripts/setup-kind-cluster.sh`.

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