a year ago
i use filesystem to save my all images. But when i deploy again my file is gone all of the product i have upload is left me just only text..
I think because of the old one would be delete after new deploy
And how should i handle this ?
Use another file system ?
9 Replies
a year ago
The files in your deployment is ephemeral, so it's not possible to store persistent files that way
to store persistent files on Railway, you'd want to use a [volume]()
i have config mount volume in railway setting and fill more 2 varibles follow the docs
and try with upload new image size 3Mb and go back to check size in volume's metric
from my setting in project is when i have upload the file it will upload to 'media' folder
and i config in payload volume path is '/media'
is i correctness config ?
a year ago
Yea, keep in mind though that the /media
folder is not in your app's root by default
I recommend you use RAILWAY_VOLUME_MOUNT_PATH
service variable to get the path of your /media
folder
i try all day but still the same with it unmount sir.
when i try to redeploy all the file is gone again
i try first with '/media' because all the file will save in media folder
second i try with '/app/media' still same result
third i try with '/app' deploy was crashed
a year ago
nah nah, Railway provides the RAILWAY_VOLUME_MOUNT_PATH
themselves, you're not supposed to write that into service variables
okay one last question ;-;)
in my code i executed code to save upload files to folder 'media'
and i mount in railway to '/app/media'
it didn't mean these two directory will sync together when i redeploy and didn't mean the file i have upload will save in mount volume
correct right ?
--- sorry for my bad english, i try so hard to understand both of english and railway sir
a year ago
No problem at all 🙂
If you write a file to RAILWAY_VOLUME_MOUNT_PATH
then it'll store that file in your Volume, this Volume is attached to the docker container when the docker container starts, the volume and its contents will remain intact until you delete it
Meaning to say, anything you write to RAILWAY_VOLUME_MOUNT_PATH
will stay there and your application will be able to access it, all the files will remain there unless you delete them, naturally
( by the way, i say write to RAILWAY_VOLUME_MOUNT_PATH
only out of principal since it's better to the path the service variable gives than just a hardcoded path, but it should work fine the way you have it )
a year ago
if built with nixpacks, yes
a year ago
if built with a dockerfile, it would be whatever the last workdir set it to
10 months ago
I cannot find RAILWAY_VOLUME_MOUNT_PATH
in the "Variables" section, as shown in the attachment. Is there any way to ensure that this env variable has been set right? (when I tried to add it, a pop-up warning message appeared, so I refrained afraid to mess things it up)
I am trying to save files there with the following nodeJS statement: path.join(process.env.RAILWAY_VOLUME_MOUNT_PATH || "./", "db")
and it still doesn't work (the files are removed after new deployments)
Is there any way, at least, to see what's going on the machine disk? I wanna know whether files are saved in `./db` or `RAIL.../db`.
I've already modified the start command, using nixpacks.toml file, to: `
RAILWAY_VOLUME_MOUNT_PATH=$RAILWAY_VOLUME_MOUNT_PATH pnpm start
`
Attachments
10 months ago
you should not be setting that variable anywhere, that variable is automatically available to your code.
10 months ago
I see. Still, I cannot access that variable via process.env in nodeJS. I'm trying to figure out why.
10 months ago
probably because you are overwriting it somewhere
10 months ago
Pretty sure I'm not. I guess I should first add it in the docker file config, using advantage of it's interpolation:
web:
environment:
- RAILWAY_VOLUME_MOUNT_PATH
=${RAILWAY_VOLUME_MOUNT_PATH
}
This's my first time using docker and nixpacks. I'm jumping around between documentations right now.
Attachments
10 months ago
Please stop trying to set it somewhere, you are overwriting it
10 months ago
Tell me where I'm overwriting it!
See the attachment in my previous reply.
10 months ago
This is not overwriting; I'm trying to pass it through a chain of local environments. Even though, if you consider it as overwriting, It doesn't change anything (it overwrites to the same value). Overwriting x to x, for instance, wouldn't change the value of x.
Furthermore, I've removed it from the toml file. And added the following if statement, as shown in the first attachment:
const RAILWAY_PATH = process.env.RAILWAY_VOLUME_MOUNT_PATH;
if (!RAILWAY_PATH || RAILWAY_PATH === '') {
console.warn('RAILWAY_VOLUME_MOUNT_PATH undefined.');
}
The second attachment, however, shows the deploy logs from railway.app dashboard.
Attachments
10 months ago
If you are unable to find out where you are overwriting it you can instead simply use the volume path you set in railway in code.
10 months ago
This is not overwriting; I'm trying to pass it through a chain of local environments. Even though, if you consider it as overwriting, It doesn't change anything (it overwrites to the same value). Overwriting x to x, for instance, wouldn't change the value of x.
Furthermore, I've removed it from the toml file. And added the following if statement, as shown in the first attachment:
const RAILWAY_PATH = process.env.RAILWAY_VOLUME_MOUNT_PATH; if (!RAILWAY_PATH || RAILWAY_PATH === '') { console.warn('RAILWAY_VOLUME_MOUNT_PATH undefined.'); }
The second attachment, however, shows the deploy logs from railway.app dashboard.
I've sent the first one wrong by mistake. Here the right one.
Attachments
10 months ago
If you are unable to find out where you are overwriting it you can instead simply use the volume path you set in railway in code.
The thing is... that I didn't, and I'm definitely not overwriting it. It's not available in the code. It's undefined in process.env
.
You know what. Now I'll overwrite it.