a year ago
This is my github action:
name: Deploy to Railway
...
jobs:
deploy:
runs-on: ubuntu-latest
env:
RAILWAY_DASHING_SERVICE: ${{ secrets.RAILWAY_DASHING_SERVICE }}
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
steps:
...
- name: Unlock git-crypt
run: |
echo "${{ secrets.GIT_CRYPT_KEY }}" | base64 -d > git-crypt.key
git-crypt unlock git-crypt.key
rm git-crypt.key
- name: Install Railway CLI
run: |
curl -fsSL https://railway.app/install.sh | sh
- name: Set env vars on Railway
run: |
./build/sync-railway-vars.sh ${{ secrets.RAILWAY_DASHING_SERVICE }} .env.production
- name: Deploy
run: railway up --service=${{ env.RAILWAY_DASHING_SERVICE }}
This worked fine. Im using git crypt to unlock the env file and push the variables using a script (will attach as comment). It set them every time not had issues with it
But i just realised i need to deploy my main app and a worker container. So moved to deploy via linking to github so it would deploy both by making it wait for CI. So i removed the last step
- name: Deploy
run: railway up --service=${{ env.RAILWAY_DASHING_SERVICE }}^ this is removed.
But now when i deploy, it runs the github CI, deploys just fine the application crashes because
Failed to parse dotenv file. Encountered an invalid name at [\GITCRYPT\?s?,R?䴛'\$;??<?8??Q&?8B??8!??p???Z??8??T??j3?]R??:?\?D.???q?x/-[?\P??&??&?lY??g??&գxN???i?q\???,????C?l?d?Nʢ? ?}???/?*G?:???
??i))?8?].So on the container i ran:
printenv | sort
...
ENV_FILE=.env.production
...^ i didnt set that. Not was it in my env file. Not does it show on railway. So im guessing something with github process is setting it
So i just thought, i would set it via railway to ENV_FILE=.env and redeploy. This doesnt work. Same issue. It now reads
printenv | sort | grep ENV_FILE
ENV_FILE=.envBut still the application fails because of the gitcrypt issue.
There is no .env file overriding it:
root@5661a2a36f9e:/application# ls -la | grep .env
-rw-rw-r-- 1 www-data www-data 1854 Jun 4 17:29 .env.example
-rw-rw-r-- 1 www-data www-data 3533 Jun 4 17:29 .env.production
-rw-rw-r-- 1 www-data www-data 1731 Jun 4 17:29 .env.testing
root@5661a2a36f9e:/application#No other env var using that file:
printenv | sort | grep ".env.production"returns nothing.
I used the raw .env file editor and there are no badly formatted GITCRYPT variables.
Can anyone suggest whats different about deploying from github?
This issue only exists when i am deploying by linking the github.
Pinned Solution
a year ago
Ah i looks like when moving to Github, its using nixpacks to deploy my application. So i assume its deploying my base code and not building and somehow using the .env.production.
Is there no way deploying from github can deploy using the container?
My main aim is to push and it deploy to multiple services, my app and my worker service
3 Replies
a year ago
Script to push env vars to railway
#!/bin/bash
# Exit on error
set -e
# Usage: ./sync-railway-vars.sh SERVICE_ID [ENV_FILE]
SERVICE_ID=$1
ENV_FILE=${2:-.env.production}
if [[ -z "$SERVICE_ID" ]]; then
echo "Usage: $0 <RAILWAY_SERVICE_ID> [.env file (default: .env.production)]"
exit 1
fi
if [[ ! -f "$ENV_FILE" ]]; then
echo "Error: '$ENV_FILE' not found"
exit 1
fi
ARGS=()
while IFS='=' read -r key value; do
# Ignore empty lines and lines starting with #
[[ -z "$key" || "$key" =~ ^#.*$ ]] && continue
# Remove inline comments (anything after a #, unless inside quotes)
value="${value%%#*}"
# Remove surrounding quotes
value="${value%\"}"
value="${value#\"}"
# Remove any remaining whitespace
value="$(echo -e "${value}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Skip if key is empty after trimming
[[ -z "$key" ]] && continue
ARGS+=(--set "${key}=${value}")
done < "$ENV_FILE"
echo "Setting ${#ARGS[@]} variables to Railway..."
railway variables "${ARGS[@]}" --service "$SERVICE_ID"a year ago
Ah i looks like when moving to Github, its using nixpacks to deploy my application. So i assume its deploying my base code and not building and somehow using the .env.production.
Is there no way deploying from github can deploy using the container?
My main aim is to push and it deploy to multiple services, my app and my worker service
a year ago
Yeah. It is using Nixpacks to build any deploy.
I would suggest using the Railway API to redeploy your service, and instead of selecting GitHub for the service type, select docker image. Before asking Railway to redeploy, build and push your app to GHCR. Then use that image.
Status changed to Solved chandrika • 12 months ago