Skip to content

Commit

Permalink
service environment variable (#3809)
Browse files Browse the repository at this point in the history
* first draft of service environment variable

* Apply suggestions from code review

Co-authored-by: AnouckColson <113913013+AnouckColson@users.noreply.github.com>

* missing end of note shortcode

* removing

* ElasticSearch service envVars

* ChromeHeadless service envVars

* ChromeHeadless service envVars (2)

* InfluxDB service envVars

* Kafka service envVars

* MariaDB service envVars

* Memcache service envVars

* MongoDB service envVars

* OpenSearch service envVars

* PostgreSQL service envVars

* RabbitMQ service envVars

* REDIS service envVars

* SOLR service envVars example

* SOLR service envVars finished

* VAULT-KMS service envVars

* REDIS service envVars with CodeTabs

* REDIS service envVars rename serviceName cache to redis

* MEMCACHED service envVars with CodeTabs

* REDIS missing envVar

* RABBITMQ service envVars with CodeTabs

* POSTGRESQL service envVars with CodeTabs

* OPENSEARCH service envVars with CodeTabs

* MONGODB service envVars with CodeTabs

* MARIADB service envVars with CodeTabs

* MARIADB service envVars - missing replication refacto

* KAFKA service envVars with CodeTabs

* change Yaml to Json format for RS snippet

* POSTGRESQL service envVars with CodeTabs

* Network storage relationship sample

* small improvment on json snippets

* MongoDB enterprise version except for Legacy section

* INFLUXDB service envVars with CodeTabs

* CHROMEHEADLESS service envVars with CodeTabs

* ELASTICSEARCH service envVars with CodeTabs

* CLICKHOUSE service envVars with CodeTabs

* reporting serviceName and relationName to P.sh

* Update sites/friday/src/development/variables/_index.md

Co-authored-by: AnouckColson <113913013+AnouckColson@users.noreply.github.com>

* Push discussed changes for more context and clarity

* Apply suggestions from review and fix links

* Fix output issue on Ruby page

* Fix occurrence

* setVariable.map with codetabs

* use variables with codetabs

* Change format of the service envVar

* Java.migrate with CodeTabs

* multi-app.relationships with CodeTabs

* sanitize db.postgres + change format of the service env

* Finishing touches on wording

---------

Co-authored-by: AnouckColson <113913013+AnouckColson@users.noreply.github.com>
Co-authored-by: Anouck Colson <anouck.colson@platform.sh>
  • Loading branch information
3 people committed Mar 8, 2024
1 parent 8edc6a5 commit d2f7059
Show file tree
Hide file tree
Showing 50 changed files with 1,653 additions and 877 deletions.
46 changes: 23 additions & 23 deletions shared/data/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"disk": false,
"docs": {
"relationship_name": "chromeheadlessbrowser",
"service_name": "headlessbrowser",
"service_name": "chromeheadless",
"url": "/add-services/headless-chrome.html"
},
"endpoint": "http",
Expand Down Expand Up @@ -101,7 +101,7 @@
"disk": true,
"docs": {
"relationship_name": "essearch",
"service_name": "searchelastic",
"service_name": "elasticsearch",
"url": "/add-services/elasticsearch.html"
},
"endpoint": "elasticsearch",
Expand Down Expand Up @@ -276,8 +276,8 @@
"description": "",
"disk": true,
"docs": {
"relationship_name": "influxtimedb",
"service_name": "timedb",
"relationship_name": "influxdbdatabase",
"service_name": "influxdb",
"url": "/add-services/influxdb.html"
},
"endpoint": "influxdb",
Expand Down Expand Up @@ -356,7 +356,7 @@
"disk": true,
"docs": {
"relationship_name": "kafkaqueue",
"service_name": "queuekafka",
"service_name": "kafka",
"url": "/add-services/kafka.html"
},
"endpoint": "kafka",
Expand Down Expand Up @@ -431,8 +431,8 @@
"repo_name": "mariadb",
"disk": true,
"docs": {
"relationship_name": "database",
"service_name": "db",
"relationship_name": "mariadbdatabase",
"service_name": "mariadb",
"url": "/add-services/mysql.html"
},
"endpoint": "mysql",
Expand Down Expand Up @@ -491,8 +491,8 @@
"repo_name": "mariadb",
"disk": true,
"docs": {
"relationship_name": "database",
"service_name": "db",
"relationship_name": "mysqldatabase",
"service_name": "mysql",
"url": "/add-services/mysql.html"
},
"endpoint": "mysql",
Expand Down Expand Up @@ -548,7 +548,7 @@
"disk": false,
"docs": {
"relationship_name": "memcachedcache",
"service_name": "cachemc",
"service_name": "memcached",
"url": "/add-services/memcached.html"
},
"endpoint": "memcached",
Expand All @@ -573,8 +573,8 @@
"repo_name": "mongodb",
"disk": true,
"docs": {
"relationship_name": "mongodatabase",
"service_name": "dbmongo",
"relationship_name": "mongodbdatabase",
"service_name": "mongodb",
"url": "/add-services/mongodb.html"
},
"endpoint": "mongodb",
Expand All @@ -598,8 +598,8 @@
"repo_name": "mongodb",
"disk": true,
"docs": {
"relationship_name": "mongodatabase",
"service_name": "dbmongo",
"relationship_name": "mongodbdatabase",
"service_name": "mongodb",
"url": "/add-services/mongodb.html"
},
"endpoint": "mongodb",
Expand Down Expand Up @@ -713,7 +713,7 @@
"disk": true,
"docs": {
"relationship_name": "ossearch",
"service_name": "searchopen",
"service_name": "opensearch",
"url": "/add-services/opensearch.html"
},
"endpoint": "opensearch",
Expand Down Expand Up @@ -754,8 +754,8 @@
"repo_name": "oracle-mysql",
"disk": true,
"docs": {
"relationship_name": "mysqldatabase",
"service_name": "dbmysql",
"relationship_name": "oracledatabase",
"service_name": "oracle-mysql",
"url": "/add-services/mysql.html"
},
"endpoint": "mysql",
Expand Down Expand Up @@ -844,8 +844,8 @@
"repo_name": "postgresql",
"disk": true,
"docs": {
"relationship_name": "postgresdatabase",
"service_name": "dbpostgres",
"relationship_name": "postgresqldatabase",
"service_name": "postgresql",
"url": "/add-services/postgresql.html"
},
"endpoint": "postgresql",
Expand Down Expand Up @@ -947,7 +947,7 @@
"disk": true,
"docs": {
"relationship_name": "rabbitmqqueue",
"service_name": "queuerabbit",
"service_name": "rabbitmq",
"url": "/add-services/rabbitmq.html"
},
"endpoint": "rabbitmq",
Expand Down Expand Up @@ -1003,7 +1003,7 @@
"disk": false,
"docs": {
"relationship_name": "rediscache",
"service_name": "cacheredis",
"service_name": "redis",
"url": "/add-services/redis.html"
},
"endpoint": "redis",
Expand Down Expand Up @@ -1151,7 +1151,7 @@
"disk": true,
"docs": {
"relationship_name": "solrsearch",
"service_name": "searchsolr",
"service_name": "solr",
"url": "/add-services/solr.html"
},
"endpoint": "solr",
Expand Down Expand Up @@ -1235,7 +1235,7 @@
"description": "",
"disk": true,
"docs": {
"relationship_name": "vault_service",
"relationship_name": "vault_secret",
"service_name": "vault-kms",
"url": "/add-services/vault.html"
},
Expand Down
10 changes: 5 additions & 5 deletions sites/friday/src/add-services/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ You can connect through your app or by opening an SSH tunnel to access the servi
title=In an app
+++

Once a service is running and exposed as a relationship,
its credentials (such as the host, username, and password) are available through the `{{% vendor/prefix %}}_RELATIONSHIPS` environment variable.
The available information is documented on each service's page along with sample code for how to connect to it from your app.
Once a service is running and exposed via a relationship,
its credentials (such as the host, username, and password) are automatically available as [service environment variables](/development/variables.html#service-environment-variables),
in the `$<RELATIONSHIP-NAME>_<SERVICE-PROPERTY>` format.
The available information is documented on each service's page, along with sample code for how to connect to it from your app.

The keys in the `{{< vendor/prefix >}}_RELATIONSHIPS` variable are fixed, but the values may change on deployment or restart.
The service environment variable names are fixed, but the values may change if you change the relationship name to the service.
So **use the environment variable** rather than hard coding the values.

<--->
Expand All @@ -177,7 +178,6 @@ Connecting to a service using an SSH tunnel is a two-step process.

### 1. Obtain service credentials


To get the credentials for a given service, run the following command:

```bash
Expand Down
79 changes: 61 additions & 18 deletions sites/friday/src/add-services/clickhouse.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,73 @@
---
title: "ClickHouse"
weight: -110
description:
description:
---

ClickHouse is a high-performance column-oriented, distributed, OLAP (Online Analytical Processing) database.</br>
It allows you to generate real-time analytical data reports using SQL queries.</br>
For more information, see the [ClickHouse documentation](https://ClickHouse.com/docs).

{{% note %}}
{{% note %}}

{{% vendor/name %}} supports ClickHouse with the following limitations:

- High availibility of service isn't supported.
- You can only configure single-node ClickHouse clusters.

{{% /note %}}
{{% /note %}}

## Supported versions

- 23.8

{{% vendor/name %}} plans on supporting long-term support ClickHouse versions in priority.

## Relationship reference
{{% relationship-ref-intro %}}

Example information available through the [`PLATFORM_RELATIONSHIPS` environment variable](/development/variables/use-variables.md#use-provided-variables)
or by running `{{< vendor/cli >}} relationships`.
{{< codetabs >}}
+++
title= Service environment variables
+++

{{% service-values-change %}}

```bash
CLICKHOUSEDATABASE_USERNAME=main
CLICKHOUSEDATABASE_FRAGMENT=
CLICKHOUSEDATABASE_IP=123.456.78.90
CLICKHOUSEDATABASE_CLUSTER=azertyuiop-main-afdwftq
CLICKHOUSEDATABASE_HOST=clickhousedatabase.internal
CLICKHOUSEDATABASE_PATH=main
CLICKHOUSEDATABASE_QUERY={'is_master': True}
CLICKHOUSEDATABASE_PASSWORD=ChangeMe
CLICKHOUSEDATABASE_PORT=9000
CLICKHOUSEDATABASE_HOST_MAPPED=false
CLICKHOUSEDATABASE_SERVICE=clickhouse
CLICKHOUSEDATABASE_HOSTNAME=azertyuiopqsdfghjklm.clickhouse.service._.eu-1.{{< vendor/urlraw "hostname" >}}
CLICKHOUSEDATABASE_EPOCH=0
CLICKHOUSEDATABASE_REL=clickhouse
CLICKHOUSEDATABASE_SCHEME=clickhouse
CLICKHOUSEDATABASE_TYPE=clickhouse:23
CLICKHOUSEDATABASE_PUBLIC=false
```

```yaml
<--->

+++
title= `PLATFORM_RELATIONSHIPS` environment variable
+++

For some advanced use cases, you can use the [`PLATFORM_RELATIONSHIPS` environment variable](/development/variables/use-variables.md#use-provided-variables).
The structure of the `PLATFORM_RELATIONSHIPS` environment variable can be obtained by running `{{< vendor/cli >}} relationships` in your terminal:

```json
{
"username": "main",
"fragment": null,
"ip": "169.254.143.42",
"cluster": "s7vj2hgh6nwsk-main-bvxea6i",
"host": "clickhouse.internal",
"ip": "123.456.78.90",
"cluster": "azertyuiop-main-afdwftq",
"host": "clickhousedatabase.internal",
"path": "main",
"query": {
"is_master": true
Expand All @@ -43,18 +76,28 @@ or by running `{{< vendor/cli >}} relationships`.
"port": 9000,
"host_mapped": false,
"service": "clickhouse",
"hostname": "oid3uu43xj2iujgwvplpo6ytme.clickhouse.service._.eu-3.platformsh.site",
"hostname": "azertyuiopqsdfghjklm.clickhouse.service._.eu-1.{{< vendor/urlraw "hostname" >}}",
"epoch": 0,
"instance_ips": [
"247.95.64.160"
],
"rel": "clickhouse",
"scheme": "clickhouse",
"type": "clickhouse:23",
"public": false
}
```

Here is an example of how to gather [`PLATFORM_RELATIONSHIPS` environment variable](/development/variables/use-variables.md#use-provided-variables) information
in a [`.environment` file](/development/variables/set-variables.md#use-env-files):

```bash {location=".environment"}
# Decode the built-in credentials object variable.
export RELATIONSHIPS_JSON=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode)

# Set environment variables for individual credentials.
export APP_CLICKHOUSE_HOST=="$(echo $RELATIONSHIPS_JSON | jq -r '.clickhousedatabase[0].host')"
```

{{< /codetabs >}}

## Usage example

### 1. Configure the service
Expand Down Expand Up @@ -96,7 +139,7 @@ services:
```

You can define ``<SERVICE_NAME>`` and ``<RELATIONSHIP_NAME>`` as you like, but it’s best if they’re distinct.
With this definition, the application container (``<APP_NAME>``) now has access to the service via the relationship ``<RELATIONSHIP_NAME>``.
With this definition, the application container (``<APP_NAME>``) now has access to the service via the corresponding [service environment variables](/development/variables/_index.md#service-environment-variables).

#### `clickhouse-http` endpoint

Expand All @@ -120,7 +163,7 @@ services:
```

You can define ``<SERVICE_NAME>`` and ``<RELATIONSHIP_NAME>`` as you like, but it’s best if they’re distinct.
With this definition, the application container (``<APP_NAME>``) now has access to the service via the relationship ``<RELATIONSHIP_NAME>``.
With this definition, the application container (``<APP_NAME>``) now has access to the service via the corresponding [service environment variables](/development/variables/_index.md#service-environment-variables).

### Example configuration

Expand All @@ -139,7 +182,7 @@ applications:
root: "myapp"
# Relationships enable an app container's access to a service.
relationships:
clickhouse: "clickhouse:clickhouse"
clickhousedatabase: "clickhouse:clickhouse"
services:
# The name of the service container. Must be unique within a project.
type: clickhouse:23
Expand All @@ -160,7 +203,7 @@ applications:
root: "myapp"
# Relationships enable an app container's access to a service.
relationships:
clickhouse: "clickhouse:clickhouse-http"
clickhousedatabase: "clickhouse:clickhouse-http"
services:
# The name of the service container. Must be unique within a project.
type: clickhouse:23
Expand Down
Loading

0 comments on commit d2f7059

Please sign in to comment.