Skip to content
Merged
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
38 changes: 37 additions & 1 deletion .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
FLY_APP_NAME: ${{ vars.FLY_APP_NAME }}
FLY_PRIMARY_REGION: ${{ vars.FLY_PRIMARY_REGION }}
FLY_VOLUME_NAME: ${{ vars.FLY_VOLUME_NAME }}
FLY_VOLUME_SIZE_GB: ${{ vars.FLY_VOLUME_SIZE_GB }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -40,7 +43,40 @@ jobs:
exit 1
fi

APP_NAME="${FLY_APP_NAME:-yappybara-api}"
APP_FROM_CONFIG="$(sed -n 's/^app = \"\\(.*\\)\"/\\1/p' fly.toml | head -n1)"
APP_NAME="${FLY_APP_NAME:-${APP_FROM_CONFIG}}"
PRIMARY_REGION="${FLY_PRIMARY_REGION:-ord}"
VOLUME_NAME="${FLY_VOLUME_NAME:-yappybara_data}"
VOLUME_SIZE_GB="${FLY_VOLUME_SIZE_GB:-1}"

if [ -z "${APP_NAME}" ]; then
echo "Unable to determine Fly app name."
echo "Set repository variable FLY_APP_NAME or app = \"...\" in fly.toml."
exit 1
fi

# Recover from stale repo variable values by falling back to fly.toml app.
if ! flyctl apps info --app "${APP_NAME}" > /dev/null 2>&1 \
&& [ -n "${APP_FROM_CONFIG}" ] \
&& [ "${APP_FROM_CONFIG}" != "${APP_NAME}" ] \
&& flyctl apps info --app "${APP_FROM_CONFIG}" > /dev/null 2>&1; then
echo "Configured FLY_APP_NAME '${APP_NAME}' not found; using fly.toml app '${APP_FROM_CONFIG}'."
APP_NAME="${APP_FROM_CONFIG}"
fi

if ! flyctl apps info --app "${APP_NAME}" > /dev/null 2>&1; then
echo "Fly app ${APP_NAME} does not exist yet. Creating it now..."
flyctl apps create "${APP_NAME}"
fi

if ! flyctl volumes list --app "${APP_NAME}" | grep -q "${VOLUME_NAME}"; then
echo "Fly volume ${VOLUME_NAME} does not exist yet. Creating it now..."
flyctl volumes create "${VOLUME_NAME}" \
--app "${APP_NAME}" \
--region "${PRIMARY_REGION}" \
--size "${VOLUME_SIZE_GB}"
fi

echo "Deploying to Fly app: ${APP_NAME}"
flyctl deploy \
--remote-only \
Expand Down
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app = "yappybara-api"
app = "yappybara"
primary_region = "ord"

[build]
Expand Down