coen.bakker

coen.bakker

I am currently using Ueberauth to allow users to use third-parties to authenticate themselves. I can make the *_CLIENT_ID and *_CLIENT_SECRET available in my dev/test env with, for example:

export GOOGE_CLIENT_ID = "..."
export GOOGLE_CLIENT_ID = "..."

But how can I prevent having to export the variables with each new shell session?

Maybe I have taken a wrong approach to setting the env variables altogether? What is the recommended way to make them available to a dev/test environment?

Showing Posts 1 to 10

coen.bakker

coen.bakker OP

Is it common to add a shell script somewhere? I see that Fly.io generated an env.sh.eex to export some variables. Should I do the same? Not sure how to run that before each compile, however…

sodapopcan

sodapopcan

For development, the answer is probably to use direnv.

Personally, I just make myself a shell script in the root directory that I call dev that has the following as a bare minimum.

#!/usr/bin/env bash

source .env

case $@ in
  c)
    iex -S mix
    ;;

  *)
    iex -S mix phx.server
    ;;
esac

Then just ./dev to start the dev server.

For production is dependent on how you deploy, of course.

coen.bakker

coen.bakker OP

This is great. Thank you.

For production I use Fly.io. You can set “secrets” with their cli and on their website.

D4no0

D4no0

Or you can create an additional config file that you will add to gitignore and import from dev.exs or test.exs.

coen.bakker

coen.bakker OP

Is that was dev.secrets.exs was/is?

D4no0

D4no0

I mean there is no convention, but yeah, I’ve seen this used in a few projects.

coen.bakker

coen.bakker OP

I’ve seen it around also.

I got the impression that it used to be generated in Phoenix apps in a previous version of the phx generator. See for example here: https://stackoverflow.com/q/68239156.

But thanks again. :raised_hands:

pdgonzalez872

pdgonzalez872

My 2c: I tent to prefer explicitness for env vars, rather than having things magically get loaded. I’ve seen and used this mechanism before:

export $(cat .env | xargs) && mix phx.server

direnv works well, but assumes folks have it set up (most do). The above is more explicit in my opinion. I don’t mind the verbosity, mostly due to me rarely having to type that out (always on a readme or in a shell history somewhere).

When working with others, there is usually something on the readme that will help (including yourself when you forget :slight_smile: ) As far as the mechanics:

  • There is usually a .env.example that is committed to the repo (example)
  • an entry for an .env file in .gitignore (example)
  • instructions to create your .env file in the readme (example)

If you don’t have a lot of env vars, I’d start with SOME_VAR=your_var mix phx.server and build from that. Then, consider the above if that sounds interesting.

sodapopcan

sodapopcan

I don’t know why I never thought of this—it seems so obvious, lol.

The dev script still comes in handy, at least for one project, where I need to start up multiple nodes. Of course, Docker is probably the “real” answer there, but I’m stubborn. Maybe there is another way? Though this is getting a little off topic of purely ENV vars.

arcanemachine

arcanemachine

I use (and love) direnv, but for working with others, I find that dotenvy is a good solution with less friction than direnv.

It’s another dependency, but it gets rolled in with the others when you run mix deps.get. Plus it works in all environments, instead of only ones where direnv is installed (CI, shared dev boxes, etc.).

I’ve encountered the custom config.exs strategy mentioned by @D4no0, and I’m not a fan of the concept. Dotenv files are closer to a “universal” configuration system, so that’s a big plus for me. It allows me to share a config system between my Elixir project, my Docker Compose config, etc.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews