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

Feature Request: Implement config:import Command for Configuration from .env File #6846

Open
lasroun opened this issue Apr 19, 2024 · 5 comments

Comments

@lasroun
Copy link

lasroun commented Apr 19, 2024

Description of feature

Background:
Currently, setting environment variables in Dokku for an app involves using the dokku config:set command. This method works well for configuring a small number of variables but becomes cumbersome when dealing with a large number of environment variables.

Proposal:
I propose adding a new command, config:import, to the Dokku CLI. This command would allow users to import environment variables from a .env file directly into the Dokku app's configuration. This feature would greatly simplify the process of configuring apps, especially during initial setups or when migrating apps to Dokku.

Expected Behavior:

  1. The config:import command should accept a file path to a .env file as an argument.
  2. Dokku would read this file and set environment variables for the specified app based on the contents of the file.
  3. This command should also handle overwrites of existing variables if they are already set in the app's environment.

Example Command:

dokku config:import <app-name> /path/to/.env

@josegonzalez
Copy link
Member

I think we should also handle:

  • merging the values onto the existing by default. If you have a KEY=VALUE already specified and the .env path has a KEY=VALUE2, we would set KEY=VALUE2
  • --replace: setting this flag would completely replace all existing environment variables. This wouldn't be default, as it would impact usage of stuff like service linking (and maybe we need to overhaul that)
  • This should support stdin via a - (dash) so you could do config:import $APP - to read in env vars. This is particularly useful if the file in question is local and the command is performed via ssh, or if the file is on the host but isn't owned by the dokku user (or otherwise unreadable).

@PapePathe
Copy link

Hey i am have some interest working on this issue. @lasroun what format do you have in mind for the .env file ?

@josegonzalez
Copy link
Member

@PapePathe i think we already import a goenv library, so whatever format that supports is probably lowest friction.

@PapePathe
Copy link

Great, i will look into the source code and see where i can start.

@PapePathe
Copy link

PapePathe commented May 11, 2024

Can you assign the story to me please.

Also i have a couple of questions. On my fork i have the version with dokku config:import <app-name> /path/to/.env working and go tests passing. After making sure the import file is valid, i reused the SetMany function to apply the changes to the app's env.

How do you feel about that? Does the SetMany supports the case of merging the values on the existing by default ?
I do not quite get the stdin support part, but i am interested in adding support for it since it find it very useful.
Given we plan to have the --replace flag should we i using SetMany ?

I think we should also handle:

  • merging the values onto the existing by default. If you have a KEY=VALUE already specified and the .env path has a KEY=VALUE2, we would set KEY=VALUE2
  • --replace: setting this flag would completely replace all existing environment variables. This wouldn't be default, as it would impact usage of stuff like service linking (and maybe we need to overhaul that)
  • This should support stdin via a - (dash) so you could do config:import $APP - to read in env vars. This is particularly useful if the file in question is local and the command is performed via ssh, or if the file is on the host but isn't owned by the dokku user (or otherwise unreadable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants