mbecker20 / komodo

🦎 a tool to build and deploy software on many servers 🦎
https://komo.do
GNU General Public License v3.0
1.86k stars 35 forks source link

[Feature] Default environment variables #191

Open em411 opened 2 days ago

em411 commented 2 days ago

Description

Currently, when creating a new stack in Komodo, the Environment form section provides a basic placeholder format # VARIABLE = value. While this is helpful for beginners, it's not so useful for advanced users who frequently use the same environment variables across different stacks.

Suggested Solution

Add a "Default" checkbox option in the variables settings that allows users to:

Use Case

Example images

image image

mbecker20 commented 1 day ago

Reminds me of #28

em411 commented 1 day ago

Default vars and global vars, while seemingly similar, serve distinct purposes and would complement each other rather than be interchangeable.

Default vars act as a template/preset for new stack initialization, where users expect to modify values per stack's specific needs. For example, having a default value for DOMAIN pointing to internal domain name is useful as a starting point, but some stacks will need to change it to external domain for public facing services. The main difference is that updating default vars doesn't affect existing stacks - it only applies to new ones, making it a simpler, more predictable feature.

Global vars, on the other hand, should function (in my opinion) as a singleton that affects all stacks uniformly, both existing and new. When you update a global var, the change propagates automatically across all stacks, making it a more complex feature that requires proper state management and update handling. This behavior is essential for values that should remain consistent across your application, like API keys or base path for bind mount directory.

Another advantage of default vars is that they serve as documentation of common configuration patterns. Users can quickly understand the expected environment structure by looking at the default template, while still maintaining the freedom to adjust values as needed.

In essence, default vars focus on initialization convenience while preserving stack independence, whereas global vars emphasize unified configuration management across all stacks.

mbecker20 commented 1 hour ago

Yeah I understand. I realize there is an existing usage pattern available that should satisfy your use case and more, call it the template pattern.

You may have noticed every Resource in Komodo has a "Copy" button available, you just enter a new name and it keep the same config. You can leverage this by creating template resources thats only use is as the source resource with the Copy api.

For example, create a new Deployment just called "template", and add the environment variables you want as defaults there. When you want to create a new Deployment, just navigate to the template use the Copy button.

While it is slightly less convenient to have to navigate to the template before creation, I don't think this impact is big (it takes seconds using the Search). Additionally, this pattern has several advantages:

  1. You can create multiple templates for different systems you manage, each with their own defaults.
  2. In addition to Environment, you can default other config parameters such as Network, Restart Mode, or Labels.
  3. You can create a ResourceSync pointing to your template resources, version them with git, and use GitOps to manage your templates over time.

You can also leverage the simple API available for all resources to create new resources from template resources for automations, for example can use this call in an Action:

komodo.write("CopyDeployment", { name: "my-new-deployment", id: "template" })

Overall I think universal configurable defaults is not adding enough value to justify this feature in addition to the template pattern. Please try out this pattern for your use case and let me know any difficulties you come across, and we can re-asses how to make this process more straightforward.

Already I see one way, which I will implement: When you click "New ..." buttons, currently you input the Name and hit create. Right below the name, can have a selector allowing to choose from your resources to copy from. Can also mark a resource as default for the template. The flow of this solution should be very similar to what you are looking for.