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
Percy15mo ago
Project ID: N/A
intro 🇮🇹
intro 🇮🇹15mo ago
N/A I don't know where to find my project Id
jonbeau
jonbeau15mo 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.718215mo 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 🇮🇹
intro 🇮🇹15mo 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.718215mo 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
Brody15mo ago
to provide you with help we would need to see your repo to understand what's going on with your app
intro 🇮🇹
intro 🇮🇹15mo 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 🇮🇹
intro 🇮🇹15mo ago
i used their flask template and modified it a bit. it's still quite simple - see my repo above
Brody
Brody15mo ago
you modified it a lot the template repo didnt have a dockerfile
intro 🇮🇹
intro 🇮🇹15mo 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
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
remove my github repo from the railway project?
Brody
Brody15mo ago
from the railway service there would be a little x button besides the repo listing in the service settings
intro 🇮🇹
intro 🇮🇹15mo ago
this?
Brody
Brody15mo ago
yep, you can remove both those
intro 🇮🇹
intro 🇮🇹15mo ago
ok just did
Brody
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
should i remove the dockerfile?
Brody
Brody15mo ago
ah yes you should, good catch
intro 🇮🇹
intro 🇮🇹15mo ago
ok just did should i push my changes?
Brody
Brody15mo ago
yes please
intro 🇮🇹
intro 🇮🇹15mo ago
ok done oh should i have renamed "app" to "backend" ?
Brody
Brody15mo ago
if you want to, it is a backend after all
intro 🇮🇹
intro 🇮🇹15mo ago
ok done and pushed to main
Brody
Brody15mo ago
okay lets get working on the backend first show me a screenshot of the entire railway project
intro 🇮🇹
intro 🇮🇹15mo ago
this?
Brody
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
ok, and i keep the postgres db?
Brody
Brody15mo ago
yes!
intro 🇮🇹
intro 🇮🇹15mo ago
Brody
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
Brody
Brody15mo ago
perfect rename __init__.py to main.py and remove the static_folder='../react-app/build', static_url_path='/' stuff from it
intro 🇮🇹
intro 🇮🇹15mo ago
ok done and pushed to main
Brody
Brody15mo ago
now just do a quick check locally and make sure you can run your backend still
intro 🇮🇹
intro 🇮🇹15mo ago
i can
Brody
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
Actually, I am getting an error: I think it is refering to the .flaskenv
Brody
Brody15mo ago
where are you trying to import backend, and why?
intro 🇮🇹
intro 🇮🇹15mo 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
Brody15mo ago
remove the file lol
intro 🇮🇹
intro 🇮🇹15mo ago
then i can't run the backend anymore
Brody
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
Brody
Brody15mo ago
should that be from models import db, user without the period?
intro 🇮🇹
intro 🇮🇹15mo ago
no it's User and worked before
Brody
Brody15mo ago
the file name has a lower case u
intro 🇮🇹
intro 🇮🇹15mo ago
it is refering to the actual user model changing it to lowercase gives the same error
Brody
Brody15mo ago
and yes i know it worked before, but you had an improper directory structure before
intro 🇮🇹
intro 🇮🇹15mo ago
yeah it was pretty messy
Brody
Brody15mo ago
so please get your codebase working locally before we proceed
intro 🇮🇹
intro 🇮🇹15mo ago
since i can't seem to figure this out i will create a minimal flask app and work from there
Brody
Brody15mo ago
sounds good
intro 🇮🇹
intro 🇮🇹15mo ago
nevermind i am encounterin the same issue here as well when moving my files to the backend as we did earlier
Brody
Brody15mo ago
alright no worries, ill be around, just let me know when you are ready to proceed
intro 🇮🇹
intro 🇮🇹15mo 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
Brody15mo ago
i dont think these linked folders will work on railway i also cant see whats inside of them
intro 🇮🇹
intro 🇮🇹15mo ago
GitHub
GitHub - hannarosenfeld/vault-manager
Contribute to hannarosenfeld/vault-manager development by creating an account on GitHub.
Brody
Brody15mo ago
that looks like it shall work
intro 🇮🇹
intro 🇮🇹15mo ago
I added the railway file just now
Brody
Brody15mo 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 🇮🇹
intro 🇮🇹15mo ago
done
Brody
Brody15mo ago
push the changed then do this
intro 🇮🇹
intro 🇮🇹15mo 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
Brody15mo ago
haha beat me to it
intro 🇮🇹
intro 🇮🇹15mo 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 🇮🇹
intro 🇮🇹15mo ago
intro 🇮🇹
intro 🇮🇹15mo ago
related to the railway file?
Brody
Brody15mo ago
oh my bad, it would be main:app
intro 🇮🇹
intro 🇮🇹15mo 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
Brody15mo 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