accessing a fly secret (DATABASE_URL) from Github actions

I have Vitest and Playwright tests that need the DATABASE_URL env variable.
right now they fail for trying to access the db at localhost:5432 which is not there.
I’ve tried setting this in my deploy.yml but it doesn’t work.


What do I need to do to pass the DATABASE_URL secret from to my Github action?


I don’t believe you can extract it directly to use in your Action, since Fly stores secrets encrypted (as you’d hope) and they are only decrypted when injected into the vm when it boots. However you can access it since of course you have access to your own vms. So run fly ssh console from the folder your fly.toml is in. That should load you into the vm, and then run echo $DATABASE_URL to see what it is.

Now that you know what it is, you simply need to provide it to Github. In your repo’s “Settings” tab, click on “Secrets and variables” in the left-hand column, then on “Actions”. Click the green button to add a new secret. Call it DATABASE_URL and put the value in there.

Now it’s available for your Github Actions to use via a reference :slight_smile: Of course if the URL uses a private Fly domain (an .internal one) then Github would not be able to resolve it (since the Github Action will normally run on a cloud instance outside of Fly). But that’s another question.

1 Like

Thank for! Thats very helpful, thanks:)

1 Like