R
Railway•14mo ago
mjavacam

Vite + Docker Deployment is Successful But Application Fail To Respond Error - Help with Deployment

Project ID: 2942e240-e493-4fc3-8ec1-d06a31b5444c I have attempted to deploy a vite app using nginx via docker but for some reason everytime it deploys it keeps saying "Application failed to respond" error. I have tried a few of the issues that are related to the similar but no solution worked so far. I think I may be doing something wrong on my end. I have replicated the steps locally and the image builds. When tested the app responds in the container but once deployed, I believe nginx seems to stall on railway. The app is using react-router-dom not sure if this would be an issue but stating it for additional content Any insight in what I may be doing wrong could help:
FROM node:18 AS base
WORKDIR /app
COPY package.json .
RUN yarn install

FROM base AS build
WORKDIR /app
ARG VITE_API_BASE_URL
ARG VITE_DIRECTLINE_TOKEN_URI
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
ENV VITE_DIRECTLINE_TOKEN_URI=${VITE_DIRECTLINE_TOKEN_URI}
COPY --from=base /app/node_modules ./node_modules
COPY --from=base /app/package.json /app/yarn.lock ./
COPY . .
RUN yarn build

FROM nginx:alpine AS production
WORKDIR /usr/share/nginx/html
# RUN rm -rf ./*
# COPY .nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist .
# EXPOSE 80
# ENTRYPOINT ["nginx", "-g", "daemon off;"]
FROM node:18 AS base
WORKDIR /app
COPY package.json .
RUN yarn install

FROM base AS build
WORKDIR /app
ARG VITE_API_BASE_URL
ARG VITE_DIRECTLINE_TOKEN_URI
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
ENV VITE_DIRECTLINE_TOKEN_URI=${VITE_DIRECTLINE_TOKEN_URI}
COPY --from=base /app/node_modules ./node_modules
COPY --from=base /app/package.json /app/yarn.lock ./
COPY . .
RUN yarn build

FROM nginx:alpine AS production
WORKDIR /usr/share/nginx/html
# RUN rm -rf ./*
# COPY .nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist .
# EXPOSE 80
# ENTRYPOINT ["nginx", "-g", "daemon off;"]
Solution:
put this into your client folder, overwriting the previous file
Jump to solution
54 Replies
Percy
Percy•14mo ago
Project ID: 2942e240-e493-4fc3-8ec1-d06a31b5444c
Brody
Brody•14mo ago
i have a ready-made solution to deploy vite apps if youd be intrested in going back to nixpacks? @mjavacam little tag for visibility
mjavacam
mjavacam•14mo ago
Hey sure no prob Sorry about the late response
Brody
Brody•14mo ago
haha just about to grab dinner, will get back to you after!
mjavacam
mjavacam•14mo ago
Alright no prob man lol food is life as we say here
Brody
Brody•14mo ago
delete or rename your dockerfile https://github.com/brody192/vite-react-template copy the nixpacks.toml and Caddyfile from this repo into yours make sure you dont have any build or start commands set in our service settings, a procfile, railway.json, etc
mjavacam
mjavacam•14mo ago
Ok will do
Brody
Brody•14mo ago
let me know if you run into any problems!
mjavacam
mjavacam•14mo ago
No prob sorting it out now
mjavacam
mjavacam•14mo ago
hey I managed to copy the files over but it is failing on the install I am guess it is due to it being a yarn workspace or yarn monorepo?
No description
No description
mjavacam
mjavacam•14mo ago
Brody
Brody•14mo ago
can you share your repo?
mjavacam
mjavacam•14mo ago
Yes no prob https://github.com/javaniecampbell/b2c-dashboard It's a private repo so I invited you to it
Brody
Brody•14mo ago
3 years ago? is this the correct repo?
mjavacam
mjavacam•14mo ago
Brody
Brody•14mo ago
yeah that makes more sense, sorry I'm very new to github
mjavacam
mjavacam•14mo ago
No issue that is on me no prob
Brody
Brody•14mo ago
how many apps does this repo contain?
mjavacam
mjavacam•14mo ago
3 apps - api - client a.k.a frontend react app - bot Got the api to deploy fine given that I set root folder to be api in settings for api service
Brody
Brody•14mo ago
how many services do you have in your railway project right now
mjavacam
mjavacam•14mo ago
3 main ones + a test one based on nginx template to see if i did something wrong so let's say 2 services + mongo db I removed the one I was testing based on nginx template
mjavacam
mjavacam•14mo ago
No description
Brody
Brody•14mo ago
okay so if you have 3 apps in that repo, you need 3 railway services to accommodate each app in your repo (not including the database)
mjavacam
mjavacam•14mo ago
The bot is deployed on azure
Brody
Brody•14mo ago
ah okay perfect
mjavacam
mjavacam•14mo ago
We can skip that one
Brody
Brody•14mo ago
you have set the root directory of the frontend service to /client right?
mjavacam
mjavacam•14mo ago
Yes I have
No description
mjavacam
mjavacam•14mo ago
And build watch path
No description
Brody
Brody•14mo ago
and the build error is still the same?
mjavacam
mjavacam•14mo ago
Yup
Brody
Brody•14mo ago
might be a silly question, but you have set the service to deploy from the banch you linked me right?
mjavacam
mjavacam•14mo ago
Yes I did
No description
mjavacam
mjavacam•14mo ago
Not a silly question at all
Solution
Brody
Brody•14mo ago
put this into your client folder, overwriting the previous file
mjavacam
mjavacam•14mo ago
I added it and pushed it waiting for it finish building
mjavacam
mjavacam•14mo ago
mjavacam
mjavacam•14mo ago
I see that it is using npm instead of yarn could that be an issue since it is a yarn workspace? could that be changed?
Brody
Brody•14mo ago
I mean the dependencies should be installed all the same, I wouldn't worry too much about that
mjavacam
mjavacam•14mo ago
Alright no prob
mjavacam
mjavacam•14mo ago
Success
Brody
Brody•14mo ago
awesome!!
mjavacam
mjavacam•14mo ago
What pointed to that issue so I can know what to look out for in the future?
Brody
Brody•14mo ago
the build issue?
mjavacam
mjavacam•14mo ago
yes, what point you to kmow it was dependency issue that was causing the build to fail
Brody
Brody•14mo ago
because the build logs told me that's what it was 🙂
mjavacam
mjavacam•14mo ago
Oh ok I'll have to read through the logs again then no issue Thanks man
Brody
Brody•14mo ago
happy to help!
mjavacam
mjavacam•14mo ago
I am new to railway just hope the docs can cover these issues alot of hidden gems in this helps ection here You the man Brody!!
Brody
Brody•14mo ago
I wish the docs could too, but I really have no idea how to put my help into a document
mjavacam
mjavacam•14mo ago
I get you man, I have that issue too but let's see what I can do with mine ... I will try to put it together and share it with you.
Brody
Brody•14mo ago
cool, I'd love to see that when you're done
Want results from more Discord servers?
Add your server