R
Railway11mo ago
MrEpiko

Deploying a website

How can I deploy Vite + React website on Railway? I already have an existing repository on GitHub.
63 Replies
Percy
Percy11mo ago
Project ID: N/A
Brody
Brody11mo ago
can you share the repo?
MrEpiko
MrEpiko11mo ago
It's private I can send you screenshot of its structure if you want
MrEpiko
MrEpiko11mo ago
No description
Brody
Brody11mo ago
send the Dockerfile please
MrEpiko
MrEpiko11mo ago
FROM python:3.10.0

WORKDIR .

COPY backend/pyproject.toml pyproject.toml

RUN pip3 install poetry

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

RUN pip install -r requirements.txt

COPY . .

CMD ["python3", "backend/main.py"]
FROM python:3.10.0

WORKDIR .

COPY backend/pyproject.toml pyproject.toml

RUN pip3 install poetry

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

RUN pip install -r requirements.txt

COPY . .

CMD ["python3", "backend/main.py"]
This one's used for backend
MrEpiko
MrEpiko11mo ago
No description
Brody
Brody11mo ago
use this dockerfile, but move it to the backend folder
FROM python:3.10.0

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /app

COPY pyproject.toml ./

RUN pip3 install poetry

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

RUN pip install -r requirements.txt

COPY . ./

CMD ["python3", "main.py"]
FROM python:3.10.0

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /app

COPY pyproject.toml ./

RUN pip3 install poetry

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

RUN pip install -r requirements.txt

COPY . ./

CMD ["python3", "main.py"]
MrEpiko
MrEpiko11mo ago
Railway will detect it even tho it's in backend folder?
Brody
Brody11mo ago
nope, go into the service settings and set the root dir to /backend
MrEpiko
MrEpiko11mo ago
Okay, what about website itself? The one in frontend folder
Brody
Brody11mo ago
we will, one thing at a time what kind of python app is this btw? im worried you might be running it in development mode thus increasing your running costs and lowering performance
MrEpiko
MrEpiko11mo ago
Flask right now but will switch to waitress once it's fully ready I am just testing it for now
Brody
Brody11mo ago
okay then in that case for your future referance you would need to use a start command like this
CMD waitress-serve --listen=*:$PORT main:app
CMD waitress-serve --listen=*:$PORT main:app
the --listen=*:$PORT is the most important and to give me a better idea what you have going on, can i see a screenshot of your railway project
MrEpiko
MrEpiko11mo ago
So instead of CMD ["python3", "main.py"], that? Which part exactly?
Brody
Brody11mo ago
correct the railway project, a screenshot of the browser window if you dont mind?
MrEpiko
MrEpiko11mo ago
Also I assume I should change $PORT to 8080 right
MrEpiko
MrEpiko11mo ago
No description
Brody
Brody11mo ago
no, you want $PORT
MrEpiko
MrEpiko11mo ago
aha okay
Brody
Brody11mo ago
oh you are already using waitress?
MrEpiko
MrEpiko11mo ago
Yeah I am
Brody
Brody11mo ago
whats your new start command (CMD)
MrEpiko
MrEpiko11mo ago
No description
MrEpiko
MrEpiko11mo ago
It's all working fine, backend wise
Brody
Brody11mo ago
perfect, then we can move on to the frontend you will need to create a new railway service in the same project, and set its root dir to /frontend
MrEpiko
MrEpiko11mo ago
Okay, sec
Brody
Brody11mo ago
https://github.com/brody192/vite-react-template you will also need to copy the nixpacks.toml and Caddyfile from this repo into your frontend folder
MrEpiko
MrEpiko11mo ago
done
Brody
Brody11mo ago
and whats the verdict?
MrEpiko
MrEpiko11mo ago
wdym I still don't have Dockerfile in frontend set up if that's what you mean
Brody
Brody11mo ago
does the frontend work? you dont need one?
MrEpiko
MrEpiko11mo ago
Oh Give me a second
Brody
Brody11mo ago
new service set /frontend root dir copy those two files add repo
MrEpiko
MrEpiko11mo ago
#18 [stage-0 12/15] RUN --mount=type=cache,id=s/4927b395-9f83-49be-98b0-f1a96e982fbe-node_modules/cache,target=/app/node_modules/.cache npm run build



#18 1.251 npm

WARN config production Use `--omit=dev` instead.

#18 1.357

#18 1.357 > [email protected] build

#18 1.357 > vite build

#18 1.357



#18 1.367 sh: 1: vite: Permission denied

#18 ERROR: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 126

-----

