Skip to content

Instantly share code, notes, and snippets.

@chrisdone-artificial
Created November 15, 2024 13:51
Show Gist options
  • Save chrisdone-artificial/1f8437e9309e6c5a502565501509f1cb to your computer and use it in GitHub Desktop.
Save chrisdone-artificial/1f8437e9309e6c5a502565501509f1cb to your computer and use it in GitHub Desktop.
reflect cron hell script
root@fsn1-cd-1:~# cat /root/brossa-cd/scripts/reflect-cron.hell
#!/usr/bin/env hell
-- assumes: jq, docker
main = do
input <- Text.readProcessStdout_ $ Process.proc "docker" ["ps","--format","json"]
let lines = Text.lines input
Monad.forM_ lines \json -> do
labels' <- Main.jq json [".Labels","-r"]
let labels = Text.splitOn "," labels'
Monad.forM_ labels \label ->
Monad.when (Text.isPrefixOf "artificial.brossa.name=reflect" label) do
id <- do text <- Main.jq json [".ID","-r"]
Monad.return $ Text.strip text
Process.runProcess_ $ Process.proc "docker" ["stop", id]
Process.runProcess_ $ Process.proc "docker" ["rm", id]
jq = \json args -> Text.readProcessStdout_ $ Text.setStdin json $ Process.proc "jq" args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment