Configure alternate .env files

This is a bit of an odd use case. I used Trellis to deploy a development Vagrant box, and Capistrano to deploy to the server. Got here somewhat randomly experimenting with workflow. The one thing that’s not working for me yet is that each deploy is configured to use a different .env file sitting in the top level of the bedrock directory.

There’s the Capistrano one configured in config/deploy.rb:

set :linked_files, fetch(:linked_files, []).push('.env')

And the one that the Vagrant box is using. Of course they contain different content.

Could someone (@swalkinshaw?) please explain how I can use a different environment file for one of the instances?

Additionally, please remind me where the mariadb/mysql user and password for the Vagrant box are set.

Thank you very much, as always.

Ah! Another Roots aha moment. If I’m understanding this correctly, the Capistrano deploy script is actually not doing anything with the .env file in my local directory because it grabs it from the shared folder on the server. The .env.production file is simply a way of storing that information locally.

However, as I was discovering this, I tried renaming .env.production to .env on the server after:deploy and it didn’t quite work.

At first the error was that .env.production didn’t exist in the deploy/shared directory (light bulb). But then after putting it there, it wasn’t getting pushed into the release directory.

If someone could glance at this bit of the deploy.rb file, I’d love any input that could deepen my understanding of what is happening (even though it’s unnecessary in solving this particular non-problem).

set :linked_files, fetch(:linked_files, []).push('.env.production')

namespace :deploy do

    desc 'Rename .env file'
    task :rename do
        on roles(:app), in: :sequence, wait: 5 do
            # Rename the .env.production file:
             file = release_path + '.env.production'
             new_file = release_path + '.env'
             File.rename(file, new_file)
        end
    end

 end

 before 'deploy:updated', 'deploy:rename'

Why does .env end up in the release directory (when added to :linked_files), but .env.production wasn’t?