2 months ago
Does Railway expose a "correct" way to update a production environmental variable programmatically so that it's live in the container service?
For background - We have a sandbox image ID which is built when a merge to main takes place. This is an indempotent image ID so the API service in railway needs to be aware of this
I'm finding myself doing this which i I think is brittle beacuse of race conditions between deployment + Github Actions
- name: Publish sandbox image
id: publish
run: |
set -euo pipefail
RAILWAY_ARGS=()
RAILWAY_FLAG_INPUTS="${RAILWAY_TOKEN:-}${RAILWAY_PROJECT_ID:-}${RAILWAY_SERVICE_ID:-}"
if [ -n "${RAILWAY_FLAG_INPUTS}" ] && { [ -z "${RAILWAY_TOKEN:-}" ] || [ -z "${RAILWAY_PROJECT_ID:-}" ] || [ -z "${RAILWAY_SERVICE_ID:-}" ]; }; then
echo "RAILWAY_TOKEN, RAILWAY_PROJECT_ID, and RAILWAY_SERVICE_ID must all be set together." >&2
exit 1
fi
if [ -n "${RAILWAY_TOKEN:-}" ] && [ -n "${RAILWAY_PROJECT_ID:-}" ] && [ -n "${RAILWAY_SERVICE_ID:-}" ]; then
RAILWAY_ARGS+=(--railway --railway-service "${RAILWAY_SERVICE_ID}")
# Update env vars without triggering a Railway deploy during image publish.
RAILWAY_ARGS+=(--railway-skip-deploys)
if [ -n "${RAILWAY_ENVIRONMENT:-}" ]; then
RAILWAY_ARGS+=(--railway-env "${RAILWAY_ENVIRONMENT}")
fi
fi
[truncated]
- name: Redeploy Railway service
if: ${{ env.RAILWAY_TOKEN != '' && env.RAILWAY_PROJECT_ID != '' && env.RAILWAY_SERVICE_ID != '' }}
run: |
set -euo pipefail
LINK_ARGS=(--project "${RAILWAY_PROJECT_ID}" --service "${RAILWAY_SERVICE_ID}")
if [ -n "${RAILWAY_ENVIRONMENT:-}" ]; then
LINK_ARGS+=(--environment "${RAILWAY_ENVIRONMENT}")
fi
railway link "${LINK_ARGS[@]}"
railway redeploy --service "${RAILWAY_SERVICE_ID}" -y4 Replies
2 months ago
Correct way to update Railway Vars in a production service
2 months ago
Are you asking if it's possible to inject variables into an already running service without having to redeploy for the app to see the new variables? If so, unfortunately, the answer would be no.
2 months ago
I'm asking about how I would go about updating environmental variables post deploy? Is the only route to update the variable via the graphQL API and then redeploy
2 months ago
I'm sorry but I don't follow, can you maybe give me a breakdown of your ideal timeline of actions?