From 83857e6f2b288377d2c308c4195388251ccbc30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Susa=20T=C3=BCnker?= Date: Thu, 11 Apr 2024 15:38:10 +0200 Subject: [PATCH 1/2] Updated section on environment variables --- .../en/docs/environment variables/_index.md | 6 +- .../environment-variables-compose.md | 128 --------------- .../environment-variables-helm.md | 147 ------------------ 3 files changed, 3 insertions(+), 278 deletions(-) delete mode 100644 content/en/docs/environment variables/environment-variables-compose.md delete mode 100644 content/en/docs/environment variables/environment-variables-helm.md diff --git a/content/en/docs/environment variables/_index.md b/content/en/docs/environment variables/_index.md index 88dffbb3..ff68caa8 100644 --- a/content/en/docs/environment variables/_index.md +++ b/content/en/docs/environment variables/_index.md @@ -1,6 +1,6 @@ --- title: "Define environment variables" -linkTitle: "Define environment variables" +linkTitle: "Environment variables" weight: 5 description: > This section describes how to define environment variables. @@ -20,5 +20,5 @@ The Score Specification supports declaring environment variables in a configurat For more information, see -- [Environment variables in score-compose]({{< relref "/docs/environment variables/environment-variables-compose" >}}) -- [Environment variables in score-helm]({{< relref "/docs/environment variables/environment-variables-helm" >}}) \ No newline at end of file +- [Environment variables in score-compose](https://github.com/score-spec/score-compose/tree/main/examples/02-environment) +- [Environment variables in score-helm](https://github.com/score-spec/score-helm/tree/main/examples/02-environment) \ No newline at end of file diff --git a/content/en/docs/environment variables/environment-variables-compose.md b/content/en/docs/environment variables/environment-variables-compose.md deleted file mode 100644 index 527d443d..00000000 --- a/content/en/docs/environment variables/environment-variables-compose.md +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: "Environment variables in score-compose" -linkTitle: "score-compose" -weight: 5 -description: > - This section describes how to define environment variables for score-compose. ---- - -When `docker compose` runs a service, it is possible to pass information from the host to the container through environment variables. - -This _hello world_ example provides an [Overview](#overview) section and two options to resolve your variable name: - -- [Overview](#overview) -- [Environment configuration in file](#environment-configuration-in-file) -- [Environment configuration in your shell](#environment-configuration-in-your-shell) -- [Learn more](#learn-more) - -## Overview - -The Score Specification uses a special `environment` property type that is specified in the `resources` section. - -```yaml {linenos=false,hl_lines=["16"]} -apiVersion: score.dev/v1b1 - -metadata: - name: hello-world - -containers: - hello: - image: busybox - command: ["/bin/sh"] - args: ["-c", "while true; do echo Hello $${FRIEND}!; sleep 5; done"] - variables: - FRIEND: ${resources.env.NAME} - -resources: - env: - type: environment -``` - -Use the `run` command to generate a Docker Compose file from Score. - -```bash -score-compose run -f ./score.yaml \ - -o ./compose.yaml -``` - -The `compose.yaml` file contains a single service definition and utilizes a host environment variable called `NAME`. - -The following `compose.yaml` file is the output of previous. - -```yaml -services: - hello-world: - command: - - -c - - 'while true; do echo Hello $${FRIEND}!; sleep 5; done' - entrypoint: - - /bin/sh - environment: - FRIEND: ${NAME-World} - image: busybox -``` - -## Environment configuration file - -It is recommended to declare your environment configuration in a `.env` file. - -Use the `--env-file` flag with the `score-compose` CLI tool to additionally produce a `.env` file that can be used alongside the generated compose file. - -```bash -score-compose run -f score.yaml \ - -o compose.yaml \ - --env-file hello.env -``` - -The `--env-file` flag will create a file that can be used with the Docker platform. - -The following is the output of the previous command in the `hello.env` file. - -```yaml -NAME=World -``` - -Run the `docker compose` command with the `--env-file` flag, specify the path to your `.env` file. - -```bash -docker compose -f compose.yaml --env-file hello.env up -``` - -The following is the output of the previous command. - -```bash -[+] Running 1/0 - ⠿ Container score-compose-hello-world-1 Created 0.0s -Attaching to score-compose-hello-world-1 -score-compose-hello-world-1 | Hello Hello! -``` - -**Results** you've successfully passed an environment variable through an `.env` file. - -## Environment configuration in your shell - -To use environment configurations in your shell, assign a value to a variable using your shell's built-in `export` command. - -The following example sets the environment variable to `Hello`. - -```bash -export NAME=Hello -docker compose -f ./compose.yaml up -``` - -The following is the output of the previous command. - -```bash -[+] Running 1/0 -⠿ Container score-compose-hello-world-1 Rec... 0.1s -Attaching to score-compose-hello-world-1 -score-compose-hello-world-1 | Hello Hello! -``` - -## Learn more - -For more information, see the following links. - -- The [score-compose environment README.md](https://github.com/score-spec/score-compose/edit/main/examples/02-environment/README.md) file. -- The [`.env`](https://docs.docker.com/compose/environment-variables/#using-the---env-file--option) option in the Docker Compose documentation. -- The [Score Specification reference]({{< relref "../score-specification/score-spec-reference" >}} "Score Specification") diff --git a/content/en/docs/environment variables/environment-variables-helm.md b/content/en/docs/environment variables/environment-variables-helm.md deleted file mode 100644 index 8277882f..00000000 --- a/content/en/docs/environment variables/environment-variables-helm.md +++ /dev/null @@ -1,147 +0,0 @@ ---- -title: "Environment variables in score-helm" -linkTitle: "score-helm" -weight: 5 -description: > - This section describes how to define environment variables for score-helm. ---- - -## Substitute environment configurations - -To use environment configurations, declare your variable names in your `score.yaml` file. - -In the following example, the `FRIEND` variable sources its value from the `NAME` property in the `resources` section. - -- `NAME` - -```yaml -apiVersion: score.dev/v1b1 - -metadata: - name: hello-world - -containers: - hello: - image: busybox - command: ["/bin/sh"] - args: ["-c", "while true; do echo Hello $${FRIEND}!; sleep 5; done"] - variables: - FRIEND: ${resources.env.NAME} - -resources: - env: - type: environment -``` - -{{% alert %}} - -> Resources need to map to the resource structure. -> To declare environment variables in a Score file, the variable name, `resources.env.NAME` must map to the structure in `resource` section. - -For more information, see the [Resource section]({{< relref "/docs/score-specification/score-spec-reference#referencing-resources" >}}) in the Score Specification reference. - -{{% /alert %}} - -## Generate a Helm values file - -Declare your environment configurations. - -1. Create a `env.yaml` file and add your environment variables. - -```yaml -env: - NAME: John -``` - -2. When running `score-helm run`, you'll want to pass the `--values` flag where `env.yaml` imported values file. - -```bash -score-helm run -f ./score.yaml \ - --values ./env.yaml \ - -o ./values.yaml -``` - -The following is the output of the previous command. - -```yml -containers: - hello: - args: - - -c - - while true; do echo Hello $${FRIEND}!; sleep 5; done - command: - - /bin/sh - env: - - name: FRIEND - value: John - image: - name: busybox -``` - -### Initialize the Workload Helm Chart Repository - -Run the following command to initialize the Workload Helm chart repository. - -```bash -helm repo add score-helm-charts https://score-spec.github.io/score-helm-charts -``` - -Once this is installed, you will be able to use the default `score-helm-charts/workload` Helm chart (you can adapt it for your own use case, find the source code [here](https://github.com/score-spec/score-helm-charts)). - -### Install Helm `values.yaml` - -Run the following command to deploy the `score-helm-charts/workload` Helm chart with the Helm `values.yaml` file generated previously. - -```bash -helm install hello score-helm-charts/workload --values ./values.yaml -``` - -The following are the outputs of the previous command. - -```yml -NAME: hello -LAST DEPLOYED: Wed Nov 1 00:00:00 2022 -NAMESPACE: default -STATUS: deployed -REVISION: 1 -TEST SUITE: None -``` - -The following is the generated Kubernetes deployment object. - -```yaml ---- -# Source: workload/templates/deployment.yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: hello - labels: - helm.sh/chart: workload-0.3.0 - app.kubernetes.io/name: hello - app.kubernetes.io/instance: hello - app.kubernetes.io/version: "0.3.0" - app.kubernetes.io/managed-by: Helm -spec: - selector: - matchLabels: - app.kubernetes.io/name: hello - app.kubernetes.io/instance: hello - template: - metadata: - labels: - app.kubernetes.io/name: hello - app.kubernetes.io/instance: hello - spec: - containers: - - name: hello - image: "busybox" - command: - - /bin/sh - args: - - -c - - while true; do echo Hello $${FRIEND}!; sleep 5; done - env: - - name: FRIEND - value: John -``` From d98a4e52efb51945a1fddc14d026400e4bd9b8ef Mon Sep 17 00:00:00 2001 From: Tobias Babin Date: Thu, 11 Apr 2024 18:00:01 +0200 Subject: [PATCH 2/2] Added aliases for environment variables Signed-off-by: Tobias Babin --- content/en/docs/environment variables/_index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/en/docs/environment variables/_index.md b/content/en/docs/environment variables/_index.md index ff68caa8..7c8e3d47 100644 --- a/content/en/docs/environment variables/_index.md +++ b/content/en/docs/environment variables/_index.md @@ -5,12 +5,13 @@ weight: 5 description: > This section describes how to define environment variables. aliases: -- /environment-variables/environment-variables-humanitec +- /docs/environment-variables/environment-variables-compose/ +- /docs/environment-variables/environment-variables-helm/ --- ## Overview -You can pass environment-specific configuration to the container during a deployment. The Score Specification enables a special environment resource type to be used to support such use cases. +You can pass environment-specific configuration to the container during a deployment. The Score Specification enables a special `environment` resource type to be used to support such use cases. Environment configurations are set within the [`resource`]({{< relref "/docs/score-specification/score-spec-reference" >}} "Container") section of your Score Specification file. These act as environment variables when you're deploying a Workload.