Skip to content

Commit 2bdcc09

Browse files
committed
Implement explicit --parallel flag
I'm working on a `--dry-run` flag that will improve the coverage of this, but wanted separate commits.
1 parent 8b4e0f3 commit 2bdcc09

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

.test/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ if [ -n "$doDeploy" ]; then
250250
empty
251251
')" # stored in a variable for easier debugging ("bash -x")
252252

253-
time "$coverage/bin/deploy" <<<"$json"
253+
time "$coverage/bin/deploy" --parallel <<<"$json"
254254

255255
docker rm -vf meta-scripts-test-registry
256256
trap - EXIT

Jenkinsfile.deploy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ node('put-shared') { ansiColor('xterm') {
106106
./.go-env.sh go build -trimpath -o bin/deploy ./cmd/deploy
107107
fi
108108
)
109-
.scripts/bin/deploy < filtered-deploy.json
109+
.scripts/bin/deploy --parallel < filtered-deploy.json
110110
'''
111111
}
112112
}

cmd/deploy/main.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,25 @@ func main() {
1818
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
1919
defer stop()
2020

21-
// TODO --dry-run ?
21+
var (
22+
args = os.Args[1:]
23+
24+
// --parallel
25+
parallel bool
26+
)
27+
for len(args) > 0 {
28+
arg := args[0]
29+
args = args[1:]
30+
31+
// TODO --dry-run
32+
switch arg {
33+
case "--parallel":
34+
parallel = true
35+
36+
default:
37+
panic("unknown argument: " + arg)
38+
}
39+
}
2240

2341
// TODO the best we can do on whether or not this actually updated tags is "yes, definitely (we had to copy some children)" and "maybe (we didn't have to copy any children)", but we should maybe still output those so we can trigger put-shared based on them (~immediately on "definitely" and with some medium delay on "maybe")
2442

@@ -103,7 +121,8 @@ func main() {
103121
normal := normal.clone()
104122

105123
wg.Add(1)
106-
go func() {
124+
// (making a function instead of direct "go func() ..." so we can support the --parallel toggle)
125+
f := func() {
107126
defer wg.Done()
108127

109128
if mutex != nil {
@@ -177,7 +196,12 @@ func main() {
177196
logText += "@" + string(desc.Digest)
178197
}
179198
fmt.Println(successPrefix + logText)
180-
}()
199+
}
200+
if parallel {
201+
go f()
202+
} else {
203+
f()
204+
}
181205
}
182206
}
183207

0 commit comments

Comments
 (0)