5 months ago
Hello Railway
I am trying to host my backend (and later frontend) on Railway, but seem to be having some trouble. The repo has a root directory specified to ensure the backend is what's being deployed.
However it seems that despite there being a Procfile, requirements.txt and that the root has a runtime.txt with the specific Python version needed, that it does not see it properly.
Anyone know what could be causing the issue ? Or is able to help
0 Replies
5 months ago
Your issue is with the Python version, right?
I got a feeling that it's moreso the repository. I'm told it cannot read gunicorn, but that IS in the requirements.txt so I'm not sure what is going wrong
5 months ago
Can you show the build and deploy logs?
Sure, how do I copy the logs from there though, don't seem to see a copy button
Guess I can just mark it:
[Region: us-west1]
==============
Using Nixpacks
==============
context: 0081f12fc1ce8a5c234af1269728346f
╔═════════════════════════ Nixpacks v1.31.0 ═════════════════════════╗
║ setup │ nodejs_18, npm-8_x ║
║────────────────────────────────────────────────────────────────────║
║ install │ npm ci ║
║────────────────────────────────────────────────────────────────────║
║ start │ gunicorn --access-logfile - --error-logfile - run:app ║
╚════════════════════════════════════════════════════════════════════╝
[internal] load build definition from Dockerfile
[internal] load build definition from Dockerfile
[internal] load build definition from Dockerfile ✔ 0ms
[internal] load build definition from Dockerfile
[internal] load build definition from Dockerfile ✔ 11ms
[internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1736208272
[internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1736208272 ✔ 101ms
[internal] load .dockerignore
[internal] load .dockerignore ✔ 0ms
[internal] load .dockerignore
[internal] load .dockerignore ✔ 9ms
[stage-0 8/8] COPY . /app
[stage-0 7/8] RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile
[internal] load build context ✔ 0ms
[internal] load build context
[internal] load build context ✔ 475ms
[stage-0 3/8] COPY .nixpacks/nixpkgs-5624e1334b26ddc18da37e132b6fa8e93b481468.nix .nixpacks/nixpkgs-5624e1334b26ddc18da37e132b6fa8e93b481468.nix ✔ 0ms – CACHED
[stage-0 4/8] RUN nix-env -if .nixpacks/nixpkgs-5624e1334b26ddc18da37e132b6fa8e93b481468.nix && nix-collect-garbage -d ✔ 0ms – CACHED
[stage-0 5/8] COPY . /app/.
[stage-0 5/8] COPY . /app/. ✔ 332ms
[stage-0 6/8] RUN --mount=type=cache,id=s/0d3c87d4-0b8e-4709-b1a1-f5b6127f16be-/root/npm,target=/root/.npm npm ci
npm warn config production Use `--omit=dev` instead.
up to date, audited 1 package in 392ms
found 0 vulnerabilities
[stage-0 6/8] RUN --mount=type=cache,id=s/0d3c87d4-0b8e-4709-b1a1-f5b6127f16be-/root/npm,target=/root/.npm npm ci ✔ 864ms
[stage-0 7/8] RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile
[stage-0 7/8] RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile ✔ 136ms
[stage-0 8/8] COPY . /app
[stage-0 8/8] COPY . /app ✔ 224ms
[auth] sharing credentials for us-west1.registry.rlwy.net
[auth] sharing credentials for us-west1.registry.rlwy.net ✔ 0ms
=== Successfully Built! ===
Run:
docker run -it us-west1.registry.rlwy.net/0d3c87d4-0b8e-4709-b1a1-f5b6127f16be:87752f75-561e-48f8-a2d2-f782d9381696
Build time: 7.72 seconds
build seems to "work", but idk if it's cause it just doesn't seem to read the files needed
Not gonna act like an expert, I'm a student so this is new to me in terms of hosting via Railway
5 months ago
Don't worry, I am also a student and not an expert.
5 months ago
The build logs seems to only install node v18, how is your project structured?
my project is a repo with a frontend and backend folder. The project itself is owned by a company I intern for, but my exam suddenly required having the project hosted, so I am trying to get it hosted with Railway as it seemed to be able to host the areas needed
5 months ago
In that case https://docs.railway.com/guides/monorepo
I already told it what root directory to go for. I however did not mention a start command. CGPT told me it would find the files needed itself and run through Procfile but maybe I set it up wrong, since the deploy logs complains about gunicorn, signaling maybe a lack of requirements.txt being run through
5 months ago
You can try putting python as a provider under providers and see if that helps.
5 months ago
Since the build logs don't show anything Python related
5 months ago
maybe this will help, but no guarantees
Wonder if I can specify a version on that, since I need a specific version, though the root directory's runtime.txt has that specified
5 months ago
You can set the Python version via the NIXPACKS_PYTHON_VERSION
env https://nixpacks.com/docs/providers/python
5 months ago
-# version in runtime.txt also works
✕ [stage-0 10/13] RUN --mount=type=cache,id=s/0d3c87d4-0b8e-4709-b1a1-f5b6127f16be-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt
process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 2
Dockerfile:30
-------------------
28 | ENV NIXPACKS_PATH=/opt/venv/bin:$NIXPACKS_PATH
29 | COPY . /app/.
30 | >>> RUN --mount=type=cache,id=s/0d3c87d4-0b8e-4709-b1a1-f5b6127f16be-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt
31 |
32 | # build phase
-------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 2
Error: Docker build failed
5 months ago
-# set a service variable NIXPACKS_VERSION=1.29.1
when you say service variable, do you mean I should set this into my .env file ? Sorry if that's a bad question
5 months ago
5 months ago
-# uxuz shall continue from here
Is there a way to check exactly what version of python the railway service installs? I assume it installed the version I needed, but I'm getting an error that there was no suitable python version for the pandas-stubs.
The company's system runs on Python 3.8.4. and runtime.txt in the root of the repository (not the backend directory), mentions that version exactly
5 months ago
It's stated in the build logs
Did try looking through them, but there is a lot of rows of text so kinda hard to find specifically
5 months ago
It's in the table which is like one of the first things it prints out
Based on this, it seems it runs python 3.11.9 or am I reading it wrong?
/nix/store/k7j3cmdpjc23cxd7axkc8j0yvq5cfhw5-postgresql-15.6-man
/nix/store/xzmgdglbldim3k39pjn16vrgxb3i72as-publicsuffix-list-0-unstable-2024-01-07
/nix/store/k3701zl6gmx3la7y4dnflcvf3xfy88kh-python3-3.11.9
/nix/store/95qcp9a6c8kk1aahclj2g7kjzrvzix49-qrencode-4.1.1
5 months ago
3.11 is the default
Seems the runtime.txt in the repo root might not be read. For safety I think I'll try adding the variable you mentioned earlier. Couldn't hurt I imagine
✕ [stage-0 6/13] RUN nix-env -if .nixpacks/nixpkgs-e05605ec414618eab4a7a6aea8b38f6fbbcc8f08.nix && nix-collect-garbage -d
process "/bin/bash -ol pipefail -c nix-env -if .nixpacks/nixpkgs-e05605ec414618eab4a7a6aea8b38f6fbbcc8f08.nix && nix-collect-garbage -d" did not complete successfully: exit code: 1
Dockerfile:10
-------------------
8 | RUN nix-env -if .nixpacks/nixpkgs-5148520bfab61f99fd25fb9ff7bfbb50dad3c9db.nix && nix-collect-garbage -d
9 | COPY .nixpacks/nixpkgs-e05605ec414618eab4a7a6aea8b38f6fbbcc8f08.nix .nixpacks/nixpkgs-e05605ec414618eab4a7a6aea8b38f6fbbcc8f08.nix
10 | >>> RUN nix-env -if .nixpacks/nixpkgs-e05605ec414618eab4a7a6aea8b38f6fbbcc8f08.nix && nix-collect-garbage -d
11 |
12 |
-------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c nix-env -if .nixpacks/nixpkgs-e05605ec414618eab4a7a6aea8b38f6fbbcc8f08.nix && nix-collect-garbage -d" did not complete successfully: exit code: 1
Error: Docker build failed
Not exactly sure what went wrong here, I assume it didn't accept the version of python ?
5 months ago
Can you show the first few lines from your build logs?
e.g.
[Region: us-west1]
==============
Using Nixpacks
==============
context: 502e3d7d84f9e67f22cc31deb908355f
╔══════ Nixpacks v1.29.1 ══════╗
║ setup │ go ║
║──────────────────────────────║
║ install │ go mod download ║
║──────────────────────────────║
║ build │ go build -o out ║
║──────────────────────────────║
║ start │ ./out ║
╚══════════════════════════════╝
did re-check variables, and I did write it correctly with NIXPACKSPYTHONVERSION equaling 3.8.4
5 months ago
the Python version seems to be right according to the python:setup
(python38), I have no idea why postgresql is there tho
I have some other variables as I inserted my full backend .env to ensure the backend is as close to my local one as possible when trying to deploy
5 months ago
<:mildpanic:804271964587819059>
Like I said, it's a company server that I need to host non-locally for my exam…it's not very well made by them 🙃
But yeah, overall, the python version made it crash before getting to the requirements so I'm confused on what to do from here I will admit
5 months ago
Interesting, so it did work with 3.11?
well it got to the requirements, where it failed on pandas-stubs due to a lack of a proper python version for what it wanted
5 months ago
Can you paste the full build logs for the latest build (the one where you specified Python 3.8)?
5 months ago
well, I am kinda lost on why it doesn't work so I don't think that will help <:mildpanic:804271964587819059>
5 months ago
if you have the time, please wait for someone that is smarter than me to help you
No worries, thanks for your help, I appreciate it <:amyzH:898576092384866345>
5 months ago
are you able to share the repo?
But I can share the requirements and what not if that's what you're looking at
5 months ago
have you ran this project locally?
Yes, over the last 10 weeks, I've worked on my exam project on it. I just need to host it as the final requirement
5 months ago
do you need node when running it locally?
I ran it through 2 git node terminals in Cursor / VS Code, one for frontend running npm run start and one running flask through a virtual environment with flask run
5 months ago
lets focus on the backend only for now please
5 months ago
do you need node to run the backend
I do not believe I do no. I don't remember using any node commands to run it, but just venv and flask
5 months ago
can you start by removing the node provider then
5 months ago
yes you would want to click the deploy button after making that change
I added a new git commit to reflect a requirement removal from the .txt, but how do I attempt another deploy with this git commit in mind? I don't see a deploy with latest commit or similar anywhere, only the last deploy and it having a "Redeploy" button
5 months ago
CMD + K > Deploy latest commit
Seems the build is successfully running now, but the deploy fails pretty much immediately
5 months ago
ah its wants the firebase json file
5 months ago
you have that locally right?
I should have, though I feel like I had it in the .env I posted in there, but give me a moment
5 months ago
you dont put json files into .env
Nono I know that, but the firebase details I meant. It's a recent addition, not made by me, as I've not worked with firebase before, so I could've missed a file I needed to put in
5 months ago
you would want to base64 encode the json file, and then put the base64 string into a service variables, then have some code that runs on start to read that environment variable, decrypt it, and write it to the appropriate file, so that the firebase library can read from the file
I do have a pwa_key.json file which has some firebase data in it, which is ignored by git on commit.
I honestly have no clue how to do what you suggested, but I assume the file is already being read somehow by the system since firebase works with that file locally
5 months ago
the file is not being uploaded to railway, thats a good thing, but you'll need to do what i suggested
Well I will have to figure out how to do that then, cause at the moment I don't know how to, as it is not something I've developed, someone else did
5 months ago
few Google searches away and you'll be good
Slight update on this issue:
It seems to run now after changing some firebase thing, however I am unable to connect the Redis service I've also created to this. Again I am a student and I've not worked with Redis before so could easily just be me being a goof, but if someone could help me take a quick look at my setup, I'd greatly appreciate it 🙂
I've currently set up the redis service, and have changed the redis_url variable to reflect this new url, but it does not seem to like it. the code that runs the worker itself is not static so it should in theory work, but maybe I forgot to do something.
Any help is appreciated <:widepeepohappy:585535359505399824>
Not gonna ping you due to rules, but I saw another thread regarding python-magic that you helped with some time ago Brody, which seems to be my issue as well, despite it being installed via my requirements.txt, so if you're able, I'd greatly appreciate it
5 months ago
happy to help but I'd need you to send me the errors you are getting
Of course, it mainly seems that libmagic is not being read properly, the error being the following:
Starting Container [2025-01-19 17:06:33 +0000] [1] [INFO] Starting gunicorn 20.1.0 [2025-01-19 17:06:33 +0000] [1] [INFO] Listening at: http://0.0.0.0:39453 (1) [2025-01-19 17:06:33 +0000] [1] [INFO] Using worker: sync [2025-01-19 17:06:33 +0000] [5] [INFO] Booting worker with pid: 5 Temporary folder 'tmp' has been created. Firebase app initialized [2025-01-19 17:06:37 +0000] [5] [ERROR] Exception in worker process File "", line 975, in _find_and_load_unlocked Traceback (most recent call last): File "", line 671, in _load_unlocked File "", line 843, in exec_module File "/opt/venv/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker File "", line 219, in _call_with_frames_removed worker.init_process() File "/app/run.py", line 5, in app = create_app(config("CONFIG_NAME")) File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process File "/app/api/app.py", line 123, in create_app from api.blueprints.fake import fake self.load_wsgi() File "/app/api/blueprints/fake.py", line 34, in File "/opt/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi from api.services.openai_api import generete_tutor_bio, TutorBioResponse self.wsgi = self.app.wsgi() File "/app/api/services/openai_api.py", line 20, in from api.langchain.rag import ( File "/opt/venv/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi File "/app/api/langchain/rag.py", line 3, in self.callable = self.load() import magic File "/opt/venv/lib/python3.8/site-packages/magic/__init__.py", line 209, in libmagic = loader.load_lib() File "/opt/venv/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load File "/opt/venv/lib/python3.8/site-packages/magic/loader.py", line 49, in load_lib return self.load_wsgiapp() raise ImportError('failed to find libmagic. Check your installation') ImportError: failed to find libmagic. Check your installation File "/opt/venv/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp return util.import_app(self.app_uri) File "/opt/venv/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app mod = importlib.import_module(module) File "/root/.nix-profile/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load [2025-01-19 17:06:37 +0000] [5] [INFO] Worker exiting (pid: 5) [2025-01-19 17:06:39 +0000] [1] [INFO] Shutting down: Master [2025-01-19 17:06:39 +0000] [1] [INFO] Reason: Worker failed to boot.
5 months ago
you said that you saw me help with this In a thread before, did that thread get solved?
Was a different version of python but it seems a dockerfile was used, which I have also tried, but to no success
5 months ago
can you define no success?
This is the dockerfile so far:
FROM python:3.8.4-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
RUN apt-get update && apt-get install -y \
libmagic-dev \
file \
build-essential \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
RUN python -c "import magic; print(magic.Magic)"
EXPOSE 5000
CMD ["gunicorn", "run:app", "--bind", "0.0.0.0:5000"]
libmagic 1.0 and python-magic 0.4.27 are specified in my requirements.txt already, but I'm not sure why exactly, but my guess is that one of them doesn't seem to get properly recognized
5 months ago
so with that Dockerfile you get the error you sent above?
5 months ago
how do you know the Dockerfile is being used to do the build?
I assume it is from seeing libmagic being installed 2 seperate places, one of which using the .gz file as shown in the pic
5 months ago
check the very top of the logs
5 months ago
you'll know when you see it
5 months ago
it will tell you what the build was done with
5 months ago
it says nixpacks haha
5 months ago
your Dockerfile isn't being used
5 months ago
Do you have your Dockerfile named Dockerfile
? capital D and all, and do you have it placed into the same folder as you've set for your root directory
5 months ago
capital D is needed
It seems to detect my dockerfile now, however, I don't see the nixpacks stuff now, with the setup, install and start commands. Is that something I should be worried about ?
5 months ago
no, Dockerfile and nixpacks are different, you only use one or the other
Alright.
It seems now this happens in the build
Collecting psycopg2==2.9.9
Downloading psycopg2-2.9.9.tar.gz (384 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-omwe95rq/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-omwe95rq/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-q5cw91q1
cwd: /tmp/pip-install-omwe95rq/psycopg2/
Complete output (23 lines):
running egg_info
creating /tmp/pip-pip-egg-info-q5cw91q1/psycopg2.egg-info
writing /tmp/pip-pip-egg-info-q5cw91q1/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-q5cw91q1/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-q5cw91q1/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-q5cw91q1/psycopg2.egg-info/SOURCES.txt'
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
;).
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.1.1; however, version 24.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
✕ [5/6] RUN pip install --no-cache-dir -r requirements.txt
process "/bin/sh -c pip install --no-cache-dir -r requirements.txt" did not complete successfully: exit code: 1
Dockerfile:22
-------------------
20 |
21 | # Install Python dependencies
22 | >>> RUN pip install --no-cache-dir -r requirements.txt
23 |
24 | # Verify libmagic is installed correctly
-------------------
ERROR: failed to solve: process "/bin/sh -c pip install --no-cache-dir -r requirements.txt" did not complete successfully: exit code: 1
I imagine it's still related to libmagic despite it failing on psycopg2's installation, but I am not really sure, as neither were installed by me
5 months ago
can you replace it with the binary version as it suggests?
tried commenting out the psycopg2 installation and using the psycopg2-binary installation that was also in the requirements.txt, which leads to the build succeeding again, but the deploy giving that same error about failing to locate libmagic and being asked to check for installation
Doesn't seem to be found while building either from the dockerfile checking the installation
[6/6] RUN python -c "import magic; print(magic.Magic)"
[6/6] RUN python -c "import magic; print(magic.Magic)" ✔ 2s
5 months ago
not sure why you are mentioning libmagic, your latest error is something about jwt, when looking at logs please carefully read them
It seems to be running now, but is there a console or similar I can use to test it ?
5 months ago
no console, isnt this a web app?
5 months ago
Well I appreciate all the help greatly, it's taken a load off the mental for the exam coming soon <:amyzH:898576092384866345> I have some CORS to work through before the url is allowed for my application but that should hopefully not be too hard to manage on my own
5 months ago
sounds good, am i good to mark as solved?
5 months ago
!s
Status changed to Solved brody • 5 months ago