a year ago
Does anyone have any experience using the CLI in CI? I can do all of the commands locally (but ran into this problem a ton locally initially, until I generated the newest one), can verify that RAILWAY_API_TOKEN is set in github CI, but I keep getting Project Token not found or No linked project found. Run railway link to connect to a project, and a service. I've sunk 5+ hours on this and can't find much online, and chatgpt is not useful. Dev Ops is not my strong suit. I can't use link, because it requires me to login. I can't login, because it's in the CI…
Would love an example of someone waiting for the deployment in the CI, generating a domain for it, and extracting the url.
I need to do this to get the server url and forward it to our front end on vercel. I need to do this for dev/main and preview branches, so I can't use a project token.
32 Replies
a year ago
waiting for the deployment in the CI -> railway up --ci
generating a domain for it and extracting the url -> DOMAIN=$(railway domain)
I can't use any railway command in the CI is my issue. I get the error messages Project Token not found
or No linked project found. Run railway link to connect to a project, and a service.
I know the environment variable is there and set. I can run a check for the variable, I've regenerated it so many times and reset the github secrets, and I can use the latest token locally and get responses.
a year ago
RAILWAY_API_TOKEN is not a project token though
a year ago
It's an account token? https://docs.railway.com/guides/cli#account-tokens
a year ago
yes
Do I not want to be using an account token? I am confused. I've gotten it to work locally. I even unlinked and reset railway CLI locally to make sure it wasn't using any pre-existing auth before I tried this flow locally.
Logs from github:
RAILWAY_API_TOKEN is set. Proceeding with Railway deployment.
RAILWAY_API_TOKEN is set. Proceeding with Railway deployment.
RAILWAY_TOKEN is not set. Proceeding with Railway deployment.
> Installing railway, please wait…
.
/^\ .
/\ "V"
/__\ I O o
//..\\ I . Poof!
\].`[/ I
/l\/j\ (] . O
/. ~~ ,\/I . Railway is now installed
\\L__j^\/I o Run `railway help` for commands
\/--v} I o .
| | I _________
| | I c(` ')o
| l I \. ,/
_/j L l\_! _//^---^\\_
Railway CLI installed successfully.
No linked project found. Run railway link to connect to a project, and a service.Bash script:
if [ -z "${{ secrets.RAILWAY_API_TOKEN }}" ]; then
echo "RAILWAY_API_TOKEN is not set. Skipping Railway deployment."
exit 0
else
echo "RAILWAY_API_TOKEN is set. Proceeding with Railway deployment."
fi
if [ -z "$RAILWAY_API_TOKEN" ]; then
echo "RAILWAY_API_TOKEN is not set. Skipping Railway deployment."
exit 0
else
echo "RAILWAY_API_TOKEN is set. Proceeding with Railway deployment."
fi
if [ "$RAILWAY_TOKEN" ]; then
echo "RAILWAY_TOKEN is set. Skipping Railway deployment."
exit 0
else
echo "RAILWAY_TOKEN is not set. Proceeding with Railway deployment."
fi
curl -fsSL https://railway.app/install.sh | sh
echo "Railway CLI installed successfully."
POLL_INTERVAL=10
TIMEOUT=600
TIME_ELAPSED=0
SERVICE_NAME="api"
ENVIRONMENT=web-app-pr-${{ steps.pr-number.outputs.result }}
railway environment $ENVIRONMENTa year ago
did you delete the config.json locally?
a year ago
what even is your end goal here?
a year ago
$HOME/.railway
I am using the preview environment to auto deploy. I then want to watch for my api service to be deployed, generate a domain name for it, then use that url in my vercel build.
a year ago
may i ask what you are running on vercel that cant be ran on railway?
It's our nextjs app. I have slowly been convincing the team to move away from vercel, but it's a process.
However, I'd want the url from the deployment either way, as we run the playwright tests against the deployed preview environment to ensure that everything is good in a deployment environment before pushing to prod.
a year ago
is it? one night we just decided to run railway.com on railway instead of vercel, and its been working great ever since
They are big fans of vercel and we are using nextjs, they want to keep the web apps on it for now, and see how the api goes first.
Getting this pipeline working, which I'd need even if we had it all on vercel because of how we run playwright tests, would be very beneficial in convincing the team 🙂
a year ago
(railway.com is nextjs)
So are you trying to use the cli to create the PR env?
I am allowing railway to auto create the environment with the preview option turned on. I am just wanting to use the CLI to wait for it to be finished building (but using up --cimight be better if it reuses/closes environments on PRs for us), then generate the domain, and use it later in the github CI
a year ago
so all you really want to do is get the domain for a service that exists within the pr env?
a year ago
you mentioned generating a domain, but why wouldnt the service have a domain to begin with?
If it has a generated public domain already for previews, awesome! Ya, that is all I want 🙂
a year ago
if the base service has a domain, so will the service in the pr env
I did delete my $HOME/.railway file, and the RAILWAY_API_TOKEN way I was doing it locally no longer works. Good call, so I am doing something wrong
a year ago
honestly, youd likely want to write some javascript to call the api and get the domain for a given service in a given environment
Well, I can do that. Kinda weird to have to do that imo.
I'll take a look at the graphql docs then for where I can ping for this info
a year ago
projectenvironmentConfig
pretty sure those are the only two you need, the frontend uses the same api, so you can just look at the fetch requests it makes
a year ago
let me know if you are having any trouble with the api