How to automate flyctl

I’m trying to automate some deployments, and am having to respond to prompts, and that’s not really good when scripting. When launching, I get a prompt for copying an existing fly.toml configuration to the new app. And, when creating a new postgres instance, I’m prompted to select the desired configuration (Development, Production, etc). How can I supply the responses to these prompts programatically?

Some commands have flags that skip prompts, but not for everything.

The best way might be to use our API directly if that’s at all possible from your automation.

If not, we can look into making sure no prompts are required, given the proper flags.

For postgres, you might skip prompts by providing these 3 flags: volume-size, initial-cluster-size and vm-size.

For launch, you might need to temporarily rename your fly.toml or invoke the command from a directory where there is not fly.toml.

What I want to do is flyctl postgres detach -a app_name --postgres-app-name in a shell script, but this command always presents a prompt for me to use the arrow keys to select the attachment I want to detach. I’ve found that I can do this like this:
echo "" | flyctl postgres detach -a app_name --postgres-app-name
You can close this issue.

1 Like

For what it’s worth, fly launch wasn’t quite designed to be scripted. Usually you’re better off running that once, committing the results, then just running fly deploy when it’s needed.

Postgres attach/detach should be scriptable, though. We can make that a little nicer.

What we’re trying to do is spin up a preview app whenever a pull request is opened in github - we need to launch a new app whenever that happens, with the PR number as part of the app name e.g. preview_pr_####. So, in the script that github’s CI runs, we can launch like this:

    --no-deploy \
    --copy-config \
    --name "$app" \
    --region "$region" \
    --org "$org" \
    --remote-only=false \
    --verbose \
    --dockerfile ./Dockerfile \
    --path .

That seems to work fine.
When we close the PR, we want to tear that whole app down, including dropping the database and the database user. That’s where scripting flyctl postgres detach comes in. I think I have it all working now.
Thanks for your help

1 Like