3 months ago
I'm trying to get a new Python/Flask project deployed, and nothing I'm doing is working. I tried deploying it with Railpack, and it doesn't look like it installed any of the dependencies. At least, when it got to the healthcheck step, it failed to launch the service because gunicorn couldn't be found, despite being clearly listed in my pyproject.toml as a dependency.
I tried switching to a Nixpack build since I have similar projects running successfully. That doesn't even get that far as it fails during the build step. I'm not sure if you have access to the logs, but you can see a long history of failed deployments, if so. Otherwise, let me know, and I can pull some of them to share with you.
The major difference between this and my other projects is that I've split my monorepo into individual private repos on GitHub, and I've switched to a pyproject.toml project set-up (instead of just requirements.txt). The various individual repos are linked together using git+ssh dependencies. There's nothing definite in the logs (from what I can see) that points in that direction, but it may be relevant.
Pinned Solution
3 months ago
I finally did work out the issue here. First problem was that bash isn't actually the shell being used, so things like if [[ ... ]] and source were failing to execute. When I switched to pure posix-compliant syntax, I found that I couldn't install my virtual environment anywhere outside the /app directory. But, when I installed everything inside the /app/venv directory, and used . (instead of source) to run the activate command, things worked out. I needed to be sure to do so in both the build script (to get the dependencies in the right place), and in the start script (to be sure to use them), but that got me over the hurdle of actually getting the script to run.
For reference, here's the final build script:
#/usr/bin/env sh
VENV_DIR="./authmo/venv"
python -m venv "${VENV_DIR}"
if [ ! -d "${VENV_DIR}" ]; then
echo "Failed to create virtual env."
exit 125
fi
. "${VENV_DIR}/bin/activate"
echo "Using pip: $(which pip)"
pip install --upgrade pip
pip install authmo_common@git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/authmo/common
pip install authmo_sql@git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/authmo/sql
pip install .And here's the final startup script:
#/usr/bin/env sh
VENV_DIR="./authmo/venv"
. "${VENV_DIR}/bin/activate"
echo "Using python: $(which python)"
SERVICE_NAME="www2-web" python -m gunicorn "authmo_www.web.server:launchApp()"6 Replies
3 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
3 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open ray-chen • 3 months ago
3 months ago
hey your issue is definitely the git+ssh dependencies railway can't access them during build
ti fix this follow this steps:
create a GitHub Personal Access Token (Settings → Developer settings → PAT with repo access)
add it to Railway as an environment variable:
GITHUB_TOKENin your
pyproject.toml, change your private repo deps from:
my-package = { git = "git+ssh://git@github.com/user/repo.git" }to:
my-package = { git = "https://x-access-token:${GITHUB_TOKEN}@github.com/user/repo.git" }and make sure you have a
nixpacks.toml:
[phases.setup]
nixPkgs = ["python310", "poetry"]
[phases.install]
cmds = ["poetry install --no-dev"]
[start]
cmd = "poetry run gunicorn app:app --bind 0.0.0.0:$PORT"the SSH keys just aren't available in railway's build env, so switching to HTTPS with the token should get you up and running. also double-check that gunicorn is in your main dependencies, not dev-dependencies.
let me know if that doesn't work
3 months ago
Thanks for the pointer! The general idea was good, but some of the details needed adjustment:
pyproject.tomldoesn't support command-line substitution at all, so including the credentials in the dependencies list does you no good.You need provide the user name who created the token (i.e., not "x-access-token") in the credentials.
So, I truncated the dependency in pyproject.toml to the mere package name, and included a setup_prod.sh script which does the installation of the two private dependencies using HTTPS. At this point, the build seems to run successfully with all packages installed (see attached log).
Unfortunately, I'm still getting the same error during the deploy stage:
/mise/installs/python/3.13.11/bin/python: No module named gunicorn
Also, I'm using Railpack, so your nixpacks.toml isn't applicable in this case. The Railpack version does seem to install Python correctly though, and pipis available as demonstrated in the log. But... there's still that error. This makes me think the version of pip accessible to my script doesn't correspond with the version of Python actually running at launch. Normally, I'd just log on to the machine and run which to double-check things, but I can't find any way to do that here. Any suggestions?
Attachments
3 months ago
I finally did work out the issue here. First problem was that bash isn't actually the shell being used, so things like if [[ ... ]] and source were failing to execute. When I switched to pure posix-compliant syntax, I found that I couldn't install my virtual environment anywhere outside the /app directory. But, when I installed everything inside the /app/venv directory, and used . (instead of source) to run the activate command, things worked out. I needed to be sure to do so in both the build script (to get the dependencies in the right place), and in the start script (to be sure to use them), but that got me over the hurdle of actually getting the script to run.
For reference, here's the final build script:
#/usr/bin/env sh
VENV_DIR="./authmo/venv"
python -m venv "${VENV_DIR}"
if [ ! -d "${VENV_DIR}" ]; then
echo "Failed to create virtual env."
exit 125
fi
. "${VENV_DIR}/bin/activate"
echo "Using pip: $(which pip)"
pip install --upgrade pip
pip install authmo_common@git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/authmo/common
pip install authmo_sql@git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/authmo/sql
pip install .And here's the final startup script:
#/usr/bin/env sh
VENV_DIR="./authmo/venv"
. "${VENV_DIR}/bin/activate"
echo "Using python: $(which python)"
SERVICE_NAME="www2-web" python -m gunicorn "authmo_www.web.server:launchApp()"3 months ago
your replies that I've seen across this and some other threads are sounding suspiciously like AI... in the bounty rules it says that you can't use AI to produce or enhance your bounty answers and doing so will get you banned from participating in them so just be careful
if you're not using AI then I apologize, that's just how it came across to me
andrewminer
I finally did work out the issue here. First problem was that bash isn't actually the shell being used, so things like if [[ ... ]] and source were failing to execute. When I switched to pure posix-compliant syntax, I found that I couldn't install my virtual environment anywhere outside the /app directory. But, when I installed everything inside the /app/venv directory, and used . (instead of source) to run the activate command, things worked out. I needed to be sure to do so in both the build script (to get the dependencies in the right place), and in the start script (to be sure to use them), but that got me over the hurdle of actually getting the script to run.For reference, here's the final build script:#/usr/bin/env sh VENV_DIR="./authmo/venv" python -m venv "${VENV_DIR}" if [ ! -d "${VENV_DIR}" ]; then echo "Failed to create virtual env." exit 125 fi . "${VENV_DIR}/bin/activate" echo "Using pip: $(which pip)" pip install --upgrade pip pip install authmo_common@git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/authmo/common pip install authmo_sql@git+https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/authmo/sql pip install .And here's the final startup script:#/usr/bin/env sh VENV_DIR="./authmo/venv" . "${VENV_DIR}/bin/activate" echo "Using python: $(which python)" SERVICE_NAME="www2-web" python -m gunicorn "authmo_www.web.server:launchApp()"
3 months ago
Thank you! I'm paying out to $10 bounty to you for the great answer 
Status changed to Awaiting User Response Railway • 3 months ago
Status changed to Solved ray-chen • 3 months ago

