bright-policeman-43626
05/21/2024, 1:29 AMCould not find key var. Available keys: command, datetime, git, local, project and secrets.
I'm basically trying to build a variable that contains other 3 like:
POSTGRES_SCHEMALESS_CONNECTION_STRING: postgres://${var.POSTGRES_USERNAME}:${var.POSTGRES_PASSWORD}@postgres-edge-api-cc:5432/${var.POSTGRES_DATABASE}
microscopic-river-74022
05/21/2024, 1:29 AMmicroscopic-river-74022
05/21/2024, 1:29 AM${var.*}
syntax to reference variables in your configuration files. However, the error message you're seeing suggests that the keys you're trying to reference (POSTGRES_USERNAME
, POSTGRES_PASSWORD
, POSTGRES_DATABASE
) are not available.
The available keys for variable interpolation in Garden are context-dependent. For example, in the Project configuration context, you have access to keys like local.*
, project.*
, etc. You can find more details about the available keys in different contexts in the Template Strings Reference ().
In your case, it seems like you're trying to use project variables. You can define these in the variables
field in your project configuration, or in a varfile. Here's an example of how you might define these variables in your project.garden.yml
file:
yaml
kind: Project
name: my-project
variables:
POSTGRES_USERNAME: my-username
POSTGRES_PASSWORD: my-password
POSTGRES_DATABASE: my-database
Once these variables are defined, you should be able to reference them in your POSTGRES_SCHEMALESS_CONNECTION_STRING
variable as you're trying to do.
If you're still having trouble, make sure that the variables are defined in the correct context and that there are no typos in the variable names. If the variables are defined in a different context (e.g., a specific module or environment), they may not be available in the project context.
Also, note that the order of precedence for variables is as follows (from highest to lowest):microscopic-river-74022
05/21/2024, 1:29 AM--var
CLI flags.
2. The module/action-level varfile (if configured).
3. Module/action variables set in module.variables
.
4. The environment-specific varfile (defaults to garden.<env-name>.env
).
5. The environment-specific variables set in environment[].variables
.
6. Configured project-wide varfile (defaults to garden.env
).
7. The project-wide variables
field.
You can find more information about using variables in Garden in the Variables and Templating guide ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
05/21/2024, 1:29 AMbright-policeman-43626
05/21/2024, 1:35 AMapiVersion: garden.io/v0
can I use a combination of actions and modules?microscopic-river-74022
05/21/2024, 1:35 AMmicroscopic-river-74022
05/21/2024, 1:35 AMapiVersion: garden.io/v0
. This is designed to make it easier to convert projects piece by piece from modules to actions.
Internally, Garden converts modules into actions as follows:
- The build step of a module (if any) becomes a Build action.
- Services become Deploy actions.
- Tests become Test actions.
- Tasks become Run actions.
This means that converting your project to the actions config can be performed gradually by starting from the end of the dependency tree. However, there are some caveats:
- Modules cannot depend on actions
- Modules cannot reference actions
- Actions can reference and depend on modules, by referencing the actions that are generated from modules.
You can find more information about this in the Migrating to Bonsai guide ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
05/21/2024, 1:35 AMbright-policeman-43626
05/21/2024, 1:36 AM"apiVersion" is missing in the Project config. Assuming "garden.io/v0" for backwards compatibility with 0.12. The "apiVersion"-field is mandatory when using the new action Kind-configs. A detailed migration guide is available at https://docs.garden.io/guides/migrating-to-bonsai
Action kinds are only supported in project configurations with "apiVersion: garden.io/v1". A detailed migration guide is available at https://docs.garden.io/guides/migrating-to-bonsai
microscopic-river-74022
05/21/2024, 1:36 AMmicroscopic-river-74022
05/21/2024, 1:36 AMapiVersion
field is missing in your Project configuration. This field is mandatory when using the new action Kind-configs.
In Garden Bonsai (0.13), the apiVersion
field in your project configuration (kind: Project
) should be set to garden.io/v1
. This is a change from Garden Acorn (0.12), where the apiVersion
field defaulted to garden.io/v0
.
Here's an example of how you might update your project configuration:
yaml
apiVersion: garden.io/v1
kind: Project
name: my-project
# rest of your configuration...
Once you've updated the apiVersion
to garden.io/v1
, you should be able to use action kinds in your project configuration. However, note that once you start using apiVersion: garden.io/v1
, team members can no longer use Acorn (0.12
) as it does not recognize apiVersion: garden.io/v1
. Therefore team members are forced to update to Bonsai (0.13
).
For more information on migrating to Bonsai and using the new action Kind-configs, you can refer to the Migrating to Bonsai guide ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------microscopic-river-74022
05/21/2024, 1:36 AMbright-policeman-43626
05/21/2024, 1:45 AMkind: Module
description: Postgres container for storing db
type: container
name: postgres
image: postgres:13-alpine
include: [./modules.garden.yml]
services:
- name: postgres
volumes:
- name: data
containerPath: /db-data
ports:
- name: postgres
containerPort: 5432
env:
POSTGRES_DATABASE: ${var.POSTGRES_DATABASE}
POSTGRES_USERNAME: ${var.POSTGRES_USERNAME}
POSTGRES_PASSWORD: ${var.POSTGRES_PASSWORD}
healthCheck:
command: [psql, -w, -U, "${var.POSTGRES_USERNAME}", -d, "${var.POSTGRES_DATABASE}", -c, "SELECT 1"]
microscopic-river-74022
05/21/2024, 1:45 AMmicroscopic-river-74022
05/21/2024, 1:45 AMyaml
# Build action for the Postgres container
---
apiVersion: garden.io/v1
kind: Build
type: container
name: postgres
description: Postgres container for storing db
image: postgres:13-alpine
include: [./modules.garden.yml]
# Deploy action for the Postgres service
---
apiVersion: garden.io/v1
kind: Deploy
type: container
name: postgres
description: Postgres service for storing db
build: postgres
spec:
volumes:
- name: data
containerPath: /db-data
ports:
- name: postgres
containerPort: 5432
env:
POSTGRES_DATABASE: ${var.POSTGRES_DATABASE}
POSTGRES_USERNAME: ${var.POSTGRES_USERNAME}
POSTGRES_PASSWORD: ${var.POSTGRES_PASSWORD}
healthCheck:
command: [psql, -w, -U, "${var.POSTGRES_USERNAME}", -d, "${var.POSTGRES_DATABASE}", -c, "SELECT 1"]
In this conversion:
- The kind: Module
configuration is split into two separate actions: a kind: Build
action for building the Postgres container, and a kind: Deploy
action for deploying the Postgres service.
- The services
field from the module configuration is moved to the spec
field in the kind: Deploy
action.
- The image
field from the module configuration is moved to the kind: Build
action.
- The apiVersion
field is added to both actions, with the value garden.io/v1
.
Remember to replace ${var.POSTGRES_DATABASE}
, ${var.POSTGRES_USERNAME}
, and ${var.POSTGRES_PASSWORD}
with the actual values or define them in the variables
field in your project configuration.microscopic-river-74022
05/21/2024, 1:45 AM