R
Railway16mo ago
intro

Deploying for the first time

Hi, I am new to railroad and I am trying to deploy my flask app. I am getting this error:
Dockerfile:24

-------------------

22 | # build phase

23 | COPY . /app/.

24 | >>> RUN npm install --prefix react-app && npm run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all

25 |

26 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm install --prefix react-app && npm run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all" did not complete successfully: exit code: 127



Error: Docker build failed
Dockerfile:24

-------------------

22 | # build phase

23 | COPY . /app/.

24 | >>> RUN npm install --prefix react-app && npm run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all

25 |

26 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c npm install --prefix react-app && npm run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all" did not complete successfully: exit code: 127



Error: Docker build failed
In the attached screenshot you can see how I am setting the build command. Do I need to add a Dockerfile to my project? I never done that before so I am confused on what to do to fix this. Thank you in advance for reading!
72 Replies
Percy
Percy16mo ago
Project ID: N/A
intro
introOP16mo ago
N/A I don't know where to find my project Id
jonbeau
jonbeau16mo ago
Hello, how did you come up with this build command? There's a few flask templates you could reference. https://railway.app/template/zUcpux
2.7182
2.718216mo ago
Hey @intro , I'm not completely sure about a solution to you're problem, but here's a good start: you're build script has a bunch of things && together, try doing just one of them at a time and see which ones trigger the error. And yes, using a docker file would probably be a straight forward way to get this to work.
intro
introOP16mo ago
@Finesse it says line 1: npm: command not found so i assume it somehow does not know npm? It's from a starter project I used before. It comes with user authentication
2.7182
2.718216mo ago
@intro have you tried not doing a custom build command? Using the Railway template. (When you first choose a project to deploy, choosing the "deploy flask app" option. Relevant: https://railway.app/new/template/zUcpux
Brody
Brody16mo ago
to provide you with help we would need to see your repo to understand what's going on with your app
intro
introOP16mo ago
this is the current state of my app: https://github.com/hannarosenfeld/vault-manager
GitHub
GitHub - hannarosenfeld/vault-manager
Contribute to hannarosenfeld/vault-manager development by creating an account on GitHub.
intro
introOP16mo ago
i used their flask template and modified it a bit. it's still quite simple - see my repo above
Brody
Brody16mo ago
you modified it a lot the template repo didnt have a dockerfile
intro
introOP16mo ago
i added the dockerfile because i obv don't know what i am doing i just want to deploy my site lol i need a front and a backend the backend needs to be flask and the frontend needs to be react
Brody
Brody16mo ago
haha no worries, we'll get you sorted so while we work through this, go ahead and remove the repo from your service so we arent triggering a new build for every little change
intro
introOP16mo ago
remove my github repo from the railway project?
Brody
Brody16mo ago
from the railway service there would be a little x button besides the repo listing in the service settings
intro
introOP16mo ago
this?
Brody
Brody16mo ago
yep, you can remove both those
intro
introOP16mo ago
ok just did
Brody
Brody16mo ago
okay so you will now want to re-structure your repo into a monorepo rename react-app to frontend and then put everything expect readme.md and the frontend folder into a backend folder
intro
introOP16mo ago
should i remove the dockerfile?
Brody
Brody16mo ago
ah yes you should, good catch
intro
introOP16mo ago
ok just did should i push my changes?
Brody
Brody16mo ago
yes please
intro
introOP16mo ago
ok done oh should i have renamed "app" to "backend" ?
Brody
Brody16mo ago
if you want to, it is a backend after all
intro
introOP16mo ago
ok done and pushed to main
Brody
Brody16mo ago
okay lets get working on the backend first show me a screenshot of the entire railway project
intro
introOP16mo ago
this?
Brody
Brody16mo ago
yep, going forward you will use that service for just your backend, so give it a name that signifies its the service for the backend later we will create another service for the frontend, but we will cross that bridge when we get to it
intro
introOP16mo ago
ok, and i keep the postgres db?
Brody
Brody16mo ago
yes!
intro
introOP16mo ago
Brody
Brody16mo ago
give it a name that signifies its the service for the backend
oh i see what you did, you want to change the service name, not the project name remove the backend suffix from the project name
intro
introOP16mo ago
Brody
Brody16mo ago
perfect rename __init__.py to main.py and remove the static_folder='../react-app/build', static_url_path='/' stuff from it
intro
introOP16mo ago
ok done and pushed to main
Brody
Brody16mo ago
now just do a quick check locally and make sure you can run your backend still
intro
introOP16mo ago
i can
Brody
Brody16mo ago
now you will need a railway.json file in your backend, so railway knows how to run the backend service
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "gunicorn main.app"
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "gunicorn main.app"
}
}
intro
introOP16mo ago
Actually, I am getting an error: I think it is refering to the .flaskenv
Brody
Brody16mo ago
where are you trying to import backend, and why?
intro
introOP16mo ago
i'm not sure.. i am sure though it's from the .flaskenv variable FLASK_APP. Changing it's value changes the value in the error:
Brody
Brody16mo ago
remove the file lol
intro
introOP16mo ago
then i can't run the backend anymore
Brody
Brody16mo ago
just add
if __name__ == '__main__':
app.run(debug=True, port=os.getenv("PORT", default=5000))
if __name__ == '__main__':
app.run(debug=True, port=os.getenv("PORT", default=5000))
to the bottom of your main.py file, then you can start the flask server with python main.py
intro
introOP16mo ago
Brody
Brody16mo ago
should that be from models import db, user without the period?
intro
introOP16mo ago
no it's User and worked before
Brody
Brody16mo ago
the file name has a lower case u
intro
introOP16mo ago
it is refering to the actual user model changing it to lowercase gives the same error
Brody
Brody16mo ago
and yes i know it worked before, but you had an improper directory structure before
intro
introOP16mo ago
yeah it was pretty messy
Brody
Brody16mo ago
so please get your codebase working locally before we proceed
intro
introOP16mo ago
since i can't seem to figure this out i will create a minimal flask app and work from there
Brody
Brody16mo ago
sounds good
intro
introOP16mo ago
nevermind i am encounterin the same issue here as well when moving my files to the backend as we did earlier
Brody
Brody16mo ago
alright no worries, ill be around, just let me know when you are ready to proceed
intro
introOP16mo ago
ok i got a simple app running now. let's take it from here: https://github.com/hannarosenfeld/vault-manager
GitHub
GitHub - hannarosenfeld/vault-manager
Contribute to hannarosenfeld/vault-manager development by creating an account on GitHub.
Brody
Brody16mo ago
i dont think these linked folders will work on railway i also cant see whats inside of them
intro
introOP16mo ago
GitHub
GitHub - hannarosenfeld/vault-manager
Contribute to hannarosenfeld/vault-manager development by creating an account on GitHub.
Brody
Brody16mo ago
that looks like it shall work
intro
introOP16mo ago
I added the railway file just now
Brody
Brody16mo ago
in your backend railway service, set the root directory to /backend then add this repo to the service ah you had a procfile, so i didnt mention the railway.json file but now that you have the railway.json leave it, and delete the old style heroku Procfile
intro
introOP16mo ago
done
Brody
Brody16mo ago
push the changed then do this
intro
introOP16mo ago
i'm getting the same error i got since the beginning now:
-----

