Trouble deploying Flask app on separate folder

Hey, so I am new to Railway and I built an app with a Flask backend and a frontend in Svelte and I am facing some issues on deployment from my repo. Here is my repo: https://github.com/ssantoshp/inhouse/tree/main I am pretty sure there is a way to solve my problem easily but I just tried a bunch of things and none of them really worked well. So, from my understanding the building should only happen from my api folder but when I set "Root directory" to /api" it seems like I cannot find my html templates from the client folder. I think there is something that is missing in what I am doing. I tried setting the "Root directory" to / and then doing cd api && gunicorn --timeout 300 "main:app" --threads 4 but then the app is unable to build because it doesnt how to build this (the / directory). Thanks!
85 Replies
Percy
Percy2y ago
Project ID: ab00c838-3b0f-46a2-af19-7ddc8661e5c6
Santosh
Santosh2y ago
ab00c838-3b0f-46a2-af19-7ddc8661e5c6
Brody
Brody2y ago
this is a mono repo with two apps, a backend and a frontend, this means you need two railway services, and you would set the root directory to use either /frontend or /backend respectively and for these two types of apps, you should not be specifying any build or start commands in their service settings
Santosh
Santosh2y ago
ok but am I able to keep the same domain name for both? or do I make one for the api and one for the frontend?
Brody
Brody2y ago
no, you would have domain.com for the frontend and api.domain.com for the backend i can understand the desire for the same domain, but its a bit of a hassle and not worth it in my opinion
Santosh
Santosh2y ago
ok, thats my first doing time doing this but just out of curiosity is it common practice do deploy 2 apps or is just due to railway? yup that makes sense
Brody
Brody2y ago
yep two apps, two services
Santosh
Santosh2y ago
perfect thanks for the quick reply!
Brody
Brody2y ago
i will say, your backend is missing a Procfile
Santosh
Santosh2y ago
oh yeah right, I used to have one ill push it too
Brody
Brody2y ago
web: gunicorn --timeout 300 --threads 4 main:app
web: gunicorn --timeout 300 --threads 4 main:app
Santosh
Santosh2y ago
thanks!
Brody
Brody2y ago
hey are you having some troubles getting your frontent online?
Santosh
Santosh2y ago
hey! yes I am It keeps doing
#10 598.6 npm WARN config production Use `--omit=dev` instead.

#10 599.3
#10 599.3 > [email protected] install
#10 599.3 > npm install --omit=dev
#10 599.3

#10 598.6 npm WARN config production Use `--omit=dev` instead.

#10 599.3
#10 599.3 > [email protected] install
#10 599.3 > npm install --omit=dev
#10 599.3

And it eventually times out I've seen that doing npm install --omit=dev in my package.json usually solve the npm WARN but it still fails
Brody
Brody2y ago
you can ignore that warning, and remove the install script
Santosh
Santosh2y ago
hmm how can I do that?
Brody
Brody2y ago
just delete line 12 in your package.json
Santosh
Santosh2y ago
oh yeah but thats what I did originally I didnt have any install script and then I tried adding npm install --omit=dev
Brody
Brody2y ago
have you set any build or start commands in your service settings
Santosh
Santosh2y ago
no
Brody
Brody2y ago
good
Santosh
Santosh2y ago
just Root directory to /client build and start are left empty
Brody
Brody2y ago
perfcet
Santosh
Santosh2y ago
retried and it deployed, I guess i need to change start to make it display the page?
Brody
Brody2y ago
run npm i serve and then change your start script to serve public -s -n -L -p $PORT
Santosh
Santosh2y ago
Brody
Brody2y ago
^
Santosh
Santosh2y ago
okey do I add npm i serve to my package.json?
Brody
Brody2y ago
the command adds it on its own
Santosh
Santosh2y ago
im confused with npm i serve oh ok got t got it downloading ok updated lets see https://inhouse.up.railway.app/ i just restarted it crashed
Brody
Brody2y ago
you did not do what i said to ^
Santosh
Santosh2y ago
I did, what did I miss? i added this to start and put package.json after npm i serve
Brody
Brody2y ago
the second half of those in instructions
Santosh
Santosh2y ago
its not it? instructions?
Brody
Brody2y ago
instructions
Santosh
Santosh2y ago
Brody
Brody2y ago
that is not the start script
Santosh
Santosh2y ago
oh okk sorry mb
Brody
Brody2y ago
remove it
Santosh
Santosh2y ago
ok done, sorry for the misunderstanding loading now
Brody
Brody2y ago
no worries
Santosh
Santosh2y ago
hmm https://github.com/ssantoshp/inhouse/blob/main/client/package.json here is the package.json but still crashes
Brody
Brody2y ago
show me the logs please
Santosh
Santosh2y ago
yup
-----
> [stage-0 6/10] RUN --mount=type=cache,id=s/c2d07d9f-9c18-4b47-9456-5d7afcfe0769-/root/npm,target=/root/.npm npm ci:
#10 2.116 npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
#10 2.116 npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
#10 2.116 npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
#10 2.116 npm ERR!
#10 2.116 npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
#10 2.116 npm ERR!
#10 2.116 npm ERR! Run "npm help ci" for more info
#10 2.118
#10 2.118 npm ERR! A complete log of this run can be found in:
#10 2.118 npm ERR! /root/.npm/_logs/2023-06-15T02_15_43_693Z-debug-0.log
-----

