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

feat: Add template argument to envify #352

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Zeko369
Copy link

@Zeko369 Zeko369 commented Jun 22, 2023

Closes #351

  • Adds -t argument to envify
  • injects MRSK_DESTINATION so a single template can be used to generate env files for multiple destinations
  • injects MRSK_DESTINATION when loading deploy.yml files

TODO

  • Docs

@nickhammond
Copy link
Contributor

Instead of passing in the template what about instead using .env.destination.erb or .env.template.erb as the default template? Then setup could just be:

  1. Create .env.template.erb and utilize ENV['KAMAL_DESTINATION']
  2. Run kamal envify -d staging
  3. Update .env.staging
  4. Run kamal envify -d production
  5. Update .env.production

@nickhammond
Copy link
Contributor

I ended up working with the current functionality and utilizing ERB to create a template for this, figured I'd share.

.env.template.erb

# Generated by kamal envify on <%= DateTime.now %>, to regenerate run `kamal envify -d <%= destination %>`

DESTINATION=<%= destination %>

# TODO: Fetch credentials with the passed in destination, staging|production for instance. 

.env.staging.erb

<%= 
  destination = "staging"
  ERB.new(File.read(".env.template.erb"), trim_mode: "-").result(binding)
%>

.env.production.erb

<%= 
  destination = "production"
  ERB.new(File.read(".env.template.erb"), trim_mode: "-").result(binding)
%>

When running kamal envify -d staging it'll load .env.staging.erb, set destination to 'staging' and utilize the rest of the template. For each additional environment that you want to envify you then just need a two line file and to set the destination name.

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.

Allow using a single env template for multiple outputs
2 participants