cloud_controller_ng icon indicating copy to clipboard operation
cloud_controller_ng copied to clipboard

Task-specific environment variables

Open nictas opened this issue 3 years ago • 0 comments

Issue

I want to be able to set task-specific environment variables when starting a task on an application:

POST /v3/apps/<GUID>/tasks
{
  "command": "/bin/bash migrate.sh abc",
  "environment_variables": {
    "CONTEXT": "{\"key_1\":\"value_1\"...}"
  }
}

Context

I'm working on an application that uses CF tasks to perform database changes (migrations). This application is also tenant-aware and has a separate database schema for each of its tenants. We therefore create a CF task for each tenant and pass the tenant ID as an argument to the migration script. For example:

cf run-task my-app "/bin/bash migrate.sh abc"
cf run-task my-app "/bin/bash migrate.sh def"

Where abc and def are tenant IDs. In addition to these tenant IDs, this script requires a relatively big JSON object that I, unfortunately, cannot describe here, but the important part is that it can vary depending on the tenant. We want to avoid passing this JSON object as an argument to the script since the command of a task is limited in size to 4097 characters. Our preference would be to set it as an environment variable, but since its value varies, we can't set it on the application itself. Ideally, we want to be able to do something like:

cf run-task my-app "/bin/bash migrate.sh abc" -e CONTEXT="<JSON>"
cf run-task my-app "/bin/bash migrate.sh def" -e CONTEXT="<DIFFERENT_JSON>"

I hope I gave you enough background. If you have any questions, I'll be happy to try and answer them.

nictas avatar Oct 11 '21 17:10 nictas