#cannot deploy server Deployment Failed during build process

206 messages · Page 1 of 1 (latest)

tidal fog
#

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.

coarse dockBOT
#

Project ID: N/A

dusk mauveBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

ashen crown
#

hello i am guidance

#

please send your package.json

ashen crown
#

@tidal fog I'm still here if you need assistance and I have a good understanding of how to deploy react apps on railway

tidal fog
#

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

Contribute to Eugenepython/FITNESS development by creating an account on GitHub.

ashen crown
tidal fog
#

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?

ashen crown
#

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

tidal fog
#

so i changed the github repository as above, i can remove the server side form railway now

ashen crown
#

you have removed the github repo from your railway service?

tidal fog
#

YES. the database is still there, the server has been deleted

ashen crown
#

delete the remaining node_modules folders from your repo

tidal fog
#

from the server side as well as in root?

ashen crown
#

everywhere please

tidal fog
#

all gone from server and from root

#

there is none n the client

ashen crown
#

okay create a new empty service in your project

tidal fog
#

ok ive just created a new empty service

ashen crown
#

this will be your backend, give it an applicable name and domain

tidal fog
ashen crown
#

give things good names

#

name your project and name that service

tidal fog
#

ok i named the service "Backend"

#

from comfrotable-reward

ashen crown
#

what did you name the project

tidal fog
#

its called "sloppy-quince" i cannot rename it i think

ashen crown
#

it would be a crime if you couldnt rename it, just read that name outloud 💀

#

click the settings button

tidal fog
#

just changed it "Workout"

ashen crown
#

perfect

tidal fog
ashen crown
#

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}}
tidal fog
#

const db = pgp('postgres://postgres:vienna1981@localhost:5432/fitness'); this line?

#

ive added in the service variables, which should match the database i think

ashen crown
#

yep thats the line, remove it or comment it out

#

show me a screenshot of your service variables please

tidal fog
#

but im using db elsewhere in the code?

ashen crown
#

you have also created a pool though

tidal fog
#

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?

ashen crown
#

you are using db and pool in multiple places, please only use one database constructor type, this will involve some refactoring on your part

tidal fog
#

ah ok , i will look thgouh this now

ashen crown
#

sounds good, let me know when thats done!

tidal fog
#

thanks, yes it will take a me a little while i will let you know soon..

ashen crown
#

okie dokie

tidal fog
#

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

Contribute to Eugenepython/FITNESS development by creating an account on GitHub.

ashen crown
tidal fog
#

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

Contribute to Eugenepython/FITNESS development by creating an account on GitHub.

ashen crown
#

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

tidal fog
#

So db has to go ? OK... Will take some more time to refractor then.... thanks

ashen crown
#

you can keep either db or pool, one has to go

tidal fog
#

Right, got it, will try and work it out..

ashen crown
#

sounds good

tidal fog
#

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

Contribute to Eugenepython/movies development by creating an account on GitHub.

ashen crown
tidal fog
#

Id forgotten about PORT ! Thanks i will make those changes..

tidal fog
#

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

Contribute to Eugenepython/movies development by creating an account on GitHub.

sleek mist
tidal fog
#

thanks!

ashen crown
#

the Caddyfile needs a capital C
the nixpacks.toml and Caddyfile need to be in the frontend folder

tidal fog
ashen crown
#

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

tidal fog
#

it was set to frontend

ashen crown
#

capital F /Frontend

tidal fog
#

but i did have npm run dev as start command

ashen crown
#

yeah remove that please

tidal fog
#

deleting it now... to leave blank

#

it still fails to deploy.... ive got no environmental variables in my frontend could that be a problem?

ashen crown
#

i dont either

tidal fog
#

sorry not sure how to use that link....

#

the logs on deployment i copied and pasted below:

#

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

ashen crown
#

i dont have anything to open odt files, could you please take a look at the log downloader i sent

tidal fog
ashen crown
#

looks like docker themselves are having issues, not much we can do here but wait

tidal fog
#

ah so it is an outside problem for railway you think?

