diff --git a/README.md b/README.md index f3700fab..97995caa 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,8 @@ MYSQL_ROOT_PASSWORD=<%= `op read "op://Vault/My App/MYSQL_ROOT_PASSWORD" -n --se This template can safely be checked into git. Then everyone deploying the app can run `mrsk envify` when they setup the app for the first time or passwords change to get the correct `.env` file. +If you need separate env variables for different destinations, you can set them with `.env.destination.erb` for the template, which will generate `.env.staging` when run with `mrsk envify -d staging`. + ## Commands ### Running commands on servers diff --git a/lib/mrsk/cli/main.rb b/lib/mrsk/cli/main.rb index 1ebb9552..c204a9c8 100644 --- a/lib/mrsk/cli/main.rb +++ b/lib/mrsk/cli/main.rb @@ -104,9 +104,13 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base end end - desc "envify", "Create .env by evaluating .env.erb" + desc "envify", "Create .env by evaluating .env.erb (or .env.staging.erb -> .env.staging when using -d staging)" def envify - File.write(".env", ERB.new(IO.read(Pathname.new(File.expand_path(".env.erb")))).result) + if destination = options[:destination] + File.write(".env.#{destination}", ERB.new(IO.read(Pathname.new(File.expand_path(".env.#{destination}.erb")))).result) + else + File.write(".env", ERB.new(IO.read(Pathname.new(File.expand_path(".env.erb")))).result) + end end desc "remove", "Remove Traefik, app, and registry session from servers"