|
8 | 8 | "io/ioutil" |
9 | 9 | "os" |
10 | 10 | "os/exec" |
| 11 | + "path" |
| 12 | + "strings" |
11 | 13 | "time" |
12 | 14 |
|
13 | 15 | "github.com/drone/drone-go/drone" |
@@ -36,7 +38,9 @@ func (p Plugin) writeCard() error { |
36 | 38 | for _, tag := range inspect.RepoTags { |
37 | 39 | sliceTagStruct = append(sliceTagStruct, TagStruct{Tag: tag}) |
38 | 40 | } |
39 | | - inspect.ParsedRepoTags = sliceTagStruct |
| 41 | + inspect.ParsedRepoTags = sliceTagStruct[1:] // remove the first tag which is always "hash:latest" |
| 42 | + // create the url from repo and registry |
| 43 | + inspect.URL = mapRegistryToURL(p.Daemon.Registry, p.Build.Repo) |
40 | 44 | cardData, _ := json.Marshal(inspect) |
41 | 45 |
|
42 | 46 | card := drone.CardInput{ |
@@ -67,3 +71,18 @@ func writeCardTo(out io.Writer, data []byte) { |
67 | 71 | io.WriteString(out, "\u001B]0m") |
68 | 72 | io.WriteString(out, "\n") |
69 | 73 | } |
| 74 | + |
| 75 | +func mapRegistryToURL(registry, repo string) (url string) { |
| 76 | + url = "https://" |
| 77 | + var domain string |
| 78 | + if strings.Contains(registry, "amazonaws.com") { |
| 79 | + domain = "gallery.ecr.aws/" |
| 80 | + } else if strings.Contains(registry, "gcr.io") { |
| 81 | + domain = "console.cloud.google.com/gcr/images" |
| 82 | + } else { |
| 83 | + // default to docker hub |
| 84 | + domain = "hub.docker.com/r/" |
| 85 | + } |
| 86 | + url = path.Join(url, domain, repo) |
| 87 | + return url |
| 88 | +} |
0 commit comments