R
Railway•15mo ago
vienna1981

cannot deploy server Deployment Failed during build process

hi, i keep failing to deploy a server which works fine in local environment but not in productoin here. It is based out of github. I get the error message : ERROR: failed to solve: process "/bin/bash -ol pipefail -c react-scripts build" did not complete successfully: exit code: 127 Error: Docker build failed I have looked at guidance but cannot see any answers. Are three any guidance or videos showing how to deploy the server side of a frontend applicaiton? I have already deployed the database without issues, just this does not seem to work with the server.
155 Replies
Percy
Percy•15mo ago
Project ID: N/A
Brody
Brody•15mo ago
hello i am guidance please send your package.json @vienna1981 I'm still here if you need assistance and I have a good understanding of how to deploy react apps on railway
vienna1981
vienna1981OP•15mo ago
https://github.com/Eugenepython/FITNESS hi so sorry had missed your first message! the above is the link to my github which has the package jsons. I can deploy my server ok i think its just the backend where i start to have problems deploying. Going bed now but hopefully you can see something !
GitHub
GitHub - Eugenepython/FITNESS
Contribute to Eugenepython/FITNESS development by creating an account on GitHub.
Brody
Brody•15mo ago
I see .env files and node_modules folders in your repo, please remove them from the repo and place the contents of this link into a .gitignore in the root of your repo https://www.toptal.com/developers/gitignore/api/node,react
vienna1981
vienna1981OP•15mo ago
hey thanks i tried this. i deleted the node modules, and i deleted the .env file, and i added a gitignore file with the content pasted in but it still fails. 3.178 sh: 1: react-scripts: not found ----- Dockerfile:24 ------------------- 22 | # build phase 23 | COPY . /app/. 24 | >>> RUN --mount=type=cache,id=s/45ed6e2b-d58e-4fa3-b34c-1733248e29a0-node_modules/cache,target=/app/node_modules/.cache npm run build 25 | 26 | ------------------- ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exit code: 127 Error: Docker build failed these are the last few logs prior to the failure is this all down to incompatibility with envrionmentalk variables?
Brody
Brody•15mo ago
i know, that was not meant to fix the build there is a few things we need to do before worrying about a build failing or succeeding you can go ahead and remove your repo from the railway service as we will be making a few changes and dont need railway rebuilding after every little change
vienna1981
vienna1981OP•15mo ago
so i changed the github repository as above, i can remove the server side form railway now
Brody
Brody•15mo ago
you have removed the github repo from your railway service?
vienna1981
vienna1981OP•15mo ago
YES. the database is still there, the server has been deleted
Brody
Brody•15mo ago
delete the remaining node_modules folders from your repo
vienna1981
vienna1981OP•15mo ago
from the server side as well as in root?
Brody
Brody•15mo ago
everywhere please
vienna1981
vienna1981OP•15mo ago
all gone from server and from root there is none n the client
Brody
Brody•15mo ago
okay create a new empty service in your project
vienna1981
vienna1981OP•15mo ago
ok ive just created a new empty service
Brody
Brody•15mo ago
this will be your backend, give it an applicable name and domain
vienna1981
vienna1981OP•15mo ago
No description
Brody
Brody•15mo ago
give things good names name your project and name that service
vienna1981
vienna1981OP•15mo ago
ok i named the service "Backend" from comfrotable-reward
Brody
Brody•15mo ago
what did you name the project
vienna1981
vienna1981OP•15mo ago
its called "sloppy-quince" i cannot rename it i think
Brody
Brody•15mo ago
it would be a crime if you couldnt rename it, just read that name outloud 💀 click the settings button
vienna1981
vienna1981OP•15mo ago
just changed it "Workout"
Brody
Brody•15mo ago
perfect
vienna1981
vienna1981OP•15mo ago
No description
Brody
Brody•15mo ago
add these variables to the raw editor in the service variables
DB_USER=${{postgresql.PGUSER}}
DB_HOST=${{postgresql.PGHOST}}
DB_NAME=${{postgresql.PGDATABASE}}
DB_PASSWORD=${{postgresql.PGPASSWORD}}
DB_PORT=${{postgresql.PGPORT}}
DB_USER=${{postgresql.PGUSER}}
DB_HOST=${{postgresql.PGHOST}}
DB_NAME=${{postgresql.PGDATABASE}}
DB_PASSWORD=${{postgresql.PGPASSWORD}}
DB_PORT=${{postgresql.PGPORT}}
you also left this in your code, this is only gonna cause connection errors when on railway https://github.com/Eugenepython/FITNESS/blob/main/Server/app.jsx#L12
vienna1981
vienna1981OP•15mo ago
const db = pgp('postgres://postgres:vienna1981@localhost:5432/fitness'); this line? ive added in the service variables, which should match the database i think
Brody
Brody•15mo ago
yep thats the line, remove it or comment it out show me a screenshot of your service variables please
vienna1981
vienna1981OP•15mo ago
but im using db elsewhere in the code?
Brody
Brody•15mo ago
you have also created a pool though https://github.com/Eugenepython/FITNESS/blob/main/Server/app.jsx#L29-L36 im not sure what your intentions are?
vienna1981
vienna1981OP•15mo ago
sorry two seconds let me check db.manyOrNone('SELECT * FROM users WHERE username = $1', [sessionTitle]) so i can use pool.query in stead of db and delete all references to db?
Brody
Brody•15mo ago
you are using db and pool in multiple places, please only use one database constructor type, this will involve some refactoring on your part
vienna1981
vienna1981OP•15mo ago
ah ok , i will look thgouh this now
Brody
Brody•15mo ago
sounds good, let me know when thats done!
vienna1981
vienna1981OP•15mo ago
thanks, yes it will take a me a little while i will let you know soon..
Brody
Brody•15mo ago
okie dokie
vienna1981
vienna1981OP•15mo ago
hi sorry. going to bed now. i tried to refractor the code without using db at all. however now i cannot use it locally properly. i add the .env file back in to try and get it working locally https://github.com/Eugenepython/FITNESS but im not sure the refractoring works as it doesnt seem to connect to the server here?
GitHub
GitHub - Eugenepython/FITNESS
Contribute to Eugenepython/FITNESS development by creating an account on GitHub.
Brody
Brody•15mo ago
no problem we can continue later, but when you're back you would need these environment variables to be available locally to run the server https://github.com/Eugenepython/FITNESS/blob/main/Server/app.jsx#L29-L35
vienna1981
vienna1981OP•15mo ago
hi i updated the code but made few changes. i remembered why is used pgp and the db object. Basically, without using it, the database was updated repeatedly and this caused problems when trying to connect to the server. For example using manyOrNone meant I could get the login name from the database without reopening the component and setting the login name back to blank. Without this the app just crashed when i tried to log in. So i had to keep it in. I also deleted the node modules, but after deleting them i always have to install pg and also vite plug in and whenever i do, the node modules just keep coming back.. so not sure if they have to be deleted or if there is a way to delete them while keeping pg and vite plugin? Sorry i realise it seems i pretty much ignored all you suggested, but this is how i can get my code to work locally and not otherwise. the .env file is still there, if the gitignore file is there does that mean i can keep it for production? https://github.com/Eugenepython/FITNESS
GitHub
GitHub - Eugenepython/FITNESS
Contribute to Eugenepython/FITNESS development by creating an account on GitHub.
Brody
Brody•15mo ago
I'm sorry but you are going to have to make your code work with all the suggestions I have made, otherwise you won't be able to run it on railway
vienna1981
vienna1981OP•15mo ago
So db has to go ? OK... Will take some more time to refractor then.... thanks
Brody
Brody•15mo ago
you can keep either db or pool, one has to go
vienna1981
vienna1981OP•15mo ago
Right, got it, will try and work it out..
Brody
Brody•15mo ago
sounds good
vienna1981
vienna1981OP•15mo ago
hi! sorry i got totally lost sorting out the code so instead i tried a simpler app to tryand see if icould deploy it. It seems to be deployed correctly (frontend, backend and database) and the app works perfectly in local environment. However when I try and run the gernarated domain https://favoritemoviesbackend-production.up.railway.app/ it fails and says aplication fails to respond. This is the code. https://github.com/Eugenepython/movies sorry again i thought id try a simpler way to try and get this into my head, but i do not understand here why everything seems deployed correctly, with the environmental variables etc but the production url does not work..
GitHub
GitHub - Eugenepython/movies
Contribute to Eugenepython/movies development by creating an account on GitHub.
Brody
Brody•15mo ago
for your backend - https://github.com/Eugenepython/movies/blob/main/Backend/backend.jsx#L4C1-L4C19 - use const PORT = process.env.PORT || 3000; instead. - https://github.com/Eugenepython/movies/blob/main/Backend/package.json#L8 - do not use nodemon when on railway for the frontend - https://github.com/brody192/vite-react-template - copy the nixpacks.toml and Caddyfile from this repo into yours
vienna1981
vienna1981OP•15mo ago
Id forgotten about PORT ! Thanks i will make those changes..
vienna1981
vienna1981OP•15mo ago
Hi ! I did all the above, but adding the nixpacks,.toml and the caddyfile in (word for word) to frontend leads to the deploment of frontned failing. If i leave them out, the deployment succeeds but the railway url still leads to a https://favoritemoviesbackend-production.up.railway.app/ Application failed to respond. this is the latest code https://github.com/Eugenepython/movies im not sure if i need to adapt the two files for my own code?
GitHub
GitHub - Eugenepython/movies
Contribute to Eugenepython/movies development by creating an account on GitHub.
Floris
Floris•15mo ago
i will look at this in 2hrs when im home
vienna1981
vienna1981OP•15mo ago
thanks!
Brody
Brody•15mo ago
the Caddyfile needs a capital C the nixpacks.toml and Caddyfile need to be in the frontend folder
vienna1981
vienna1981OP•14mo ago
No description
No description
No description
vienna1981
vienna1981OP•14mo ago
https://github.com/Eugenepython/movies unfortunately i still get an error 😦
GitHub
GitHub - Eugenepython/movies
Contribute to Eugenepython/movies development by creating an account on GitHub.
vienna1981
vienna1981OP•14mo ago
No description
Brody
Brody•14mo ago
https://test-service2.up.railway.app/ have you set the Movie-client root directory to /Frontend? and make sure you dont have any build or start commands set in the service settings
vienna1981
vienna1981OP•14mo ago
it was set to frontend
Brody
Brody•14mo ago
capital F /Frontend
vienna1981
vienna1981OP•14mo ago
but i did have npm run dev as start command
Brody
Brody•14mo ago
yeah remove that please
vienna1981
vienna1981OP•14mo ago
deleting it now... to leave blank it still fails to deploy.... ive got no environmental variables in my frontend could that be a problem?
Brody
Brody•14mo ago
i dont either please provide logs https://bookmarklets.up.railway.app/log-downloader/
vienna1981
vienna1981OP•14mo ago
sorry not sure how to use that link.... the logs on deployment i copied and pasted below:
vienna1981
vienna1981OP•14mo ago
it seems to be some kind of eror wit a docker
vienna1981
vienna1981OP•14mo ago
the deployment is successful without the caddyfile and the nitpix but i get Application failed to respond with the caddfile and the nitpix i get unsuccessful deployment and sill get Application failed to respond as well
Brody
Brody•14mo ago
i dont have anything to open odt files, could you please take a look at the log downloader i sent
vienna1981
vienna1981OP•14mo ago
Brody
Brody•14mo ago
looks like docker themselves are having issues, not much we can do here but wait
vienna1981
vienna1981OP•14mo ago
ah so it is an outside problem for railway you think?
Brody
Brody•14mo ago
yes it is
vienna1981
vienna1981OP•14mo ago
Ah ok... hopefully gets sorted soon then lol Thanks very much testing if discord is working...
Brody
Brody•14mo ago
why? what happened to discord?
Medim
Medim•14mo ago
seems like discord as down some hours ago
Brody
Brody•14mo ago
unfortunate
vienna1981
vienna1981OP•14mo ago
ah yeah it failed earlier right after i sent the message to test it lol further to my last message.. the app is now successful but i get a failure message relating to CORS
vienna1981
vienna1981OP•14mo ago
No description
vienna1981
vienna1981OP•14mo ago
this was my client logs
vienna1981
vienna1981OP•14mo ago
it works locally but not in production and im not sure why the CORs affects it as ive triedvarious things with it in code
Brody
Brody•14mo ago
does your backend has the cors middleware?
vienna1981
vienna1981OP•14mo ago
yes cors is in the backend app.use( cors({ origin: 'https://movie-client-production.up.railway.app', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', credentials: true, }) ); i tried thisin backend (it works locally with the other url)
Brody
Brody•14mo ago
send me the link to your frontend please
vienna1981
vienna1981OP•14mo ago
GitHub
movies/Frontend at main · Eugenepython/movies
Contribute to Eugenepython/movies development by creating an account on GitHub.
Brody
Brody•14mo ago
I'd like the railway url please
vienna1981
vienna1981OP•14mo ago
oh sorry here it is https://movie-client-production.up.railway.app/ its fairly simple. pressing "submit" starts the communication with backend and should stroe the input in database
Brody
Brody•14mo ago
okay will look shortly https://github.com/Eugenepython/movies/blob/main/Backend/backend.jsx#L41 that should just be PORT not PG_PORT
vienna1981
vienna1981OP•14mo ago
just changed it to const PORT = process.env.PORT || 3000;.... still get that error message though 😭
Brody
Brody•14mo ago
can you share the deployment logs for the backend
Brody
Brody•14mo ago
please do no use pm2 on railway, your start command should only be node backend.jsx also, ive ignored it for a while, but why .jsx? your file extension should just be .js
vienna1981
vienna1981OP•14mo ago
ive always used jsx out of habit in react but youre right this just vanilla javascript k ill change to js for backend and all references too and ill switch the start
Brody
Brody•14mo ago
sounds good
vienna1981
vienna1981OP•14mo ago
sorry, this time it got worse, the deployment crashed
vienna1981
vienna1981OP•14mo ago
after the change from jsx to js, and the change in start command
Brody
Brody•14mo ago
you dont have express in your dependencies npm install express
vienna1981
vienna1981OP•14mo ago
oh sorry wa ssure i had installed those, installed again and pushed
vienna1981
vienna1981OP•14mo ago
No description
Brody
Brody•14mo ago
deployment logs again please
vienna1981
vienna1981OP•14mo ago
No description
vienna1981
vienna1981OP•14mo ago
oh hang on wrong file..
Brody
Brody•14mo ago
Error: Cannot find module 'dotenv' please make sure you have all modules installed
vienna1981
vienna1981OP•14mo ago
oh right just seen that, re installing here
vienna1981
vienna1981OP•14mo ago
doesnt seem to be recognising the port neither the 'port' i console logged but didnt use nor the process.env.PORT
Brody
Brody•14mo ago
do you have a PORT service variable set?
vienna1981
vienna1981OP•14mo ago
yes....
Brody
Brody•14mo ago
remove it
vienna1981
vienna1981OP•14mo ago
oh.... you mean environmental variables in the database or server on railway?
Brody
Brody•14mo ago
the service variables
vienna1981
vienna1981OP•14mo ago
ok sorry 2 mnins.. the railway dashboard is playing up and i cant see project anymore.... ill just refresh a few times its looking like i cannot access my projects anymore..
Brody
Brody•14mo ago
screenshot?
vienna1981
vienna1981OP•14mo ago
No description
vienna1981
vienna1981OP•14mo ago
this is when i try and go into my project didnt happen until 5 mins ago
Brody
Brody•14mo ago
vienna1981
vienna1981OP•14mo ago
may have to leave it for a while.... are you saying i should remove all the envrionmental variables from the server side on railway?
Brody
Brody•14mo ago
nope never said anything like that keep an eye out in #🚨|incidents
vienna1981
vienna1981OP•14mo ago
oh right didnt undertstand what you meant by the service variables and PORT service variable set
Brody
Brody•14mo ago
we'll come back to this when the incident is resolved
vienna1981
vienna1981OP•14mo ago
ah ok thanks see you later
Brody
Brody•14mo ago
resloved, if youre still around?
vienna1981
vienna1981OP•14mo ago
hey yup back here
Brody
Brody•14mo ago
okay, do you have a PORT service variable?
vienna1981
vienna1981OP•14mo ago
tbh not 100% sure what that means... in my code? const PORT = process.env.PORT || 3000; this is my backend
Brody
Brody•14mo ago
this is where the service variables are located
No description
vienna1981
vienna1981OP•14mo ago
No description
vienna1981
vienna1981OP•14mo ago
these are the server variables should i just remove the variable for PG_PORT?
Brody
Brody•14mo ago
id like to note PG_PORT is not the same as PORT please dont confuse the two your variables are fine deployment logs please
vienna1981
vienna1981OP•14mo ago
AH ok i see
vienna1981
vienna1981OP•14mo ago
still an error just a different kind ol
vienna1981
vienna1981OP•14mo ago
lol
Brody
Brody•14mo ago
thats the same error
vienna1981
vienna1981OP•14mo ago
ah ok sorry thought id seen difference
Brody
Brody•14mo ago
at this moment i am stumped, i will do some testing myself shortly and get back to you
vienna1981
vienna1981OP•14mo ago
i thought to console log the process.ENV.port but not sure it would even show up
Brody
Brody•14mo ago
ill look into this
vienna1981
vienna1981OP•14mo ago
thanks!
Brody
Brody•14mo ago
i made some changes and no longer got the port error https://github.com/Eugenepython/movies/pull/1
vienna1981
vienna1981OP•14mo ago
hey thanks! did you add the frontend URL as process.env.FRONTEND_URL as the crucial change? does this automatically detect the frontendURL from the pool?
Brody
Brody•14mo ago
the frontend doesn't have anything to do with a pool add this in the raw editor of the backend's service variables, be sure to replace the needed text FRONTEND_URL=https://${{<the frontends service name>.RAILWAY_PUBLIC_DOMAIN}}
vienna1981
vienna1981OP•14mo ago
added it to the raw editor (i have previosuly jst added environmental variables line by line) these are the new environemtnal variables as they appear now the logs look very short for once and vaguel successful lol
vienna1981
vienna1981OP•14mo ago
No description
vienna1981
vienna1981OP•14mo ago
i add in this variable as environmental variable
vienna1981
vienna1981OP•14mo ago
the logs look short for once console.log(prodFrontendURL); comes out as ${{https://movie-client-production.up.railway.app}}
vienna1981
vienna1981OP•14mo ago
No description
vienna1981
vienna1981OP•14mo ago
may be frontend url is stil incorrect im not sure Still getting the cors error
Brody
Brody•14mo ago
that variable you added is incorrect, please read the text within the angle brackets
vienna1981
vienna1981OP•14mo ago
somewhat unbelievably... it now works! i just bought you 3 trains, thanks so much hope railway do something for you too!
Brody
Brody•14mo ago
awe thanks for the trains 🙂 glad i could help!
vienna1981
vienna1981OP•14mo ago
so basically, the key was not to hard code the frontend url, but to take it as an environmental variable from the frontend service as FRONTEND.URL
Brody
Brody•14mo ago
yeah!
vienna1981
vienna1981OP•14mo ago
OK oool thanks again, hope this helps others too whn they ask!
Brody
Brody•14mo ago
no problem! 🙂
Want results from more Discord servers?
Add your server