R
Railway2y ago
eg102

how to host python backend with react frontend on railway

Hello, I am new to railway, I am using aiohttp python socketio async server with react frontend. This is error I got: Nixpacks build failed  Nixpacks was unable to generate a build plan for this app. Please check the documentation for supported languages: https://nixpacks.com  The contents of the app directory are: I’ve added a procfile which is : python link to my backend. Is this all I need to add or is there something I am missing. Any help would be appreciated thanks
Getting Started | Nixpacks
App source + Nix packages + Docker = Image
262 Replies
Percy
Percy2y ago
Project ID: N/A
eg102
eg102OP2y ago
N/A
Brody
Brody2y ago
can you share a link to your repo?
eg102
eg102OP2y ago
It’s privated tho it’s basically: Folder1forbackend: Inside> myserver.py Folder2forfrontend: Inside> Folder> just some js and html files: package-lock.json package.json .gitignore file Procfile This is basically exactly how it’s like
Brody
Brody2y ago
create react app?
eg102
eg102OP2y ago
There’s also plenty of other files in the folder 2 file for react But I’m wondering what is the guidelines for hosting this cuz it keeps crashing
Brody
Brody2y ago
? i could give you exact guide lines if i could see the repo
eg102
eg102OP2y ago
damn cuz it’s not just my repo Dk what u mean by this I’ve created a react app yes
Brody
Brody2y ago
using what? create-react-app or vite
eg102
eg102OP2y ago
create-react-app pretty sure
Brody
Brody2y ago
can i see a screenshot of the repo lol you arent giving me much to work with
eg102
eg102OP2y ago
Alr For sure bro lol my bad
eg102
eg102OP2y ago
eg102
eg102OP2y ago
Wanna see something specific
Brody
Brody2y ago
lets focus on getting the frontend running first, so show me a screenshot of the frontend folder
eg102
eg102OP2y ago
Alright
eg102
eg102OP2y ago
eg102
eg102OP2y ago
eg102
eg102OP2y ago
This my package.json
Brody
Brody2y ago
show me a screenshot of your railway project
eg102
eg102OP2y ago
I just added GitHub repo didn’t do anything else
Brody
Brody2y ago
remove the repo
eg102
eg102OP2y ago
Okay
Brody
Brody2y ago
and then show me a screenshot of the project
eg102
eg102OP2y ago
Sorry, what part of the project?
Brody
Brody2y ago
a screenshot of the browser with your project open railway project
eg102
eg102OP2y ago
On my phone dam
Brody
Brody2y ago
on your phone, bro go get a computer
eg102
eg102OP2y ago
aight aight
eg102
eg102OP2y ago
eg102
eg102OP2y ago
No charge that’s my bad
Brody
Brody2y ago
are you not near a computer?
eg102
eg102OP2y ago
Laptop no charge
Brody
Brody2y ago
how are you planning to make changes to the github repo?
eg102
eg102OP2y ago
Ur right bro thought it would be simple Was chilling on my bed
Brody
Brody2y ago
get that laptop plugged in
eg102
eg102OP2y ago
Plugged in 💯
Brody
Brody2y ago
once you got that up and running show me a desktop screenshot of the railway project
eg102
eg102OP2y ago
100% 🙏
eg102
eg102OP2y ago
Brody
Brody2y ago
you have removed repo from that service right
eg102
eg102OP2y ago
yes
Brody
Brody2y ago
google rename that service to frontend
eg102
eg102OP2y ago
ok
eg102
eg102OP2y ago
alr
eg102
eg102OP2y ago
eg102
eg102OP2y ago
is this right?
Brody
Brody2y ago
yes, but show me the full package.json anyway
eg102
eg102OP2y ago
for sure
eg102
eg102OP2y ago
eg102
eg102OP2y ago
eg102
eg102OP2y ago
bro thats all lmao
Brody
Brody2y ago
no its not lmao
eg102
eg102OP2y ago
oh wait sent same screenshot
eg102
eg102OP2y ago
eg102
eg102OP2y ago
my fault
Brody
Brody2y ago
okay in the frontend service set the root directory to /frontend
eg102
eg102OP2y ago
did it
Brody
Brody2y ago
add the repo back to the frontend service
eg102
eg102OP2y ago
taking sum time
eg102
eg102OP2y ago
Brody
Brody2y ago
full build logs please
eg102
eg102OP2y ago
its super long tho
eg102
eg102OP2y ago
Brody
Brody2y ago
get copy pasting
eg102
eg102OP2y ago
eg102
eg102OP2y ago
ok
Brody
Brody2y ago
into a .txt file
eg102
eg102OP2y ago
aight
eg102
eg102OP2y ago
eg102
eg102OP2y ago
☠️
Brody
Brody2y ago
ikr
eg102
eg102OP2y ago
eg102
eg102OP2y ago
wait one sec one sec
eg102
eg102OP2y ago
eg102
eg102OP2y ago
full
Brody
Brody2y ago
your lock file is out of sync, run npm i --package-lock-only
eg102
eg102OP2y ago
ok same exact error
Brody
Brody2y ago
delete the lock file entirely and run that command again
eg102
eg102OP2y ago
aight
eg102
eg102OP2y ago
eg102
eg102OP2y ago
got dis much shorter
Brody
Brody2y ago
run npm install @tensorflow/tfjs-node
eg102
eg102OP2y ago
bro tried to do that got a ton of errors
eg102
eg102OP2y ago
Brody
Brody2y ago
are you even using tesorflow in your frontend app?
eg102
eg102OP2y ago
no backend yea
Brody
Brody2y ago
then why are you importing it in your frontend
eg102
eg102OP2y ago
did i do that?
Brody
Brody2y ago
somewhere
eg102
eg102OP2y ago
ye found it
Brody
Brody2y ago
show me your current package.json please
eg102
eg102OP2y ago
{ "name": "app", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "axios": "^1.3.3", "cors": "^2.8.5", "crypto-js": "^4.1.1", "js-cookie": "^3.0.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.8.0", "react-scripts": "5.0.1", "serve": "^14.2.0", "socket.io-client": "^4.5.4", "web-vitals": "^2.1.4" }, "scripts": { "dev": "react-scripts start", "start": "serve build -s -n -L -p $PORT", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
Brody
Brody2y ago
cool
eg102
eg102OP2y ago
awesome bro thanks a ton btw i hope u getting payed
Brody
Brody2y ago
backend time show me a screenshot of the backend folder in github
eg102
eg102OP2y ago
aight hol on gve me asec Bro is it cool if we do the backend some other time held up by things completely get it if u cant and u busy appreciate u a lot tho man
Brody
Brody2y ago
sure, send that screenshot when you are ready
eg102
eg102OP2y ago
eg102
eg102OP2y ago
@Brody hey this my backend Apologies on taking a long time
Brody
Brody2y ago
what's a pipfile what type of app is your backend?
eg102
eg102OP2y ago
Im using aiohttp
eg102
eg102OP2y ago
eg102
eg102OP2y ago
This is the profile I honestly forgot
Brody
Brody2y ago
aiohttp is nice heres a template i whipped up for you https://github.com/brody192/aiohttp-template
eg102
eg102OP2y ago
ay sup bruh so I added all the files and this is what I got
eg102
eg102OP2y ago
Brody
Brody2y ago
bruh
eg102
eg102OP2y ago
"Treating warnings as errors because process.env.CI = true. #12 19.18 Most CI servers set it automatically. #12 19.18 #12 19.19 Failed to compile. #12 19.19"
Brody
Brody2y ago
no no
eg102
eg102OP2y ago
damn wasup
Brody
Brody2y ago
my template has nothing to do with the frontend
eg102
eg102OP2y ago
ye ik this error is unrelated
Brody
Brody2y ago
show me a screenshot of the contents of the frontend folder i have to double check
eg102
eg102OP2y ago
aight
eg102
eg102OP2y ago
eg102
eg102OP2y ago
didnt add nothing to it bro dw
Brody
Brody2y ago
okay you are safe
eg102
eg102OP2y ago
this the reason i got the error so
Brody
Brody2y ago
so you wanna do the right thing, or the easy thing?
eg102
eg102OP2y ago
i guess easy whatever works
Brody
Brody2y ago
the right thing to do would be to fix the warnings lol im guessing you dont wanna do that
eg102
eg102OP2y ago
hol on how i do
Brody
Brody2y ago
the warnings tell you why they are warnings, just fix them lol
eg102
eg102OP2y ago
oh hell nah
Brody
Brody2y ago
fine
eg102
eg102OP2y ago
bro its so long
Brody
Brody2y ago
lazy way set a service variable CI = false i had to see if youd do the right thing anyway
eg102
eg102OP17mo ago
Bro u there @Brody
Brody
Brody17mo ago
#🛂|readme #5
eg102
eg102OP17mo ago
Sorry bro it’s just I have no idea how to use the template Lol I know it’s been a while my fault
Brody
Brody17mo ago
what template
eg102
eg102OP17mo ago
the aiohttp
Brody
Brody17mo ago
its not public lol keyword: withhold
eg102
eg102OP17mo ago
oh that’s crazy ok
Brody
Brody17mo ago
im assuming you have an aiohttp backend already coded that isnt working?
eg102
eg102OP17mo ago
Nah na it’s working I have a full stack website working But like So I’ve hosted it the way u said actually But just the frontend The backend ain’t working
Brody
Brody17mo ago
you just said it was working
Brody
Brody17mo ago
eg102
eg102OP17mo ago
Nah I mean like in my local host it’s working lol but like when I host it backend not working just frontend
Brody
Brody17mo ago
duh show me screenshot of project in railway please
eg102
eg102OP17mo ago
Yes sir Broo sorry give me exactly 5 mins
Brody
Brody17mo ago
you have 4 and a half
eg102
eg102OP17mo ago
Alr back sending in a bit
eg102
eg102OP17mo ago
eg102
eg102OP17mo ago
here u go bro
eg102
eg102OP17mo ago
Brody
Brody17mo ago
where is the backend?
eg102
eg102OP17mo ago
idk how i did that i just did what u told me fr
Brody
Brody17mo ago
i dont remember what i ate for breakfast yesterday, i dont know what ive told you
eg102
eg102OP17mo ago
onesec
eg102
eg102OP17mo ago
Brody
Brody17mo ago
ahhhh
eg102
eg102OP17mo ago
ye
Brody
Brody17mo ago
mono repo share the repo again
eg102
eg102OP17mo ago
aight
eg102
eg102OP17mo ago
Brody
Brody17mo ago
no like a link to it
eg102
eg102OP17mo ago
alr ima make it public
Brody
Brody17mo ago
i will only spoon
eg102
eg102OP17mo ago
GitHub
GitHub - mrfudgebottom/streamingbear
Contribute to mrfudgebottom/streamingbear development by creating an account on GitHub.
Brody
Brody17mo ago
this says flask server, but the stuff is for aiohttp
eg102
eg102OP17mo ago
yeye lol
Brody
Brody17mo ago
what framework are you using locally
eg102
eg102OP17mo ago
forgot bout that its aiohttp
Brody
Brody17mo ago
change flask-server to just backend then
eg102
eg102OP17mo ago
been trying then gave up dk how bro but its fine honestly can fchange after
Brody
Brody17mo ago
eg102
eg102OP17mo ago
aight
Brody
Brody17mo ago
delete the pycache folder too
eg102
eg102OP17mo ago
aight
Brody
Brody17mo ago
^
eg102
eg102OP17mo ago
broo im actually looking rn google how to do
Brody
Brody17mo ago
"how to rename folder" bro aint no way you googling that
eg102
eg102OP17mo ago
nah on github
Brody
Brody17mo ago
rename is locally push changes
eg102
eg102OP17mo ago
bro im doing on the giothub website dont even have vscoden open☠️
Brody
Brody17mo ago
why you make this harder for yourself
eg102
eg102OP17mo ago
idkkk aight gimme a solid sec
Brody
Brody17mo ago
what makes you think the backend is aiohttp mymachine.py is flask
eg102
eg102OP17mo ago
nah its not check the last couple of lines of code
eg102
eg102OP17mo ago
i did it use it all i can delete that line of code I was using flask in the beginning thats why apologies on the confusion ok done i did it
eg102
eg102OP17mo ago
yes i imported but not running on flask
Brody
Brody17mo ago
remove flask
eg102
eg102OP17mo ago
aightt
Brody
Brody17mo ago
do you use pipfile locally
eg102
eg102OP17mo ago
i believe so
Brody
Brody17mo ago
well pick one, pipfile or requirements.txt one has to go
eg102
eg102OP17mo ago
ok one second im gonna check if it works ok without it
Brody
Brody17mo ago
it wont whatever you choose, you are missing a whole lot of dependencies from either file type ^
eg102
eg102OP17mo ago
well requirements.txt
Brody
Brody17mo ago
okay then delete the pipfiles
eg102
eg102OP17mo ago
nah i mean ill keep the pipfile and del requirement
Brody
Brody17mo ago
gotcha
eg102
eg102OP17mo ago
done
Brody
Brody17mo ago
well now add all the needed deps to your pipfile
eg102
eg102OP17mo ago
just these two: aiohttp==3.8.4 gunicorn==20.1.0 not sure how to do
Brody
Brody17mo ago
you choose pipfile without knowing how to do it??
eg102
eg102OP17mo ago
nah btw i didnt add requirements.txt remember u told me to add it
Brody
Brody17mo ago
^
eg102
eg102OP17mo ago
Done @Brody Been extremely busy
Brody
Brody17mo ago
how many times i gotta tell you, no pings
eg102
eg102OP17mo ago
alr never again Would super appreciate the next couple steps bro
Brody
Brody17mo ago
you have caught me at a bad time, i am about to head out for a few hours
eg102
eg102OP17mo ago
oh, thats completely fine np👍
Brody
Brody17mo ago
in the railway.json file, change the start command to gunicorn mymachine:app --worker-class aiohttp.GunicornWebWorker --workers 3
eg102
eg102OP17mo ago
aight just saw this now my bad done
Brody
Brody17mo ago
whats your root dir set to in the service settings
eg102
eg102OP17mo ago
one sec /frontend
Brody
Brody17mo ago
screenshot of whole project please
eg102
eg102OP17mo ago
eg102
eg102OP17mo ago
Brody
Brody17mo ago
ah we haven't created a service for the backend yet
eg102
eg102OP17mo ago
yea
Brody
Brody17mo ago
well go ahead and add an empty service
eg102
eg102OP17mo ago
dam how can i do that im unfamiliar
Brody
Brody17mo ago
the + New button
eg102
eg102OP17mo ago
u mean new project?
Brody
Brody17mo ago
no
eg102
eg102OP17mo ago
eg102
eg102OP17mo ago
u mean + new variable? yeah alr
Brody
Brody17mo ago
no new service blank service
eg102
eg102OP17mo ago
alr just one question where should I click?
Brody
Brody17mo ago
start by closing that service lol
eg102
eg102OP17mo ago
aiiiight yoyooy i found it
eg102
eg102OP17mo ago
Brody
Brody17mo ago
give it a name
eg102
eg102OP17mo ago
aight bro
Brody
Brody17mo ago
and set the root dir to /backend
eg102
eg102OP17mo ago
bet
Brody
Brody17mo ago
then add your github repo
eg102
eg102OP17mo ago
been deploying for sum time should i have patience bro failed
eg102
eg102OP17mo ago
Brody
Brody17mo ago
remove the healthcheck from railway.json
eg102
eg102OP17mo ago
alr it "Crashed" shoulkd i just restart its asking me if I wanna oh damn nvm worked now crashed again for some reason
Brody
Brody17mo ago
you should send the deploy logs
eg102
eg102OP17mo ago
Yo it’s super long but this error is repeating a ton of times: File "/app/mymachine.py", line 1, in <module> from dotenv import load_dotenv ModuleNotFoundError: No module named 'dotenv Hold on I’ll fix it
Brody
Brody17mo ago
I mean with railway you don't even need .env files but remember when I said this lol
eg102
eg102OP17mo ago
Yeah nah it’s just that I imported so many things that I’m not using at all e "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/app/mymachine.py", line 6, in <module> import numpy as np ModuleNotFoundError: No module named 'numpy Now got this
eg102
eg102OP17mo ago
Alr bro so I’m gonna continue when I wake up cuz super late for me rn 👍 Appreciate u a lot 🙏 Bro for some reason ton of my imports it’s not found. Should i add them to my pipfile somehow and then it’ll work?
Brody
Brody17mo ago
that is what I said to do ^
eg102
eg102OP17mo ago
done
Brody
Brody17mo ago
you said that last time lol
eg102
eg102OP17mo ago
nah 100% hol on onesec bro so webserver detected but i got a long error [2023-07-26 18:16:54 +0000] [41] [INFO] Worker exiting (pid: 41) [2023-07-26 18:16:54 +0000] [1] [WARNING] Worker with pid 42 was terminated due to signal 15 [2023-07-26 18:16:54 +0000] [1] [WARNING] Worker with pid 41 was terminated due to signal 15 [2023-07-26 18:16:54 +0000] [1] [INFO] Shutting down: Master [2023-07-26 18:16:54 +0000] [1] [INFO] Reason: Worker failed to boot. it crashed File "/app/mymachine.py", line 7, in <module> import torch File "/opt/venv/lib/python3.10/site-packages/torch/init.py", line 228, in <module> _load_global_deps() File "/opt/venv/lib/python3.10/site-packages/torch/init.py", line 189, in _load_global_deps _preload_cuda_deps(lib_folder, lib_name) File "/opt/venv/lib/python3.10/site-packages/torch/init.py", line 154, in _preload_cuda_deps raise ValueError(f"{lib_name} not found in the system path {sys.path}") ValueError: libcublas.so.*[0-9] not found in the system path ['/app', '/opt/venv/bin', '/root/.nix-profile/lib/python310.zip', '/root/.nix-profile/lib/python3.10', '/root/.nix-profile/lib/python3.10/lib-dynload', '/opt/venv/lib/python3.10/site-packages'] its something about me importing torch not about it being not found
Brody
Brody17mo ago
does your app require a GPU?
eg102
eg102OP17mo ago
yea im pretty sure
Brody
Brody17mo ago
then it's not gonna work on railway
eg102
eg102OP17mo ago
oh ok
Brody
Brody17mo ago
but double check if it's need the gpu
eg102
eg102OP17mo ago
alr
Brody
Brody17mo ago
and if so, maybe there's a way to tell torch to use cpu only
eg102
eg102OP17mo ago
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") model.to(device) i have this. Means if the device has gpu then use that if not then use cpu
Brody
Brody17mo ago
well it's not defaulting to cpu it would seem but try a nixpacks.toml file with this in it
[phases.setup]
nixPkgs = ["...", "cudaPackages.libcublas"]
[phases.setup]
nixPkgs = ["...", "cudaPackages.libcublas"]
eg102
eg102OP17mo ago
aiight in backend folder?
Brody
Brody17mo ago
yes
Want results from more Discord servers?
Add your server