-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagging.go
65 lines (54 loc) · 1.34 KB
/
tagging.go
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
package main
import (
"fmt"
"log"
"os"
"strings"
)
func retagImage(imageFullName, sourceTag, targetTag string) error {
imageNameParts := strings.Split(imageFullName, "/")
if len(imageNameParts) != 3 {
return fmt.Errorf("Incorrect image full name '%s'", imageFullName)
}
// registry := imageNameParts[0]
org := imageNameParts[1]
image := imageNameParts[2]
var token string
if org == "experimentalplatform" {
token = os.Getenv("TOKEN_PLATFORM")
} else if org == "protonetinc" {
token = os.Getenv("TOKEN_PROTONET")
} else {
return fmt.Errorf("Unknown image org '%s'", org)
}
id, err := getTagImage(image, org, sourceTag, token)
if err != nil {
return err
}
return setTagImage(image, org, targetTag, id, token)
}
func retagAll(images map[string]string, sourceTag, targetTag string) error {
type response struct {
Image string
Error error
}
count := len(images)
channel := make(chan response)
for k := range images {
imageFullName := k
go func() {
err := retagImage(imageFullName, sourceTag, targetTag)
channel <- response{Image: imageFullName, Error: err}
}()
}
for i := 0; i < count; i++ {
resp := <-channel
if resp.Error == nil {
log.Printf("Image '%s': SUCCESS", resp.Image)
} else {
log.Printf("Image '%s': ERROR: %s", resp.Image, resp.Error.Error())
return resp.Error
}
}
return nil
}