Dockerfile:20
-------------------
18 | ENV NIXPACKS_PATH /app/node_modules/.bin:$NIXPACKS_PATH
19 | COPY . /app/.
20 | >>> RUN --mount=type=cache,id=s/c2d07d9f-9c18-4b47-9456-5d7afcfe0769-/root/npm,target=/root/.npm npm ci
21 |
22 | # build phase
-------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm ci" did not complete successfully: exit code: 1

Error: Docker build failed
-----
> [stage-0 6/10] RUN --mount=type=cache,id=s/c2d07d9f-9c18-4b47-9456-5d7afcfe0769-/root/npm,target=/root/.npm npm ci:
#10 2.116 npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
#10 2.116 npm ERR! [-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
#10 2.116 npm ERR! [-ws|--workspaces] [--include-workspace-root] [--install-links]
#10 2.116 npm ERR!
#10 2.116 npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
#10 2.116 npm ERR!
#10 2.116 npm ERR! Run "npm help ci" for more info
#10 2.118
#10 2.118 npm ERR! A complete log of this run can be found in:
#10 2.118 npm ERR! /root/.npm/_logs/2023-06-15T02_15_43_693Z-debug-0.log
-----

Dockerfile:20
-------------------
18 | ENV NIXPACKS_PATH /app/node_modules/.bin:$NIXPACKS_PATH
19 | COPY . /app/.
20 | >>> RUN --mount=type=cache,id=s/c2d07d9f-9c18-4b47-9456-5d7afcfe0769-/root/npm,target=/root/.npm npm ci
21 |
22 | # build phase
-------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm ci" did not complete successfully: exit code: 1

Error: Docker build failed
Brody
Brody2y ago
thats not a crash 🙄
Santosh
Santosh2y ago
it failed I meant
Brody
Brody2y ago
your lock file is somehow 2 weeks out of sync
Santosh
Santosh2y ago
oh this I shall update too
Brody
Brody2y ago
run npm i --package-lock-only
Santosh
Santosh2y ago
ok updated oh
Brody
Brody2y ago
for your own sanity please start using vite
Santosh
Santosh2y ago
i heard of it but yeah i will promise
Brody
Brody2y ago
i beg you, please use it
Santosh
Santosh2y ago
how does it help me in this situation?
Brody
Brody2y ago
your public folder is a mess
Santosh
Santosh2y ago
oh ... what part
Brody
Brody2y ago
the part where its not a single page app but you are trying to treat it like one
Santosh
Santosh2y ago
wdym? how do I treat it like one? is svelte just for single page?
Brody
Brody2y ago
just take my advice and start using vite asap
Santosh
Santosh2y ago
okey we'll do npm WARN config production Use --omit=dev instead.
[email protected] start serve public -s -n -L -p $PORT
INFO Accepting connections at http://localhost:5473 for the deploy log https://inhouse.up.railway.app/
Brody
Brody2y ago
looks good
Santosh
Santosh2y ago
that works i think
Brody
Brody2y ago
now move to vite to fix the rest of the issues with your app
Santosh
Santosh2y ago
opens not the good page tho
Brody
Brody2y ago
vite
Santosh
Santosh2y ago
😢
Brody
Brody2y ago
have fun
Santosh
Santosh2y ago
lol i need to figure out why and how now lol but thanks for all the help!
Brody
Brody2y ago
vite has a svelte plugin, it will be super easy just go find a vite/sveltle template to reference it
Santosh
Santosh2y ago
but does it mean I can keep my multiple html files? or should I manage to make them a spa
Brody
Brody2y ago
vite is only for single page apps
Santosh
Santosh2y ago
oh boi
Santosh
Santosh2y ago
Santosh
Santosh2y ago
is there hope so id need a rewrite?
Brody
Brody2y ago
just convert to a spa and do client side routing
Santosh
Santosh2y ago
ill have to look into that then ig
Brody
Brody2y ago
yes you will
Santosh
Santosh2y ago
i should at some point thanks!
Brody
Brody2y ago
prob should have before you started this project tbh
Santosh
Santosh2y ago
it is what it is, we learn along the way 😉 thats a good lesson for later projects
Brody
Brody2y ago
i like the positivity! i wish you good luck
Santosh
Santosh2y ago
Thank you so much for your help!
Brody
Brody2y ago
no problem!
Santosh
Santosh2y ago
@Brody Can I DM you?
Brody
Brody2y ago
#🛂|readme #5 - no pings youre funny
Want results from more Discord servers?
Add your server