Fl4m3Ph03n1x
Background
I have an umbrella project with several apps inside. I want to create a special release that will have additional files inside, like JSON files, configuration, images etc.
I know that in a normal Phoenix project everything inside the priv folder will be in the release under "#{child-app-name}-#{child-app-version}/priv".
Problem
The issue here is that some of my configuration files depend on these assets. So in my config/prod.exs I have tried several ways to get the path dynamically, bu nothing works. The following examples all fail:
config :my_app,
products: "application-data\\lib\\web_interface-#{Application.spec(:web_interface, :vsn) |> to_string()}\\priv\\persistence\\products.json"
config :my_app,
products: "application-data\\lib\\web_interface-#{WebInterface.Mixfile.project()[:version]}\\priv\\persistence\\products.json"
config :my_app,
products: "application-data\\lib\\web_interface-#{Application.get_application(:web_interface)}\\priv\\persistence\\products.json"
The one that works is as follows:
products: "application-data\\lib\\web_interface-2.2.0\\priv\\persistence\\products.json",
You can see the issue here is that the version number will change from release to release, and I don’t want to change my prod.exs every time a new release is made.
My solution would be to move the assets I depend on to the root level, so my configuation can access them via "application-data\\assets\\products.json or something similar.
Questions
Is this possible to achieve, given that I am building a tar in my release?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You should be using
Application.app_dir(:app_name, "priv/dir/…")in your code to reference files inpriv/folder. You can use configuration for the second parameter if needed.entone
Additionally you can use the :code.priv_dir/1 function
LostKobrakai
Yeah, it’s using charlists though and is imo not as nice to work with from elixir.
Fl4m3Ph03n1x
Using:
results in:
If you mean however, that my application code should reference
Application.app_dir(:web_interface, "priv/")then this is not possible. The applications are independent from each other. The only thing each child app requires is a path to a folder with assets.I cannot tie any child app to another app by mentioning the other app’s name in the code. This is not a solution I can implement, which is why I am trying to understand what can be done at the level of releases or
prod.exsfiles.Same applies for
:code.priv_dir.LostKobrakai
You can configure e.g.
{:app_name, rel_path}and transform that toApplication.app_dir/2calls at runtime. That’s e.g. howPlug.Staticis to be configured.Fl4m3Ph03n1x
So, instead of:
I would have:
And then in the code instead of having:
I would instead have:
Correct?
I can see this working.
However, would this be advised over moving the folders inside of the release tar to a new position?
LostKobrakai
That’s the way to go yes.
christhekeele
FWIW these days I register these release-resiliant path concerns in my application’s compile-time
config.exs. I find it to be more reliable and easier to reason about if I do it myself:This works well for umbrella apps, since the each have their own
config :app_namespace.For often-referenced paths, I’ll even add a shortcut in my project’s main entrypoint module:
Then, for example, configuring
Plug.Staticcan look like:LostKobrakai
Tbh that feels a bit bend over backwards to start with relative paths, expand them to absolute paths for the context of the mix project, just to turn them back into relative paths within the application code again. But I do like the approach of having functions return the paths. I’ve used that approach as well in some projects. It puts a clear interface of what paths are provided by an application / which ones are used by downstream consumers.
Fl4m3Ph03n1x
I am generally not comfortable having functions that return configuration settings.
To me, configurations are different from the functionality an application offers, they are a prerequisite and should therefore have their own space, instead of polluting the main API that I expose to the public.
Still, if nothing else works, I will definitely use such approaches, I find code that actually does something better than code that is theoretically more perfect, but then does nothing
Also, thanks @christhekeele for your input. I appreciate you took the time to read all the threads and then took even more time to add your own opinion, even though the topic is becoming long and I had marked it as solved.