-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brigadm
executable file
·88 lines (82 loc) · 2.99 KB
/
brigadm
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
#!/usr/bin/env variant
flows:
- name: ssm
flows:
- name: put
inputs:
- name: name
argument-index: 0
- name: value
argument-index: 1
script: |
aws ssm put-parameter --name "{{.name}}" --value "{{.value}}" --type String --overwrite
- name: get
inputs:
- name: name
argument-index: 0
script: |
aws ssm get-parameters --names "{{.name}}" | jq -rc '.Parameters[0].Value
- name: init-with-ssm
inputs:
- name: namespace
- name: name
- name: ssh-key-from-ssm-parameter
- name: script
script: |
brigadm ssm get {{.ssh_key_from_ssm_parameter}} > tmp-key
brigadm init --namespace {{.namespace}} --name={{.name}} --ssh-key-from-path=tmp-key --script={{.script}}
rm tmp-key
- name: boostrap
inputs:
- name: name
description: the github repository name = application name = namespace name
- name: org
description: the github organization name
- name: brigade-script-repo
decription: the github repo contains the default brigade script(brigade.js) used when the target repo misses brigade.js
- name: ssh-key
- name: brigade-script-path
description: path to the default brigade script used by the resulting brigade project
script: |
if ! brigadm status; then brigadm init --namespace {{.name}} --repository={{.org}}/{{.brigade_script_repo}} --ssh-key-from-ssm-parameter={{.ssh_key}}; fi
run=$(cat <<-BASH
brigadm init --namespace {{.name}} --repository={{.org}}/{{.name}} --ssh-key-from-ssm-paramaeter={{.ssh_key}} --default-script={{.brigade_script_path}}
BASH
)
brigadm run "$run" --namespace {{.name}}
brigadm wait --namespace {{.name}}
brig run {{.name}} --namespace {{.name}} --event init
- name: init
inputs:
- name: namespace
- name: ssh-key-from-path
- name: script
- name: name
script: |
if ! helm repo list | grep brigade; then
helm repo add brigade https://azure.github.io/brigade
fi
helm upgrade brigade brigade/brigade --install --set rbac.enabled=true --namespace {{.namespace}} --tiller-namespace {{.namespace}}
echo 'sshKey: |' > values.yaml
cat {{.ssh_key_from_path}} | sed 's/^/ /' >> values.yaml
echo 'defaultScript: |' >> values.yaml
cat {{.script}} | sed 's/^/ /' >> values.yaml
helm upgrade brigade-project brigade/brigade-project --install --set project={{.name}},repository=github.com/{{.name}},cloneURL=git@github.com:{{.name}}.git -f values.yaml
- name: run
inputs:
- name: command
argument-index: 0
- name: namespace
- name: image
- name: commit
script: |
echo 'const { events, Job, Group} = require("brigadier"); events.on("run", (e, p) => { var j = new Job("brigadm-run", "{{.image}}"); j.tasks = ["'{{.command}}'"]; j.run() });' > tmp-brigade.js
brig run {{.namespace}} --namespace {{.namespace}} --event run --file tmp-brigade.js
rm tmp-brigade.js
- name: wait
flows:
- name: init
inputs:
- name: namespace
script: |
while ! brig project list --namespace {{.namespace}}; do sleep 1; done