rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Dotenv >=3 Breaks Jets Environment Variables #712

Closed dkobia closed 7 months ago

dkobia commented 9 months ago

Checklist

My Environment

Software Version
Operating System *Nix
Jets ~> 5.0.10
Ruby 3.2.2

Dotenv recently got updated to 3.0.0 and because the version in Jets is not pinned, it upgrades to 3.0.0 which doesn't seem to work well with Jets. I am currently using the parameter store with MY_VARIABLE=SSM

Expected Behaviour

.env.[environment] should update environment variables in the generated lambdas

Current Behavior

Environment variables specified in .env.[environment] are not created

Step-by-step reproduction instructions

Code Sample

--

Solution Suggestion

djolereject commented 9 months ago

What can we do about this until it's resolved? What Jets version is the last one where variables are copied to server? edit: Maybe there is another way of pushing ENV?

jmouka commented 9 months ago

I'm having a similar issue, related to the dotenv update (version 3.1.0). Basically the env files are not correctly overwriting, it's keeping the first value set, eg .env.development -> FOO=123 .env.development.local -> FOO=abc

After loading, I have ENV['FOO'] -> 123 (first value set).

My environment Ruby 3.2.2 Jets version: 4.0.10 dotenv version: 3.1.0

I "fixed" it by specifying the dotenv version in the project's Gemfile, so it loads the older version before Jets, eg

gem 'dotenv', '~> 2.8.1'
gem "jets", "~> 4.0.3"
djolereject commented 9 months ago

My issue is more like the OP mentioned - I don't get any values in production. I moved variables from .env.production to .env, and when I check them out through JETS_ENV=production jets console I can see them, but in the actual app they are not there. I first noticed that I can't access ENV value in one of the initializers, but when I removed it from there, I just got an error "Missing secret_key_base for 'production' environment, set this string with bin/jets credentials:edit". So it appears no ENV values are getting copied and I have no clue if it's the same issue as this one.

jmouka commented 9 months ago

I tried deploying with Dotenv 3.1.0 and I see the same (or similar) issue; my Lambdas only get these ENV values: JETS_AWS_ACCOUNT, JETS_ENV, and JETS_STAGE.

Adding gem 'dotenv', '~> 2.8.1' to my project Gemfile fixes it (all ENV values come back).

I haven't dug deeper into why (no time), but definitely an issue with Dotenv >= 3.

pgib commented 9 months ago

Thank you – was wondering why my mailers weren't sending all of the sudden.

djolereject commented 9 months ago

But dotenv 2.8.1 needs Jets < 5 if I'm not wrong. This means that Jets 5 is unavailable at this time?

jmouka commented 9 months ago

But dotenv 2.8.1 needs Jets < 5 if I'm not wrong. This means that Jets 5 is unavailable at this time?

Jets doesn't specify dotenv version (https://github.com/rubyonjets/jets/blob/master/jets.gemspec). I did a quick test and dotenv 2.8.1 is working with Jets 5. My Gemfile is

source "https://rubygems.org"

gem 'dotenv', '~> 2.8.1'
gem "jets", "~> 5.0.0"
gem "importmap-jets"
gem "sprockets-jets"
gem "sassc" # only required if using sass in stylesheets

# Include mysql2 gem if you are using ActiveRecord, remove next line
# and config/database.yml file if you are not

# development and test groups are not bundled as part of the deployment
group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'shotgun'
  gem 'rack'
  gem 'puma'
end

group :test do
  gem 'rspec' # rspec test group only or we get the "irb: warn: can't alias context from irb_context warning" when starting jets console
  gem 'launchy'
  gem 'capybara'
end

I haven't tried deploying, but it runs locally and ENV is working.

djolereject commented 9 months ago

@jmouka Thanks, it's working, I don't know why I thought it's a dependency.