kamal icon indicating copy to clipboard operation
kamal copied to clipboard

feat: Add template argument to envify

Open Zeko369 opened this issue 1 year ago • 2 comments

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

Zeko369 avatar Jun 22 '23 16:06 Zeko369

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 avatar Oct 24 '23 19:10 nickhammond

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.

nickhammond avatar Dec 29 '23 20:12 nickhammond

Closing as we've removed kamal envify in Kamal 2.

djmb avatar Sep 30 '24 07:09 djmb