You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For production environment I defined the corresponding DATABASE_URL value in .env.production file. Naturally, I want to use that value in production, however, when I run kamal env push -d production, the transferred value corresponds to the development system-wide definition instead of the production one. And this is the expected behavior since dotenv precedence works that way.
There are some workarounds. One option is to directly write the right value into the .kamal/env/my-service-production.env file using ssh. However, this makes env push command meaningless. I could also use database.yml locally and DATABASE_URL on the server. Write a script to temporarily redefine, push, and restore env var is another solution. Deploying using Github Actions can help too, but the main issue remains: there seems to be no way to use the same variable names on the environment that runs Kamal and the destination server.
I think a convenient alternative could be to include the env: file option in the deploy.[env].yml file, exclusively or in combination with current clear/secret options.
If you see any option to solve this with the current Kamal features and settings, I will be grateful for your comments.
Best!
Edit: script calling Dotenv.overload() Run as: bin/deploy_env push -d production
#!/usr/bin/env ruby# frozen_string_literal: truerequire'thor'require'dotenv'classDeployEnv < Thordesc'push','Wrapper for kamal env push command'method_option:destination,aliases: '-d',required: true,desc: 'Specify destination for environment file (.env.[DESTINATION])'defpushDotenv.overload(".env.#{options[:destination]}")`kamal env push -d #{options[:destination]}`endendDeployEnv.start
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I use DevContainer for all my projects, using a template setup, and always setting the database connection with
DATABASE_URL
environment variable.Below is the env section for
deploy.yml
file I use:For production environment I defined the corresponding
DATABASE_URL
value in.env.production
file. Naturally, I want to use that value in production, however, when I runkamal env push -d production
, the transferred value corresponds to the development system-wide definition instead of the production one. And this is the expected behavior sincedotenv
precedence works that way.There are some workarounds. One option is to directly write the right value into the
.kamal/env/my-service-production.env
file using ssh. However, this makesenv push
command meaningless. I could also usedatabase.yml
locally andDATABASE_URL
on the server. Write a script to temporarily redefine, push, and restore env var is another solution. Deploying using Github Actions can help too, but the main issue remains: there seems to be no way to use the same variable names on the environment that runs Kamal and the destination server.I think a convenient alternative could be to include the
env: file
option in thedeploy.[env].yml
file, exclusively or in combination with current clear/secret options.If you see any option to solve this with the current Kamal features and settings, I will be grateful for your comments.
Best!
Edit: script calling
Dotenv.overload()
Run as:bin/deploy_env push -d production
Beta Was this translation helpful? Give feedback.
All reactions