david
TL;DR: How to ensure that file paths specified in a library when compiled in a macro reflect correct paths at release. /app/_build/prod/lib/library_name/priv/ when compiled vs /app/lib/library_name-version/priv/ when released.
Hi there,
Working on an avatar generation library:
Avatarex - Generate unique, reproducible avatars from hashed strings (*hat tip to @Eiji for help in the rewrite)
I’m a bit confused as to how to ensure that the image asset paths which are being generated at compile time, as part of a using macro, reflect where they’ll actually be at runtime.
So paths that are generated at compile time:
:avatarex |> :code.priv_dir() |> Path.join("sets") |> ...
corresponds to locations that exist during compilation:
/app/_build/prod/lib/avatarex/priv/sets/birdy/body/body_1.png
but are different from the paths that are used at runtime:
/app/lib/avatarex-0.2.0/priv/sets/birdy/body/body_1.png
I do need to be able to File.ls the /app/_build/prod/lib/avatarex/priv/sets/birdy/body/ path at compile time to then generate the list of available images in that directory, but then again at runtime they need to look in /app/lib/....
I thought this may also be related to me not understanding how /app/_build/prod/lib becomes /app/lib upon release.
Thanks,
David
Resources I’ve Reviewed:
- Using static files in a library
- build embedded plataformatec blog post
- Wrong path in Elixir after release with distillery
:code.priv_dir(:my_app)points toprivdirectory in_build- Google Groups: What is
priv - SO: Elixir httpserver : priv_dir returns something in _build directory, thus I can’t send static files that are in source directory
- How to include static assets in an Elixir application
- Accessing the priv folder from mix 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 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Eiji
Oh, I see the point. Since paths are not guaranteed to be the same across different environments and releases we were using
:code.priv_dir/1to get a proper path. However we are doing it atcompile timeinprodenvironment and paths were changed inrelease…You should do 2 things:
privdirectory. Since contents ofprivdirectory does not changes we can safely callFile.ls!/1on them.The problem is that
imagesis not the only variable which storespath. You would need to remember when you would update the code.Let me know if you have some questions.