-
Notifications
You must be signed in to change notification settings - Fork 0
/
gho
executable file
·110 lines (99 loc) · 2.73 KB
/
gho
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/perl -w
use strict;
use warnings;
use v5.10;
use utf8;
my %apps = (
api => {
build => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml api/build.yml )),
},
},
deploy => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml api/deploy.yml )),
},
},
restart => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml api/restart.yml )),
},
},
},
secrets => {
edit => {
run => sub {
# Password stored in 1Password as “PGXN Manager Secrets”
run(qw(ansible-vault edit manager/secrets.yml))
}
}
},
manager => {
build => {
run => sub {
# Password stored in 1Password as “PGXN Manager Secrets”
run(qw(
ansible-playbook -i hosts.yaml manager/build.yml -e @manager/secrets.yml --ask-vault-pass
))
},
},
deploy => {
run => sub {
# Password stored in 1Password as “PGXN Manager Secrets”
run(qw(
ansible-playbook -i hosts.yaml manager/deploy.yml -e @manager/secrets.yml --ask-vault-pass
))
},
},
restart => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml manager/restart.yml )),
},
},
},
site => {
build => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml site/build.yml )),
},
},
deploy => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml site/deploy.yml )),
},
},
restart => {
run => sub {
run(qw( ansible-playbook -i hosts.yaml site/restart.yml )),
},
},
},);
sub run {
system(@_) == 0 or exit $? >> 8;
}
sub usage {
say STDERR @_ if @_;
say "Usage: gho ACTION APP";
say "Run gho --help for a complete list of actions and apps."
}
sub bail {
usage(@_);
exit 1;
}
sub help {
usage();
say "\nActions & Commands";
my %seen;
for my $cmd (grep { !$seen{$_}++ } sort map { keys %{ $_ } } values %apps) {
say "* $cmd";
say " - $_" for grep { $apps{$_}->{$cmd} } sort keys %apps;
}
exit;
}
my ($cmd_name, $app_name) = @ARGV;
help() if $cmd_name && $cmd_name =~ /^-{0,2}help$/;
bail() unless $cmd_name && $app_name;
my $app = $apps{$app_name} or bail("Unknown app “$app_name”");
my $cmd = $app->{$cmd_name} or bail("Unknown $app_name command “$cmd_name”");
$cmd->{run}();