Where is the server’s priv folder on Fly? I’m having trouble finding a file that I hope is being copied correctly during deployment.
For more context, for Metamorphic’s passphrase generator it uses the eff_large_wordlist.txt and subsequent strategy.
The GenServer for this is started in the Application:
...
# Start the word retrieval GenServer API for password generator.
{Metamorphic.Extensions.PasswordGenerator.WordRepository, %{}},
...
Then, there’s a WordLoader file that calls:
# I've also used Application.app_dir(@otp_app, "/priv/dict/eff_large_wordlist.txt")
# with success locally.
@word_list_contents File.stream!(
Path.join(:code.priv_dir(@otp_app), "/dict/eff_large_wordlist.txt")
)
This worked great in deployment with Render and locally. When deploying to Fly I run into the enoent error and that it was looking for the file at /app/_build/prod/lib/<@otp_app>/priv/dict/eff_large_wordlist.txt.
In the Docker file it runs the command COPY priv priv.
My local file structure root priv directory looks like /home/user/github/name/priv.
I’m not super familiar with Docker, but my understanding is that COPY priv priv is copying all the files in my priv folder over to a priv folder for the server on Fly. Is it copying the folder structure? I’ve used both Application.app_dir/2 and :code.priv_dir/1 and both work except for deployment to Fly (which my thinking is because I’m either not copying the file over and/or not finding it correctly).
otp_app = Mix.Project.config()[:app]
version = Mix.Project.config()[:version]
if Mix.env() in [:prod] do
@word_list_contents File.stream!(
"/app/lib/#{otp_app}-#{version}/priv/dict/eff_large_wordlist.txt"
)
else
@word_list_contents File.stream!(
Path.join(:code.priv_dir(otp_app), "/dict/eff_large_wordlist.txt")
)
end
Hmmm…you know, I think the original code I posted was incorrect as that path is no longer used in my code. I think the following might work better and remove the if statement.
Yea, hm I wonder if it has something to do with it trying to build the release? Because it would always return the file path of /app/_build/... whenever using Application.app_dir/2 or :code.priv_dir/1.
Yea thanks! I did a quick test and deployed to Fly with this and it works:
@otp_app Mix.Project.config()[:app]
def load_words do
File.stream!(Path.join(:code.priv_dir(@otp_app), "/dict/eff_large_wordlist.txt"))
...
end
Whereas before I was setting that as an attribute constant:
...
@word_list_contents File.stream!(Path.join(:code.priv_dir(@otp_app), "/dict/eff_large_wordlist.txt"))
def load_words do
word_list_contents
...
end
So, as I’m understanding, when building for the Fly release it compiles the attribute @word_list_contents and then returning the wrong file path of /app/_build/.... I didn’t realize that because when deploying to Render I think it was compiled locally and then sent up (because I never ran into this issue on Render)?