chrisdel101
Error deploying to Fly.io re: file path "could not read file ...no such file or directory"
I’m deploying to flyio using the flyctl launch tool + my app runs locally.
I have a function that reads a file.
def read_json(json_file) do
json_file
|> File.read!()
|> Jason.decode!()
end
It’s called like this (attempt to true relative path):
@json myApp.read_json("./alert_text.json")
or allow elixir to find it as usual:
@json myApp.read_json("alert_text.json")
The alert_text.json file is a root now, but I also tried moving it into the lib folder. No matter what, fly will not find it.
When I run the fly command I get ** (File.Error) could not read file "./alert_text.json": no such file or directory. I have no idea how to make fly find my file.
Is there some kind of function I can use to make it use absolute paths? I’d need to be environment agnostic to work on fly’s system and my local system.
Edit: just looked up Path module. Playing around with absname at the moment.
Marked As Solved
sodapopcan
The /priv dir is where you should store non-source files (if not in TheCloud™) and can be accessed like so:
file =
Path.join([:code.priv_dir(:my_app), "path", "to", "file"])
|> File.read!()
You must use :code.priv_dir/1 because the location changes once built.
Also Liked
sevenseacat
Is that file being copied to your container as part of your Docker build?
al2o3cr
Also consider using the @external_resource attribute to ensure that the module that’s reading that file into @json is recompiled when the JSON file changes.
Popular in Questions
Other popular topics
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









