forked from SeleniumHQ/docker-selenium
-
Notifications
You must be signed in to change notification settings - Fork 25
/
get-image-sha256-digest.go
56 lines (45 loc) · 1.07 KB
/
get-image-sha256-digest.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
package main
import (
"io/ioutil"
"log"
"net/http"
"fmt"
"encoding/json"
"os"
)
type Latest struct {
Images []struct {
Architecture string `json:"architecture"`
Digest string `json:"digest"`
}
}
func main() {
argLen := len(os.Args)
if argLen < 2 {
showUsage()
os.Exit(1)
}
url := os.Args[1] // https://hub.docker.com/v2/repositories/selenium/standalone-chrome/tags/latest/
resp, err := http.Get(url)
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
var jsonResp Latest
sb := string(body)
json.Unmarshal([]byte(sb), &jsonResp)
for _, image := range jsonResp.Images {
fmt.Printf(image.Architecture + " " + image.Digest + "\n")
}
}
func showUsage() {
fmt.Println(`Usage:
get-image-sha256-digest TAG_URL
TAG_URL -> URL for a container image manifest (Required)
Example Usage:
$ get-image-sha256-digest https://hub.docker.com/v2/repositories/selenium/standalone-chrome/tags/latest/
`)
}