> [stage-0 12/15] RUN --mount=type=cache,id=s/4927b395-9f83-49be-98b0-f1a96e982fbe-node_modules/cache,target=/app/node_modules/.cache npm run build:

WARN config production Use `--omit=dev` instead.

1.357

1.357 > [email protected] build

1.357 > vite build

1.357

1.367 sh: 1: vite: Permission denied

-----



Dockerfile:30

-------------------

28 | # build phase

29 | COPY . /app/.

30 | >>> RUN --mount=type=cache,id=s/4927b395-9f83-49be-98b0-f1a96e982fbe-node_modules/cache,target=/app/node_modules/.cache npm run build

31 |

32 | # fmt phase

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 126



Error: Docker build failed
#18 [stage-0 12/15] RUN --mount=type=cache,id=s/4927b395-9f83-49be-98b0-f1a96e982fbe-node_modules/cache,target=/app/node_modules/.cache npm run build



#18 1.251 npm

WARN config production Use `--omit=dev` instead.

#18 1.357

#18 1.357 > [email protected] build

#18 1.357 > vite build

#18 1.357



#18 1.367 sh: 1: vite: Permission denied

#18 ERROR: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 126

-----

> [stage-0 12/15] RUN --mount=type=cache,id=s/4927b395-9f83-49be-98b0-f1a96e982fbe-node_modules/cache,target=/app/node_modules/.cache npm run build:

WARN config production Use `--omit=dev` instead.

1.357

1.357 > [email protected] build

1.357 > vite build

1.357

1.367 sh: 1: vite: Permission denied

-----



Dockerfile:30

-------------------

28 | # build phase

29 | COPY . /app/.

30 | >>> RUN --mount=type=cache,id=s/4927b395-9f83-49be-98b0-f1a96e982fbe-node_modules/cache,target=/app/node_modules/.cache npm run build

31 |

32 | # fmt phase

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 126



Error: Docker build failed
No idea why is it mentioning Docker tho
Brody
Brody11mo ago
in the future, use this https://bookmarklets.up.railway.app/log-downloader/ railway uses docker for all apps, and will automatically generate a dockerfile for you as for the error, make sure you have your dist and node_modules folders in your .gitignore file and not in the repo
MrEpiko
MrEpiko11mo ago
No description
MrEpiko
MrEpiko11mo ago
And error is still the same
Brody
Brody11mo ago
make sure those folders dont exist in the repo on github
MrEpiko
MrEpiko11mo ago
Oh right my bad
Brody
Brody11mo ago
its node_modules/ btw
MrEpiko
MrEpiko11mo ago
Now I am getting this
No description
MrEpiko
MrEpiko11mo ago
As for this site, it's not working for me for some reason
MrEpiko
MrEpiko11mo ago
When I go to it it says "This site is designed to be used with Railway"
No description
Brody
Brody11mo ago
please follow the instructions on the page
MrEpiko
MrEpiko11mo ago
Yeah I did, is there some video explanation?
Brody
Brody11mo ago
no sorry, its only 3 steps
MrEpiko
MrEpiko11mo ago
Can you take a look at screenshot while I try to figure it out
Brody
Brody11mo ago
make sure your files are cased correctly, github does not seem to normally track a filename casing. you could be importing Logo.jsx just fine locally, but on github the file could be called logo.jsx
MrEpiko
MrEpiko11mo ago
It was working fine until I deleted node_modules from github repo
root
root11mo ago
If you're on Windows, for instance, you could be able to import it case-insensitively locally make sure the file is named Logo.css and not logo.css
Brody
Brody11mo ago
coincidence haha .jsx
root
root11mo ago
.css
MrEpiko
MrEpiko11mo ago
No description
root
root11mo ago
look at the error
Brody
Brody11mo ago
interesting
root
root11mo ago
Yep, that's the problem. Rename logo.css to Logo.css.
Adam
Adam11mo ago
he can’t it wasn’t downloaded with the bookmarklet Brody isn’t allowed to look at screenshots, that’s why he always asks for the bookmarklet
Brody
Brody11mo ago
i mean you arent wrong, if it wasnt a blurry image i would have seen it lol
MrEpiko
MrEpiko11mo ago
Random question, but why can't you see images?
Brody
Brody11mo ago
adam is joking, i can see images, but unless i look at the image in the browser, the image is small and i miss stuff thats why i am adamant about using the bookmarklet
MrEpiko
MrEpiko11mo ago
Aha Well, looks like it's working now Thank you so much 😄
Brody
Brody11mo ago
no problem!
Want results from more Discord servers?
Add your server