Rust app failing with `No such file or directory`

Basically i am trying to deploy a rust app that needs to read files that are part of the codebase. these files are checked in too. but the app is failing with No such file or directory I am deploying via the cli railway up
43 Replies
Percy
Percy2y ago
Project ID: N/A
Percy
Percy2y ago
It appears that the issue is related to the .nixpacks directory not being able to find the Cargo.toml file.
⚠️ experimental feature
sebastiantf
sebastiantfOP2y ago
N/A the app builds the application fine with the Cargo.toml. But on runtime, it doesnt seem to find a file also railway shell doesn't seem to work even after doing railway link
alex
alex2y ago
run railway -V what version of cli are you running *capital V btw
sebastiantf
sebastiantfOP2y ago
3.0.1
alex
alex2y ago
upgrade 3.0.1 is bugged curl -fsSL https://raw.githubusercontent.com/railwayapp/cli/master/install.sh | bash
sebastiantf
sebastiantfOP2y ago
upgraded to 3.0.3 but railway shell is just opening my own local in a different shell within how to list the directory structure of the deployment? i think theres a mismatch in that
alex
alex2y ago
it is supposed to do that it just injects your env vars into the shell btw for rust just include_as_str!
sebastiantf
sebastiantfOP2y ago
oh i thought its opens a shell in the container. mb
alex
alex2y ago
also railway storage is ephemeral no persistent storage if you need persistent storage spin up a postgres
Brody
Brody2y ago
or use a bucket
sebastiantf
sebastiantfOP2y ago
so programs on railway cannot do a fs read?
Brody
Brody2y ago
yes they can
alex
alex2y ago
they can read, not write i believe
sebastiantf
sebastiantfOP2y ago
i dont want to write
alex
alex2y ago
and between relaunches it will disappear are you using relative file URIs?
Brody
Brody2y ago
they can read and write, its just anything you write gets wiped on next deploy
alex
alex2y ago
oh i misunderstood
Brody
Brody2y ago
no worries
sebastiantf
sebastiantfOP2y ago
.
├── Cargo.lock
├── Cargo.toml
├── README.md
// --snip--
├── config
│   └── log4rs.yaml
├── logs
│   └── logs.log
// --snip--
├── src
│   ├── lib.rs
│   ├── main.rs
// --snip--
└── target
├── CACHEDIR.TAG
├── debug
└── release
.
├── Cargo.lock
├── Cargo.toml
├── README.md
// --snip--
├── config
│   └── log4rs.yaml
├── logs
│   └── logs.log
// --snip--
├── src
│   ├── lib.rs
│   ├── main.rs
// --snip--
└── target
├── CACHEDIR.TAG
├── debug
└── release
basically this is the dir structure i am doing railway up from
alex
alex2y ago
where is the file
sebastiantf
sebastiantfOP2y ago
the rust app is trying to read ./config/log4rs.yaml
alex
alex2y ago
ok erm
sebastiantf
sebastiantfOP2y ago
i tried logging the path its trying to access and it prints this: path: "/app/config/log4rs.yaml"
alex
alex2y ago
IDK how nixpacks handles that stuff can you ls the foldr see if the file is even there lmao
sebastiantf
sebastiantfOP2y ago
let mut path = PathBuf::new();
path.push(std::env::current_dir().unwrap());
path.push("config/log4rs.yaml");
println!("path: {:#?}", path);
log4rs::init_file(path, Default::default()).unwrap();
let mut path = PathBuf::new();
path.push(std::env::current_dir().unwrap());
path.push("config/log4rs.yaml");
println!("path: {:#?}", path);
log4rs::init_file(path, Default::default()).unwrap();
this is the code for that i dont know how to do that. i was hoping railway shell logs me into that deployment container. but it doesnt
alex
alex2y ago
what kind of persistent application rocket.rs? whats the app even for
sebastiantf
sebastiantfOP2y ago
its basically just a web server but i am using log4rs and reading its config from that file
alex
alex2y ago
hmm no clue then
sebastiantf
sebastiantfOP2y ago
looking at the build logs, i suppose railway only copies the final executable from the build into the docker image and runs that. that doesn't include any of the other files
alex
alex2y ago
thats what i thought you should use the rust macro include_as_str!("path"); it will... include the file as an &str
sebastiantf
sebastiantfOP2y ago
can you point me to a doc for that? couldnt find it googling
alex
alex2y ago
nvm im studipd istits just include_str!(); i made a goof my bad
alex
alex2y ago
This macro will yield an expression of type &'static str which is the contents of the file.
sebastiantf
sebastiantfOP2y ago
but it still needs to read the file doesnt it?
alex
alex2y ago
it will do it during build time macro will expand during build
sebastiantf
sebastiantfOP2y ago
oh okay. let me try
alex
alex2y ago
gl
sebastiantf
sebastiantfOP2y ago
awesome! that worked. thnx! 🙏 🙏 altho i suppose i cannot use any kind of variable or env var for the path in include_str can I? i was planning to move that config file path to an env var or something
Brody
Brody2y ago
sure you can maybe not with include_str, but you can read the string from the env variable
sebastiantf
sebastiantfOP2y ago
yeah include_str requires it to be string literal
alex
alex2y ago
if you do it with env var nothing will change because the file will be sucked up at build time and rust will not care at all
Want results from more Discord servers?
Add your server