Skip to content

Instantly share code, notes, and snippets.

@lubien
Created October 3, 2024 14:39
Show Gist options
  • Save lubien/0f087bcafa0d4e334c808272ef0e1fa6 to your computer and use it in GitHub Desktop.
Save lubien/0f087bcafa0d4e334c808272ef0e1fa6 to your computer and use it in GitHub Desktop.
flyio org purger

Fly Org Cleaner

Mix.install([
  {:req, "~> 0.5.6"},
  {:kino, "~> 0.14.1"}
])

Section

fly_api_token = System.get_env("LB_LUBIEN_ORG_SECRET")
String.length(fly_api_token)
req = Req.new(base_url: "https://api.machines.dev/v1", auth: {:bearer, fly_api_token})
:ok
{:ok, res} = Req.get(req, url: "/apps?org_slug=lubien")
%{body: %{"apps" => apps}} = res

Kino.DataTable.new(apps)
test_apps = 
  apps
# |> Enum.filter(& String.starts_with?(&1["name"], "flyio-deployer-"))
  |> Enum.filter(& String.starts_with?(&1["name"], "hello-") || String.starts_with?(&1["name"], "app-"))

Kino.DataTable.new(test_apps)
for a <- test_apps do
  "fly apps destroy #{a["name"]} --yes"
end
|> Enum.join("\n")
|> IO.puts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment