Skip to content

[BUG] Use .env.local and .env.test #23

Open
@fbuys

Description

@fbuys
Contributor

IMPORTANT: please make sure you ask yourself all intro questions and fill all sections of the template.

Before we start...:

  • I checked the documentation and found no answer
    I checked to make sure that this issue has not already been filed
    I'm reporting the issue to the correct repository (for multi-repository projects)

Expected behavior:

Create a Rails app using this template.
Add ENV to the .env.sample file.
And be able to run the app with foreman or docker.

Actual behavior:

Running a newly created app (based on this template) does not run in docker or foreman.

Steps to reproduce:

  1. I create a rails app using this template.
  2. I add a few ENV entries into the .env.sample file.
  3. Then I run the setup script.
  4. Then I try to run the app in docker or with foreman.
  5. But the app does fails to run.

Context and environment:

From this issue: fastruby/dotenv_validator#46
And this PR: fastruby/dotenv_validator#51

The issue was that foreman and docker-compose would automatically parse any .env files present in the project and populate the environment variables before the Rails app could run, but with no treatment of comments and blank spaces. As a result, when dotenv parsed the file, since the variables would already be populated by docker, it would not change them and, because of this, dotenv_validator validated environment variables that included any blank spaces or comments present in the .env files.

This caused dotenv_validator to fail even for environment variables that should pass.

More details can be found in the changes to the README of dotenv_validator here. After this change we can now successfully run the app in docker and locally with foreman without dotenv_validator failing.

We want to make these changes:
Add this to .gitignore

.env.local
.env.test

Add to bin/setup

unless File.exist?(".env.local")
  cp ".env.sample", ".env.local"
  system! "ln -s .env.local .env.test"
end

I will abide by the [code of conduct] (CODE_OF_CONDUCT.md)

Activity

added
bugSomething isn't working
on Dec 8, 2021
arielj

arielj commented on Dec 9, 2021

@arielj
Contributor

I'm not sure if this is needed here, the rails-template does not reference foreman anywhere. I guess it makes sense if we first make the rails-template create the docker-compose or forman configs.

fbuys

fbuys commented on Dec 10, 2021

@fbuys
ContributorAuthor

Sure @arielj that makes sense.
I thought making this change could be useful because it works without docker-compose or foreman.

Do you think there is a reason not to make use of the .local and .test whether we introduce docker-compose or foreman now?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @arielj@fbuys

        Issue actions

          [BUG] Use .env.local and .env.test · Issue #23 · fastruby/rails-template