Skip to content

Instantly share code, notes, and snippets.

@RayMPerry
Created October 9, 2021 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RayMPerry/f2e1df44d561dc532c58dbd6170c2db8 to your computer and use it in GitHub Desktop.
Save RayMPerry/f2e1df44d561dc532c58dbd6170c2db8 to your computer and use it in GitHub Desktop.
orchestration.raku
subset UpCommand of Str where 'up';
subset DownCommand of Str where 'down';
subset KillPortsCommand of Str where 'kill-ports';
subset MigrateCommand of Str where 'migrate';
subset NukeCommand of Str where 'nuke';
subset YarnCommand of Str where 'yarn';
multi sub MAIN(YarnCommand $command) {
shell $_ for <cd repos/nestjs-libs && yarn>, <cd ->;
}
multi sub MAIN(NukeCommand $command) {
shell $_ for <pm2 delete all>,
<pm2 save --force>,
<cd repos/nestjs-libs && docker-compose up -d>,
<cd - && pm2 start ecosystem.config.js>,
<pm2 save>;
}
multi sub MAIN(MigrateCommand $command) {
shell $_ for <cd repos/nestjs-libs && npx prisma migrate dev>, <cd ->;
}
multi sub MAIN(KillPortsCommand $command, *@ports) {
my $process = run 'netstat', '-tulpn', :out, :err;
my @output = $process.out.lines: :close;
if @ports.elems < 1 {
note <6379 5432 5050 4200 7070>;
exit;
}
shell "kill -9 {$/[0][0]}" if m:g/ \: @ports \s+ .+ LISTEN \s+ (<graph>+) \/ .+ $ / for @output;
say "Done.";
}
multi sub MAIN(UpCommand $command) {
shell $_ for <cd repos/nestjs-libs && docker-compose up -d>, <cd - && pm2 start ecosystem.config.js>;
}
multi sub MAIN(DownCommand $command) {
shell $_ for <pm2 stop all>, <pm2 kill>, <cd repos/nestjs-libs && docker-compose down>, <cd ->;
}
sub USAGE {
say "Use `{$*PROGRAM-NAME} <up|down|kill-ports|migrate|nuke|yarn>`.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment