R
Railway12mo 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
Percy12mo ago
Project ID: N/A
Brody
Brody12mo ago
can you share the repo?
MrEpiko
MrEpiko12mo ago
It's private I can send you screenshot of its structure if you want
MrEpiko
MrEpiko12mo ago
No description
Brody
Brody12mo ago
send the Dockerfile please
MrEpiko
MrEpiko12mo 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
MrEpiko12mo ago
No description
Brody
Brody12mo 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
MrEpiko12mo ago
Railway will detect it even tho it's in backend folder?
Brody
Brody12mo ago
nope, go into the service settings and set the root dir to /backend
MrEpiko
MrEpiko12mo ago
Okay, what about website itself? The one in frontend folder
Brody
Brody12mo 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
MrEpiko12mo ago
Flask right now but will switch to waitress once it's fully ready I am just testing it for now
Brody
Brody12mo 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
MrEpiko12mo ago
So instead of CMD ["python3", "main.py"], that? Which part exactly?
Brody
Brody12mo ago
correct the railway project, a screenshot of the browser window if you dont mind?
MrEpiko
MrEpiko12mo ago
Also I assume I should change $PORT to 8080 right
MrEpiko
MrEpiko12mo ago
No description
Brody
Brody12mo ago
no, you want $PORT
MrEpiko
MrEpiko12mo ago
aha okay
Brody
Brody12mo ago
oh you are already using waitress?
MrEpiko
MrEpiko12mo ago
Yeah I am
Brody
Brody12mo ago
whats your new start command (CMD)
MrEpiko
MrEpiko12mo ago
No description
MrEpiko
MrEpiko12mo ago
It's all working fine, backend wise
Brody
Brody12mo 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
MrEpiko12mo ago
Okay, sec
Brody
Brody12mo 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
MrEpiko12mo ago
done
Brody
Brody12mo ago
and whats the verdict?
MrEpiko
MrEpiko12mo ago
wdym I still don't have Dockerfile in frontend set up if that's what you mean
Brody
Brody12mo ago
does the frontend work? you dont need one?
MrEpiko
MrEpiko12mo ago
Oh Give me a second
Brody
Brody12mo ago
new service set /frontend root dir copy those two files add repo
MrEpiko
MrEpiko12mo 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
Brody12mo 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
MrEpiko12mo ago
No description
MrEpiko
MrEpiko12mo ago
And error is still the same
Brody
Brody12mo ago
make sure those folders dont exist in the repo on github
MrEpiko
MrEpiko12mo ago
Oh right my bad
Brody
Brody12mo ago
its node_modules/ btw
MrEpiko
MrEpiko12mo ago
Now I am getting this
No description
MrEpiko
MrEpiko12mo ago
As for this site, it's not working for me for some reason
MrEpiko
MrEpiko12mo ago
When I go to it it says "This site is designed to be used with Railway"
No description
Brody
Brody12mo ago
please follow the instructions on the page
MrEpiko
MrEpiko12mo ago
Yeah I did, is there some video explanation?
Brody
Brody12mo ago
no sorry, its only 3 steps
MrEpiko
MrEpiko12mo ago
Can you take a look at screenshot while I try to figure it out
Brody
Brody12mo 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
MrEpiko12mo ago
It was working fine until I deleted node_modules from github repo
root
root12mo 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
Brody12mo ago
coincidence haha .jsx
root
root12mo ago
.css
MrEpiko
MrEpiko12mo ago
No description
root
root12mo ago
look at the error
Brody
Brody12mo ago
interesting
root
root12mo ago
Yep, that's the problem. Rename logo.css to Logo.css.
Adam
Adam12mo 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
Brody12mo ago
i mean you arent wrong, if it wasnt a blurry image i would have seen it lol
MrEpiko
MrEpiko12mo ago
Random question, but why can't you see images?
Brody
Brody12mo 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
MrEpiko12mo ago
Aha Well, looks like it's working now Thank you so much 😄
Brody
Brody12mo ago
no problem!
Want results from more Discord servers?
Add your server