Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add a way to create the postgres cluster if it doesn't exist #23

Draft
wants to merge 1 commit into
base: upstream
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ If you have an existing `fly.toml` in your repo, this action will copy it with a
| `region` | Which Fly region to run the app in. Alternatively, set the env `FLY_REGION`. Defaults to `iad`. |
| `org` | Which Fly organization to launch the app under. Alternatively, set the env `FLY_ORG`. Defaults to `personal`. |
| `path` | Path to run the `flyctl` commands from. Useful if you have an existing `fly.toml` in a subdirectory. |
| `postgres` | Optional name of an existing Postgres cluster to `flyctl postgres attach` to. |
| `postgres` | Optional name of a new or existing Postgres cluster to `flyctl postgres attach` to. |
| `postgres_standalone` | If "true", the Postgres cluster specified by `postgres` will be created as necessary and deleted during teardown. |
| `update` | Whether or not to update this Fly app when the PR is updated. Default `true`. |
| `secrets` | Secrets to be set on the app. Separate multiple secrets with a space |
| `vmsize` | Set app VM to a named size, eg. shared-cpu-1x, dedicated-cpu-1x, dedicated-cpu-2x etc. Takes precedence over cpu, cpu kind, and memory inputs. |
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ inputs:
description: path to a directory containing a fly.toml to clone
postgres:
description: Optionally attach the app to a pre-existing Postgres cluster on Fly
postgres_standalone:
description: If true, create the postgres cluster specified by the 'postgres' input, and destroy it on teardown
secrets:
description: Secrets to be set on the app. Separate multiple secrets with a space
vmsize:
Expand Down
11 changes: 11 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ fi
# PR was closed - remove the Fly app if one exists and exit.
if [ "$EVENT_TYPE" = "closed" ]; then
flyctl apps destroy "$app" -y || true
if [ -n "$INPUT_POSTGRES" && "$INPUT_POSTGRES_STANDALONE" = "true" ]; then
flyctl apps destroy "$INPUT_POSTGRES" -y || true
fi
exit 0
fi

# Create postgres app if necessary
# TODO: do we want the postgres app specs to be configurable?
if [ -n "$INPUT_POSTGRES" && "$INPUT_POSTGRES_STANDALONE" = "true" ]; then
if ! flyctl status --app "$INPUT_POSTGRES"; then
flyctl postgres create --name "$INPUT_POSTGRES" --region "$region" --org "$org" --vm-size shared-cpu-1x --volume-size 1 --initial-cluster-size 1 || true
fi
fi

# Deploy the Fly app, creating it first if needed.
if ! flyctl status --app "$app"; then
# Backup the original config file since 'flyctl launch' messes up the [build.args] section
Expand Down