R
Railway

✋|help

Deploying for the first time

AAda238/23/2023
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


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!
AAda238/23/2023
N/A
I don't know where to find my project Id
Jjonbeau8/23/2023
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.71828/23/2023
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.
AAda238/23/2023
@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.71828/23/2023
@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
Bbrody1928/23/2023
to provide you with help we would need to see your repo to understand what's going on with your app
AAda238/23/2023
this is the current state of my app:

https://github.com/hannarosenfeld/vault-manager
i used their flask template and modified it a bit. it's still quite simple - see my repo above
Bbrody1928/23/2023
you modified it a lot
the template repo didnt have a dockerfile
AAda238/23/2023
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
Bbrody1928/23/2023
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
AAda238/23/2023
remove my github repo from the railway project?
Bbrody1928/23/2023
from the railway service
there would be a little x button besides the repo listing in the service settings
AAda238/23/2023
this?
Bbrody1928/23/2023
yep, you can remove both those
AAda238/23/2023
ok just did
Bbrody1928/23/2023
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
AAda238/23/2023
should i remove the dockerfile?
Bbrody1928/23/2023
ah yes you should, good catch
AAda238/23/2023
ok just did
should i push my changes?
Bbrody1928/23/2023
yes please
AAda238/23/2023
ok done
oh should i have renamed "app" to "backend" ?
Bbrody1928/23/2023
if you want to, it is a backend after all
AAda238/23/2023
ok done and pushed to main
Bbrody1928/23/2023
okay lets get working on the backend first
show me a screenshot of the entire railway project
AAda238/23/2023
this?
Bbrody1928/23/2023
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
AAda238/23/2023
ok, and i keep the postgres db?
Bbrody1928/23/2023
yes!
AAda238/23/2023
Bbrody1928/23/2023
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
AAda238/23/2023
Bbrody1928/23/2023
perfect
rename __init__.py to main.py
and remove the static_folder='../react-app/build', static_url_path='/' stuff from it
AAda238/23/2023
ok done and pushed to main
Bbrody1928/23/2023
now just do a quick check locally and make sure you can run your backend still
AAda238/23/2023
i can
Bbrody1928/23/2023
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"
    }
}
AAda238/23/2023
Actually, I am getting an error:

I think it is refering to the .flaskenv
Bbrody1928/23/2023
where are you trying to import backend, and why?
AAda238/23/2023
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:
Bbrody1928/23/2023
remove the file lol
AAda238/23/2023
then i can't run the backend anymore
Bbrody1928/23/2023
just add
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
AAda238/23/2023
Bbrody1928/23/2023
should that be from models import db, user without the period?
AAda238/23/2023
no it's User and worked before
Bbrody1928/23/2023
the file name has a lower case u
AAda238/23/2023
it is refering to the actual user model
changing it to lowercase gives the same error
Bbrody1928/23/2023
and yes i know it worked before, but you had an improper directory structure before
AAda238/23/2023
yeah it was pretty messy
Bbrody1928/23/2023
so please get your codebase working locally before we proceed
AAda238/23/2023
since i can't seem to figure this out i will create a minimal flask app and work from there
Bbrody1928/23/2023
sounds good
AAda238/23/2023
nevermind i am encounterin the same issue here as well when moving my files to the backend as we did earlier
Bbrody1928/23/2023
alright no worries, ill be around, just let me know when you are ready to proceed
AAda238/23/2023
ok i got a simple app running now. let's take it from here:
https://github.com/hannarosenfeld/vault-manager
Bbrody1928/23/2023
i dont think these linked folders will work on railway
i also cant see whats inside of them
Bbrody1928/23/2023
that looks like it shall work
AAda238/23/2023
I added the railway file just now
Bbrody1928/23/2023
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
AAda238/23/2023
done
Bbrody1928/23/2023
push the changed then do this
AAda238/23/2023
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


sorry i realized i still had that old build command in settings. just removed.
building again.
Bbrody1928/23/2023
haha beat me to it
AAda238/23/2023
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
AAda238/23/2023
AAda238/23/2023
related to the railway file?
Bbrody1928/23/2023
oh my bad, it would be main:app
AAda238/23/2023
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 ^^
Bbrody1928/24/2023
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

Looking for more? Join the community!

Recommended Posts
I can't seem to be able to use the mariadb app i'm running in my PHP projectI want to be able to connect my mariadb app deployed on railway in my PHP script but when I try to uRailway too slowI have an issue with my railwat app. The app is too slow once update my github project. Making it alTrying to communicate over private network and not workingI have a service that has just private networking enabled and listens on ipv6 (http server). When I How is Redis instance pricing calculatedDoes the per vCPU and per GB memory pricing apply to a Redis database? Would like to know before I svolume permissionsMy docker run script is trying to install as a user owned file into volume mount point but getting pDeployment Issue: ModuleNotFoundError for Flask with Poetry-based ProjectHello, I'm having trouble deploying a Flask app on Railway using Poetry for dependency management. DDoes HTTP response count towards egress quota?I just want to check an external endpoint a few times a day but the response is quite big.Hosting a Directus + NuxtJs project service availableI'm trying to host a Directus service and NuxtJs service but I'm having some trouble getting the froDB StorageHello all, I have a question. How much storage does Railway have when building a server or databaseLogs broken?Hello is there a problem with logs? I am not seeing any build or deploy logs at all, I just see the Minecraft Server isn't working?When I use the minecraft server template and leave everything it will give this error in the logs anFormbricks Template error (upon redeployment w/ SMTP setup)``` error getting environment TypeError: fetch failed at Object.fetch (node:internal/deps/undicPayload CMS + Nextjs Deployment Failed during build processUsing the template courtesy of @Brody with Next.js added [as seen here](https://github.com/payloadcmHosting a modded Minecraft serverHi guys! I'm trying to host a modded minecraft server through Railway using the `Minecraft Server` tCan't connect to RedisThis is the error I am getting. What I have checked so far * Made sure I used the env variables provHello everyone, i'm trying to make a python websocket using websockets library also flaskso basically i have this -> ```py async def main(): url = os.environ.get('RAILWAY_URL', 'localExtension of Payment Due Date for SubscriptionIs there a way I can request for a brief extension of a few days for my upcoming payment?Hello Everyone! I am facing some problem related to deploying my nodejs application.I have deployed my nodejs application using github, but do not know how can I connect phpmyadmin so RedeployHey there, is there away to start a redploy using the Railway APIKafka Connectioncould anyone help me setup kafka cluster? I've went through the deployment process but getting a con