Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Last active August 29, 2015 14:17
Show Gist options
  • Save paulosuzart/ea335ad9349316ebb2db to your computer and use it in GitHub Desktop.
Save paulosuzart/ea335ad9349316ebb2db to your computer and use it in GitHub Desktop.
open Unix
open Printf
open Cmdliner
open ANSITerminal
let rec do_deploy domain delay host =
let cmd = sprintf [cyan; on_blue] "fabric app.deploy -H %s.%s\n" host domain in
print_string [cyan; on_blue] cmd;
match Unix.system cmd with
| WEXITED i -> printf [yellow; on_blue] "Done %s" cmd
| _ -> printf [red; on_blue] "Error while running %s" cmd;;
let deploy verbose hosts domain delay =
if verbose then
printf [cyan; on_blue] "###Will deploy %s at %s with %ds interval###\n" (String.concat ", " hosts) domain delay;
let rec loop hs =
match hs with
| [] -> exit 1;
| [host] ->
do_deploy domain delay host;
if verbose then
printf [yellow; on_blue] "###verbose = %b\nhosts = %s\ndomain = %s\ndelay=%d###\n" verbose (String.concat ", " hosts) domain delay;
`Ok (printf [yellow; on_blue] "Finished deploy for %s\n" (String.concat ", " hosts));
| host :: tail ->
do_deploy domain delay host;
for i = delay downto 0 do Unix.sleep 1 done;
loop tail; in
loop hosts;;
let verbose =
let doc = "Print relevant information during execution." in
Arg.(value & flag & info ["v"; "verbose"] ~doc)
let hosts =
let doc = "Target host to be deployed at $(i,DOMAIN)." in
Arg.(non_empty & opt (list string) [] & info ["H"; "hosts"] ~docv:"HOSTS"
~doc)
let domain =
let doc = "Target domain where $(i,HOSTS) will be deployed." in
Arg.(value & opt string "office" & info ["d"; "domain"] ~docv:"DOMAIN"
~doc)
let delay =
let doc = "Delay between deploys" in
Arg.(value & opt int 500 & info ["i"; "interval"] ~docv:"INTERV" ~doc)
let cmd =
let doc = "deploy using fabric app.deploy against given domain" in
let man = [
`S "BUGS";
`P "Email them to <paulo at gmail.com>."]
in
Term.(ret (pure deploy $ verbose $ hosts $ domain $ delay)),
Term.info "deploy-all" ~version:"0.0.1" ~doc ~man
let () = match Term.eval cmd with `Error _ -> exit 1 | _ -> exit 0
#ocamlfind ocamlopt -o deploy-all -linkpkg -package cmdliner -package ANSITerminal deploy_all.ml
# to compile, and
./deploy-all -H portal1,portal2 -d production.domain -v -i 300
# to run
# ./deploy-all --help
DEPLOY-ALL(1) Deploy-all Manual DEPLOY-ALL(1)
NAME
deploy-all - deploy using fabric app.deploy against given domain
SYNOPSIS
deploy-all [OPTION]...
OPTIONS
-d DOMAIN, --domain=DOMAIN (absent=office)
Target domain where HOSTS will be deployed.
-H HOSTS, --hosts=HOSTS
Target host to be deployed at DOMAIN.
--help[=FMT] (default=pager)
Show this help in format FMT (pager, plain or groff).
-i INTERV, --interval=INTERV (absent=500)
Delay between deploys
-v, --verbose
Print relevant information during execution.
--version
Show version information.
BUGS
Email them to <paulo at gmail.com>.
Deploy-all 0.0.1 DEPLOY-ALL(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment