Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templating to porter config file #1879

Merged
merged 2 commits into from
Feb 1, 2022

Conversation

carolynvs
Copy link
Member

@carolynvs carolynvs commented Jan 28, 2022

What does this change

Support templating in the Porter config file, e.g.
~/.porter/config.json|toml|yaml.

The template syntax uses a yaml-friendly delimiiter, ${}. For example,
${env.NAME} or ${secret.NAME}. If you are using toml or json for your
config file format, then you may need to use quotes around template
values to ensure that the config file has valid syntax when it is
loaded.

We load the config file first with only environment variables
substituted, then we initialize the secrets plugin, and finally do a
second pass of the config file to replace any secrets. So that first
pass needs to be a valid file based on the current format.

For example, in a porter.toml file, secrets should be quoted:

[[storage]]
  name = "dev"
  plugin = "mongodb"

  [storage.config]
    url = "${secret.connection-string}"

Only environment variables and secrets can be substituted. The secrets
are resolved from the default secret storage.

I am implementing this with the liquid template engine (from shopify
that was ported to Go). I don't want us to commit to supporting liquid
templates at this time, it's just an implementation detail that liquid
is used at the moment and it could change later.

Preview of the config documentation at https://deploy-preview-1879--porter.netlify.app/configuration/

What issue does it fix

Closes #1763

Notes for the reviewer

Eventually porter.yaml will transition to this new template delimiter before v1.

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

@carolynvs carolynvs force-pushed the secret-free-config branch 4 times, most recently from 269d979 to c387d58 Compare February 1, 2022 14:41
@carolynvs carolynvs mentioned this pull request Feb 1, 2022
4 tasks
Support templating in the Porter config file, e.g.
~/.porter/config.json|toml|yaml.

The template syntax uses a yaml-friendly delimiiter, ${}. For example,
${env.NAME} or ${secret.NAME}. If you are using toml or json for your
config file format, then you may need to use quotes around template
values to ensure that the config file has valid syntax when it is
loaded.

We load the config file first with only environment variables
substituted, then we initialize the secrets plugin, and finally do a
second pass of the config file to replace any secrets. So that first
pass needs to be a valid file based on the current format.

For example, in a porter.toml file, secrets should be quoted:

```toml
[[storage]]
  name = "dev"
  plugin = "mongodb"

  [storage.config]
    url = "${secret.connection-string}"
```

Only environment variables and secrets can be substituted. The secrets
are resolved from the default secret storage.

I am implementing this with the liquid template engine (from shopify
that was ported to Go). I don't want us to commit to supporting liquid
templates at this time, it's just an implementaiton detail that liquid
is used at the moment and it could change later.

Signed-off-by: Carolyn Van Slyck <[email protected]>
@carolynvs carolynvs marked this pull request as ready for review February 1, 2022 15:31
Copy link
Member

@vdice vdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Excited to use this new functionality 👏

# Defines storage accounts
[[storage]]
# The storage account name
name = "cosmos"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should/can this be "devdb" to match the default-storage value above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops!

It is set with the PORTER_ALLOW_DOCKER_HOST_ACCESS environment variable.

This flag is available for the following commands: install, upgrade], invoke, and uninstall.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This flag is available for the following commands: install, upgrade], invoke, and uninstall.
This flag is available for the following commands: install, upgrade, invoke, and uninstall.

Signed-off-by: Carolyn Van Slyck <[email protected]>
@carolynvs
Copy link
Member Author

/azp run porter-integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carolynvs carolynvs merged commit a93a44a into getporter:release/v1 Feb 1, 2022
@carolynvs carolynvs deleted the secret-free-config branch February 1, 2022 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants