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
Project ID:
N/A
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
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.
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,reacthey 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?
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
so i changed the github repository as above, i can remove the server side form railway now
you have removed the github repo from your railway service?
YES. the database is still there, the server has been deleted
delete the remaining node_modules folders from your repo
from the server side as well as in root?
everywhere please
all gone from server and from root
there is none n the client
okay create a new empty service in your project
ok ive just created a new empty service
this will be your backend, give it an applicable name and domain
give things good names
name your project and name that service
ok i named the service "Backend"
from comfrotable-reward
what did you name the project
its called "sloppy-quince" i cannot rename it i think
it would be a crime if you couldnt rename it, just read that name outloud 💀
click the settings button
just changed it "Workout"
perfect
add these variables to the raw editor in the service variables
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
const db = pgp('postgres://postgres:vienna1981@localhost:5432/fitness'); this line?
ive added in the service variables, which should match the database i think
yep thats the line, remove it or comment it out
show me a screenshot of your service variables please
but im using db elsewhere in the code?
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?
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?
you are using
db
and pool
in multiple places, please only use one database constructor type, this will involve some refactoring on your partah ok , i will look thgouh this now
sounds good, let me know when thats done!
thanks, yes it will take a me a little while i will let you know soon..
okie dokie
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.
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
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.
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
So db has to go ? OK... Will take some more time to refractor then.... thanks
you can keep either db or pool, one has to go
Right, got it, will try and work it out..
sounds good
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.
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 yoursId forgotten about PORT ! Thanks i will make those changes..
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.
i will look at this in 2hrs when im home
thanks!
the Caddyfile needs a capital C
the nixpacks.toml and Caddyfile need to be in the frontend folder
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.
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 settingsit was set to frontend
capital F
/Frontend
but i did have npm run dev as start command
yeah remove that please
deleting it now... to leave blank
it still fails to deploy.... ive got no environmental variables in my frontend could that be a problem?
i dont either
please provide logs https://bookmarklets.up.railway.app/log-downloader/
sorry not sure how to use that link....
the logs on deployment i copied and pasted below:
it seems to be some kind of eror wit a docker
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
i dont have anything to open odt files, could you please take a look at the log downloader i sent
got it i think
looks like docker themselves are having issues, not much we can do here but wait
ah so it is an outside problem for railway you think?
yes it is
Ah ok... hopefully gets sorted soon then lol
Thanks very much
testing if discord is working...
why? what happened to discord?
seems like discord as down some hours ago
unfortunate
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
this was my client logs
it works locally but not in production and im not sure why the CORs affects it as ive triedvarious things with it in code
does your backend has the cors middleware?
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)
send me the link to your frontend please
https://github.com/Eugenepython/movies/tree/main/Frontend this is frontend in github
GitHub
movies/Frontend at main · Eugenepython/movies
Contribute to Eugenepython/movies development by creating an account on GitHub.
I'd like the railway url please
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
okay will look shortly
https://github.com/Eugenepython/movies/blob/main/Backend/backend.jsx#L41
that should just be
PORT
not PG_PORT
just changed it to const PORT = process.env.PORT || 3000;.... still get that error message though ðŸ˜
can you share the deployment logs for the backend
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
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
sounds good
sorry, this time it got worse, the deployment crashed
after the change from jsx to js, and the change in start command
you dont have express in your dependencies
npm install express
oh sorry wa ssure i had installed those,
installed again and pushed
deployment logs again please
oh hang on wrong file..
Error: Cannot find module 'dotenv'
please make sure you have all modules installedoh right just seen that, re installing here
doesnt seem to be recognising the port
neither the 'port' i console logged but didnt use nor the process.env.PORT
do you have a
PORT
service variable set?yes....
remove it
oh.... you mean environmental variables in the database or server on railway?
the service variables
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..
screenshot?
this is when i try and go into my project
didnt happen until 5 mins ago
thats not ideal, issue with railway
https://discord.com/channels/713503345364697088/846875565357006878
may have to leave it for a while.... are you saying i should remove all the envrionmental variables from the server side on railway?
nope never said anything like that
keep an eye out in #🚨|incidents
oh right didnt undertstand what you meant by the service variables and PORT service variable set
we'll come back to this when the incident is resolved
ah ok thanks
see you later
resloved, if youre still around?
hey
yup
back here
okay, do you have a
PORT
service variable?tbh not 100% sure what that means... in my code?
const PORT = process.env.PORT || 3000; this is my backend
this is where the service variables are located
these are the server variables
should i just remove the variable for PG_PORT?
id like to note
PG_PORT
is not the same as PORT
please dont confuse the two
your variables are fine
deployment logs pleaseAH ok i see
try commenting out these lines
https://github.com/Eugenepython/movies/blob/main/Backend/backend.js#L7-L8
still an error just a different kind ol
lol
thats the same error
ah ok sorry thought id seen difference
at this moment i am stumped, i will do some testing myself shortly and get back to you
i thought to console log the process.ENV.port but not sure it would even show up
ill look into this
thanks!
i made some changes and no longer got the port error
https://github.com/Eugenepython/movies/pull/1
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?
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}}
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
i add in this variable as environmental variable
the logs look short for once
console.log(prodFrontendURL); comes out as ${{https://movie-client-production.up.railway.app}}
may be frontend url is stil incorrect im not sure
Still getting the cors error
that variable you added is incorrect, please read the text within the angle brackets
somewhat unbelievably... it now works! i just bought you 3 trains, thanks so much hope railway do something for you too!
awe thanks for the trains 🙂
glad i could help!
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
yeah!
OK oool thanks again, hope this helps others too whn they ask!
no problem! 🙂