> [stage-0 8/10] RUN yarn install --prefix react-app && yarn run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all:

0.299 /bin/bash: line 1: yarn: command not found

-----

Dockerfile:24

-------------------

22 | # build phase

23 | COPY . /app/.

24 | >>> RUN yarn install --prefix react-app && yarn run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all

25 |

26 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c yarn install --prefix react-app && yarn run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all" did not complete successfully: exit code: 127



Error: Docker build failed

-----

> [stage-0 8/10] RUN yarn install --prefix react-app && yarn run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all:

0.299 /bin/bash: line 1: yarn: command not found

-----

Dockerfile:24

-------------------

22 | # build phase

23 | COPY . /app/.

24 | >>> RUN yarn install --prefix react-app && yarn run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all

25 |

26 |

-------------------

ERROR: failed to solve: process "/bin/bash -ol pipefail -c yarn install --prefix react-app && yarn run build --prefix react-app && pip install -r requirements.txt && pip install psycopg2 && flask db upgrade && flask seed all" did not complete successfully: exit code: 127



Error: Docker build failed

sorry i realized i still had that old build command in settings. just removed. building again.
Brody
Brody16mo ago
haha beat me to it
intro
introOP16mo ago
the build completed though i can't see my site when i click on the link. deploy logs giving me a bunch of errors. what stands out to me is this: ModuleNotFoundError: No module named 'main.app'; 'main' is not a package
intro
introOP16mo ago
intro
introOP16mo ago
related to the railway file?
Brody
Brody16mo ago
oh my bad, it would be main:app
intro
introOP16mo ago
yay it's live now thank you i will create my models etc from here and probably be back with more errors at some point ^^
Brody
Brody16mo ago
sounds good, let me know when you want to tackle the seprate frontend service it should be plenty easy to get your original react app running on railway instead of this same react app for context, frontend solved in a new thread
Want results from more Discord servers?
Add your server