Spin up a Fly.io preview environment for every pull request

By General Input

The moment a pull request opens, we launch a live preview of that branch on Fly.io and post the link right on the PR and in your team's Slack channel.

Integrations

  • Fly.io
  • GitHub
  • Slack Bot

Type

Agentic Task

Categories

  • Engineering

Trigger this workflow with a webhook whenever a pull request is opened in my GitHub repository. Read the pull request number, the head branch name, and the repository from the webhook payload so the rest of the run can reference them.

Let me configure two settings up front: the name of my Fly.io preview app that should host the branch, and the container image the Machine should boot from. Use those two values everywhere below.

When the pull request opens, call the Fly.io Create Machine operation in my preview app to launch a Machine for this branch, booting it from the configured image. Tag the Machine with the pull request number in the Machine metadata so I can always tell which preview belongs to which pull request.

Fly.io can refuse to place a Machine when the target region is out of capacity, and the API does not queue the request, so you own the retries. If Create Machine cannot place the Machine, use the Fly.io Get Placements operation to see which regions currently have room, then retry Create Machine in a fallback region. Work through a few sensible regions before giving up. If every attempt fails, post a comment on the pull request explaining that no region had capacity right now.

Once the Machine is created, use the Fly.io Wait for State operation to block until it reaches the started state, so I only share the preview once it is actually running.

When the Machine is running, build the preview URL from the configured preview app name (the app's public Fly.io URL) and post it back onto the pull request using the GitHub Create an Issue Comment operation, addressed to the pull request number. Keep the comment short: the preview link plus one line telling reviewers they can click straight through.

Then send a short heads-up to my team's Slack channel with the Slack Bot Send a Message operation, including the pull request title, its number, and the preview link, so the team can jump straight into review.

Related prompts

Explore more prompts
A brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasonLiveChat coverage board for planning next week's shiftsPhone routing control panel for LiveKit voice agentsLinkedIn Ads budget pacing dashboard for every client accountGive your team Looker numbers without buying more seatsPause marketing emails to escalated customers, then restore them