From 365d8af0ce0eb68b3b688a331112ae75bb9ebdb5 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 4 Oct 2024 13:47:52 -0700 Subject: [PATCH 1/3] add interpolation to docs --- docs/concepts/interpolation.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/concepts/interpolation.md diff --git a/docs/concepts/interpolation.md b/docs/concepts/interpolation.md new file mode 100644 index 000000000..2e1334dea --- /dev/null +++ b/docs/concepts/interpolation.md @@ -0,0 +1,23 @@ +--- +title: Interpolation +description: Construct environment variable values in `compose.yml` file by referencing other configuration variables. +sidebar_position: 200 +--- + +# Interpolation + +Environment variables are set within the *environment* section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container. + +Variables can be set by assigning a literal value, a reference to a [configuration value](./configuration.md), or a mix of literal and variable references. Variable references are declared using either **\$\{variable_name\}** or **$variable_name** forms. It is recommended to use the bracketed form. By interpolating over variable references within a string we can construct complex strings. Interpolation may be particularly useful when constructing connection strings to other services. + +``` +service: + environment: + - USER_PASSWORD // configuration variable + - USER_NAME // configuration variable + - CONNECT=dbservice:${USER_NAME}:${USER_PASSWORD}@$example.com:9876 +``` +In the example, if we assume the value of the configuration variable ***USER_PASSWORD*** is *password* then the value assigned to ***CONNECT*** will be *dbservice:alice:password@example.com:9876* + + +During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled. \ No newline at end of file From ba52445ede554b6823a1a7220272bfa579c7859b Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 7 Oct 2024 10:24:01 -0700 Subject: [PATCH 2/3] move interpolation to configuration section. Added connection string to managed postgres docs --- docs/concepts/configuration.md | 20 +++++++++++++++++++ .../managed-storage/managed-postgres.md | 3 +++ 2 files changed, 23 insertions(+) diff --git a/docs/concepts/configuration.md b/docs/concepts/configuration.md index 5983eb03d..dc02827f9 100644 --- a/docs/concepts/configuration.md +++ b/docs/concepts/configuration.md @@ -44,6 +44,24 @@ services: Use the `defang config` command of the Defang CLI to manage the values. +## Interpolation + +Environment variables are set within the *environment* section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container. + +Variables can be set by assigning a literal value, a reference to a configuration value, or a mix of literal and variable references. Variable references are declared using either **\$\{variable_name\}** or **$variable_name** forms. It is recommended to use the bracketed form. By interpolating over variable references within a string we can construct complex strings. Interpolation may be particularly useful when constructing connection strings to other services. + +``` +service: + environment: + - USER_PASSWORD // configuration variable + - USER_NAME // configuration variable + - CONNECT=dbservice:${USER_NAME}:${USER_PASSWORD}@example.com:9876 +``` +In the example above, if we assume the value of the configuration variable ***USER_PASSWORD*** is *password* then the value assigned to ***CONNECT*** will resolve to *dbservice:alice:password@example.com:9876* + + +During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled. + ## Connecting Services If you have created a service before a secret you can connect it by running the `defang compose start` command if using the [`defang compose` workflow](./compose.md). If you are using the [Pulumi-based workflow](./pulumi.md) you will need to redeploy using Pulumi. @@ -57,3 +75,5 @@ You can find a sample of how to set sensitive config values [here](https://githu Here are the different ways sensitive config values are stored depending on the provider you are using: * [AWS](../providers/aws/aws.md#secrets) + + diff --git a/docs/concepts/managed-storage/managed-postgres.md b/docs/concepts/managed-storage/managed-postgres.md index 262ed272b..560ed25f7 100644 --- a/docs/concepts/managed-storage/managed-postgres.md +++ b/docs/concepts/managed-storage/managed-postgres.md @@ -48,6 +48,9 @@ You can connect to the managed Postgres instance using the name of your service # value set using `defang config set POSTGRES_PASSWORD` POSTGRES_PASSWORD: // highlight-end + # Note: you can create a connection string by using interpolation, + # reference config variables by using ${} + CONNECTURL: postgresql://${POSTGRES_PASSWORD}@database:5432/postgres database: image: postgres:15 x-defang-postgres: true From 0025b38fb42dc3c85542e8f3f8e94c3509d65c9f Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 7 Oct 2024 14:06:17 -0700 Subject: [PATCH 3/3] remove unnecessary interpolation doc --- docs/concepts/interpolation.md | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 docs/concepts/interpolation.md diff --git a/docs/concepts/interpolation.md b/docs/concepts/interpolation.md deleted file mode 100644 index 2e1334dea..000000000 --- a/docs/concepts/interpolation.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: Interpolation -description: Construct environment variable values in `compose.yml` file by referencing other configuration variables. -sidebar_position: 200 ---- - -# Interpolation - -Environment variables are set within the *environment* section of a service in a `compose.yaml` file. Any variables declared here will become available within the service container. - -Variables can be set by assigning a literal value, a reference to a [configuration value](./configuration.md), or a mix of literal and variable references. Variable references are declared using either **\$\{variable_name\}** or **$variable_name** forms. It is recommended to use the bracketed form. By interpolating over variable references within a string we can construct complex strings. Interpolation may be particularly useful when constructing connection strings to other services. - -``` -service: - environment: - - USER_PASSWORD // configuration variable - - USER_NAME // configuration variable - - CONNECT=dbservice:${USER_NAME}:${USER_PASSWORD}@$example.com:9876 -``` -In the example, if we assume the value of the configuration variable ***USER_PASSWORD*** is *password* then the value assigned to ***CONNECT*** will be *dbservice:alice:password@example.com:9876* - - -During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled. \ No newline at end of file