ashen crown
#

yes it is

tidal fog
#

Ah ok... hopefully gets sorted soon then lol

#

Thanks very much

tidal fog
#

testing if discord is working...

ashen crown
#

why? what happened to discord?

torpid surge
ashen crown
#

unfortunate

tidal fog
#

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

#

it works locally but not in production and im not sure why the CORs affects it as ive triedvarious things with it in code

ashen crown
#

does your backend has the cors middleware?

tidal fog
#

yes cors is in the backend

ashen crown
#

send me the link to your frontend please

tidal fog
ashen crown
#

I'd like the railway url please

tidal fog
#

its fairly simple. pressing "submit" starts the communication with backend and should stroe the input in database

ashen crown
#

okay will look shortly

tidal fog
#

just changed it to const PORT = process.env.PORT || 3000;.... still get that error message though 😭

ashen crown
#

can you share the deployment logs for the backend

tidal fog
ashen crown
#

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

tidal fog
#

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

ashen crown
#

sounds good

tidal fog
#

sorry, this time it got worse, the deployment crashed

#

after the change from jsx to js, and the change in start command

ashen crown
#

you dont have express in your dependencies
npm install express

tidal fog
#

oh sorry wa ssure i had installed those,

#

installed again and pushed

ashen crown
#

deployment logs again please

tidal fog
#

oh hang on wrong file..

ashen crown
#

Error: Cannot find module 'dotenv'
please make sure you have all modules installed

tidal fog
#

oh 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

ashen crown
#

do you have a PORT service variable set?

tidal fog
#

yes....

ashen crown
#

remove it

tidal fog
#

oh.... you mean environmental variables in the database or server on railway?

ashen crown
#

the service variables

tidal fog
#

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..

ashen crown
#

screenshot?

tidal fog
#

this is when i try and go into my project

#

didnt happen until 5 mins ago

ashen crown
#

thats not ideal, issue with railway

tidal fog
#

may have to leave it for a while.... are you saying i should remove all the envrionmental variables from the server side on railway?

ashen crown
#

nope never said anything like that

#

keep an eye out in #🚨|incidents

tidal fog
#

oh right didnt undertstand what you meant by the service variables and PORT service variable set

ashen crown
#

we'll come back to this when the incident is resolved

tidal fog
#

ah ok thanks

#

see you later

ashen crown
#

resloved, if youre still around?

tidal fog
#

hey

#

yup

#

back here

ashen crown
#

okay, do you have a PORT service variable?

tidal fog
#

tbh not 100% sure what that means... in my code?

#

const PORT = process.env.PORT || 3000; this is my backend

ashen crown
#

this is where the service variables are located

tidal fog
#

these are the server variables

#

should i just remove the variable for PG_PORT?

ashen crown
#

id like to note PG_PORT is not the same as PORT please dont confuse the two

#

your variables are fine

#

deployment logs please

tidal fog
#

AH ok i see

ashen crown
tidal fog
#

lol

ashen crown
#

thats the same error

tidal fog
#

ah ok sorry thought id seen difference

ashen crown
#

at this moment i am stumped, i will do some testing myself shortly and get back to you

tidal fog
#

i thought to console log the process.ENV.port but not sure it would even show up

ashen crown
#

ill look into this

tidal fog
#

thanks!

ashen crown
tidal fog
#

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?

ashen crown
#

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}}

tidal fog
#

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

tidal fog
#

the logs look very short for once and vaguel successful lol

tidal fog
#

i add in this variable as environmental variable

#

the logs look short for once

#

may be frontend url is stil incorrect im not sure

tidal fog
#

Still getting the cors error

ashen crown
#

that variable you added is incorrect, please read the text within the angle brackets

tidal fog
#

somewhat unbelievably... it now works! i just bought you 3 trains, thanks so much hope railway do something for you too!

ashen crown
#

awe thanks for the trains 🙂

#

glad i could help!

tidal fog
#

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

ashen crown
#

yeah!

tidal fog
#

OK oool thanks again, hope this helps others too whn they ask!