gcauchon
Good afternoon folks
I’ve been playing around with LiveView for a few days now and I have to admit it’s changing my approach to many use cases for client projets!
There is one thing I can wrap my head around: configuration for the production release; let me explain…
- In our actual way of packaging releases in Docker images, following 12-Factor App principles, the
Plug.Sessiongets it’skeyandsigning_saltoptions from environment variables withApplication.get_env/3.
- The
LiveViewdocumentation says to extract the@session_optionsto a module attribute…
As module attribute, options are expanded at compile time! It works locally for development purposes since the same variables are used at both compile time and runtime, but breaks during the docker build… of the CI workflow because SESSION_KEY and SIGNING_SALT are not available!
I looked at the code in Phoenix and Plug.Session to understand if there is a different way to configure the socket session callback, but came out clear the
session needs to be a Map…
Is it considered good practice to bake the session key and signing_salt in a version binaries, meaning we would have to build a new Docker image to change those value?
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
gcauchon
@chrismccord, @josevalim, @snewcomer I’m curious to get your opinion on ^this?
chrismccord
On Phoenix master we allow the session connect_info to be an MFA, so stay tuned.
gcauchon
Did a little research for reference to anyone finding this post in the future!
Here’s the code in
Phoenix.Socket.Transportto support a{MFA}3-tuple to initialize the session configuration:phoenix/lib/phoenix/socket/transport.ex at main · phoenixframework/phoenix · GitHub
The original issue: Missing capability of loading runtime config for Phoenix.Endpoint.socket · Issue #3659 · phoenixframework/phoenix · GitHub
And the pull request adding the feature: Allow setting mfa for loading socket session config by kafaichoi · Pull Request #3668 · phoenixframework/phoenix · GitHub
gcauchon
@chrismccord Even with MFA, it looks like the configuration still is compile time!
The before_compile macro expands to private
do_handler/3functions to match on every HTTP/Socket paths.To generate the list of sockets to loop on,
socket_paths/4invokesPhoenix.Socket.Transport.load_config/2explicitly, thus resolving the MFA, at compile time…gcauchon
A little update on my configuration issue with MFA!
I opened an issue on the Phoenix repo yesterday…
https://github.com/phoenixframework/phoenix/issues/3754
it was fixed 6h later by @josevalim
i-n-g-m-a-r
@gcauchon How do you solve the
plug Plug.Sessioncompile-time problem?It seems this part was solved:
But it does not seem to play nicely with this part:
I try to understand the explanation here:
This part:
But to me this is abracadabra and I’m not sure how this relates to configuring
Plug.Sessionat runtime.Do you have an actual working example of configuring the session at runtime?
(probably startup time is a better term)
gcauchon
I’m not using the “vanilla”
Plug.Sessionconfiguration! Like for many other plugs in the default Phoenix configuration, you hate to useinit/1andcall/2explicitly to bypass the default macro expansion at compile time.I also extracted a
get_options/0function to a separate module to be{m, f, a}compatible and am not using the module attribute because it is not required anymore!lib/foo_web/endpoint.exlib/foo_web/session.exi-n-g-m-a-r
Thank you for this explanation, very useful indeed.
I wonder how
System.get_env/2performance compares to populating the application environment on startup and callingApplication.get_env/3on every request.Not sure whether
System.get_env/2caches results and is also a single ets read once a value becomes available.i-n-g-m-a-r
Thanks again @gcauchon, your solution works like a charm, awesome!
I decided to load session options into the application environment.
Also an inline session module will do the trick.
Configure session at runtime.
gcauchon
I really like the idea of reading environment variables from
Application, notSystem. I will adopt a similar approach for sure