R
Railway15mo ago
YoPassIt

Tell Nixpack to include public folder in build

I have an Axum build on Rust that is are web socket chat rooms, which also serves static files. When I run the cargo locally everything is fine, but when I deploy to railway the routes all work fine, except for the static file route which I can only tell doesn't work because the Nixpack isn't placing the public folder within the directory. Do I need to manually build a Docker Image, and if so how do I get Railway to use my Docker Image instead of generating a new Image.
28 Replies
Percy
Percy15mo ago
Project ID: N/A
YoPassIt
YoPassItOP15mo ago
N/A
Brody
Brody15mo ago
are you sure you don't have that folder in a gitignore?
YoPassIt
YoPassItOP15mo ago
yes all I had in the git ignore was target
Brody
Brody15mo ago
are you using relative paths when you serve this folder?
YoPassIt
YoPassItOP15mo ago
I placed the public folder in src as well as externally Well in rust its from the crate level so relative to the crate yes
Brody
Brody15mo ago
looks like there's a chance nixpacks is running just the built binary in a slim image, so it's possible the public folder isn't being copied to the final image is it possible for you to just embed that folder into the binary?
YoPassIt
YoPassItOP15mo ago
I believe thats the case. Its just html, css, and js so I have no idea
Brody
Brody15mo ago
it's not clear to me on how to stop nixpacks from doing that, so I propose two options, embed the folder into the binary or write a dockerfile to deploy your app
YoPassIt
YoPassItOP15mo ago
If railway detects a Docker File it will use it automatically?
Brody
Brody15mo ago
yep!
YoPassIt
YoPassItOP15mo ago
okay I'll get to it, by the way it may be wise to detech foldernames with static/public or other common static file folders and just load them into the build directory of the container
Brody
Brody15mo ago
hey you know rust (I don't) so I'm sure that would be a welcome PR (nixpacks is rust)
YoPassIt
YoPassItOP15mo ago
Lol I would love to but I'm not confident in my rust at all. This is actually my first project in it. Just trying to deploy and show it off.
Brody
Brody15mo ago
fair enough
YoPassIt
YoPassItOP15mo ago
But thanks.
Brody
Brody15mo ago
https://github.com/railwayapp/nixpacks/blob/main/src/providers/rust.rs#L181 here's the logic for nixpacks on how it decides to run your binary in a slim image, maybe you can change some things around in your project to get it to stop running it in a slim image?
YoPassIt
YoPassItOP15mo ago
Alright I'll give it a look. I don't mind making a docker image anyways, its not too hard.
Brody
Brody15mo ago
Dockerfile*
YoPassIt
YoPassItOP15mo ago
yes, that's what i meant Hey how do ports work with Nixpacks, do I just put any port as the env in the Dockerfile and will the Nixpack just be smart it enough to map it to the one they're supplying?
Brody
Brody15mo ago
when using a dockerfile nixpacks is not used in anyway shape or form. you do not need to specify any port in the dockerfile, you only need to have your app listen on the auto generated PORT variable
YoPassIt
YoPassItOP15mo ago
Well I just gave it 3000 and exposed 3000 and railway figured it out. It works now. https://wscr-rust-axum-production.up.railway.app/ // in case you would like to look
Brody
Brody15mo ago
did you set a PORT variable in the service variables?
YoPassIt
YoPassItOP15mo ago
FROM rust:1.72-alpine AS build

WORKDIR /app

COPY . .

RUN apk add --no-cache musl-dev openssl-dev
RUN cargo build --release

COPY ./public ./public

RUN cargo install --path .
RUN cargo build --release

ENV PORT=3000
EXPOSE 3000

CMD ["./target/release/wscr"]
FROM rust:1.72-alpine AS build

WORKDIR /app

COPY . .

RUN apk add --no-cache musl-dev openssl-dev
RUN cargo build --release

COPY ./public ./public

RUN cargo install --path .
RUN cargo build --release

ENV PORT=3000
EXPOSE 3000

CMD ["./target/release/wscr"]
This all I've done. It just works, locally i need to -p port foward it to my computer which is what I thought would be needed to configure it with Railway but it just works
Brody
Brody15mo ago
?
YoPassIt
YoPassItOP15mo ago
What are service variables Like in railway the environment?
Brody
Brody15mo ago
nvm, glad its working!
YoPassIt
YoPassItOP15mo ago
Lol, I didn't set any config in railway. Just deployed it. One click per say.
Want results from more Discord servers?
Add your server