2 months ago
Hello, my goal is to run my After Party tasks automatically. I had set up a Github Action, created my RAILWAY_TOKEN so it can access the environment, etc. I can not get past the following error (from GH action logs):
PG::ConnectionBad: could not translate host name "postgres.railway.internal" to address: Name or service not known (PG::ConnectionBad)I assume this means that it can't use the internal DB host inside GH Actions. Which makes sense. But I can't escape this error even when passing in the DB URL, I imagine because it's still trying to pull in the environment variable on the service itself. Any ideas? It would be great if Railway could expand their GH actions examples from just the one runner in their docs. Thanks for any help.
0 Replies
2 months ago
Are you trying to connect to the Postgres database directly from GitHub actions?
Well I am trying to use the Railway CLI as defined in this blog post.
EDIT: Solved
My latest iteration, where I manually pass in the database URL, gave me a new error, which gave me a clue. There was a DB index error, and it was coming from another DB. So I had to manually pass in the Public Database URL for all my databases. Here is the working action. Hope it helps someone!
# .github/workflows/post-deploy.yml
name: Post-deploy tasks
on:
deployment_status:
states: [success]
jobs:
deploy:
runs-on: ubuntu-latest
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
RAILS_API_SVC_ID:
MAIN_DB_URL:
QUEUE_DB_URL:
CABLE_DB_URL:
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true
- name: Install Railway CLI
run: |
curl -fsSL https://railway.app/install.sh | sh
echo "$HOME/.railway/bin" >> "$GITHUB_PATH"
- name: Run After Party tasks
run: |
railway run --service ${{ env.RAILS_API_SVC_ID }} sh -c 'RAILS_ENV=production \
DATABASE_URL="$MAIN_DB_URL" \
QUEUE_DATABASE_URL="$QUEUE_DB_URL" \
CABLE_DATABASE_URL="$CABLE_DB_URL" \
bundle exec rails after_party:run'